minor: Some very minor first clean up in IdManager 70/48670/3
authorMichael Vorburger <vorburger@redhat.com>
Thu, 24 Nov 2016 15:56:05 +0000 (16:56 +0100)
committerMichael Vorburger <vorburger@redhat.com>
Thu, 24 Nov 2016 16:49:53 +0000 (17:49 +0100)
Change-Id: I693b60d89fd26ae36f5268fb137e2b945009801b
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/AvailableIdHolder.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdPoolListener.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdUtils.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/ReleasedIdHolder.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/jobs/CleanUpJob.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/jobs/IdHolderSyncJob.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/jobs/LocalPoolCreateJob.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/jobs/LocalPoolDeleteJob.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/jobs/UpdateIdEntryJob.java

index bce595749b0a770b8050de38195f27907eb07d49..74b54f7ea4e21418225b35c298b516cba25e6588 100644 (file)
@@ -14,9 +14,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.
 import com.google.common.base.Optional;
 
 public class AvailableIdHolder implements IdHolder {
+
     private long low = 0;
     private long high = 0;
-    private AtomicLong cur = new AtomicLong();
+    private final AtomicLong cur = new AtomicLong();
 
     public AvailableIdHolder(long low, long high) {
         addIdBlock(low, high);
index 2bcc423601c390d445d8130eced2653bbd518a81..ebe0475dd837e8a4beb4d8408ed65c0d867122b7 100644 (file)
@@ -21,8 +21,9 @@ import org.slf4j.LoggerFactory;
 public class IdPoolListener extends AsyncClusteredDataTreeChangeListenerBase<IdPool, IdPoolListener> implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(IdPoolListener.class);
-    DataBroker broker;
-    IdManager idManager;
+
+    private final DataBroker broker;
+    private final IdManager idManager;
 
     @Inject
     public IdPoolListener(DataBroker broker, IdManager idManager) {
index f015d795c27c7bc8d0ad48b24acc48280cd6ce55..838d26afc29ab6a8569af1265712959f6eeab2f6 100644 (file)
@@ -53,14 +53,17 @@ import com.google.common.util.concurrent.CheckedFuture;
 public class IdUtils {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(IdUtils.class);
+
     public static final long DEFAULT_DELAY_TIME = 30;
     private static final long DEFAULT_AVAILABLE_ID_COUNT = 0;
     private static final int DEFAULT_BLOCK_SIZE_DIFF = 10;
     public static final int RETRY_COUNT = 6;
-    public static ConcurrentHashMap<String, Integer> poolUpdatedMap = new ConcurrentHashMap<>();
     public static final String ID_POOL_CACHE = "ID_POOL_CACHE";
 
+    public static ConcurrentHashMap<String, Integer> poolUpdatedMap = new ConcurrentHashMap<>();
+
     private static int BLADE_ID;
+
     static {
         try {
             BLADE_ID = InetAddresses.coerceToInteger(InetAddress.getLocalHost());
@@ -127,13 +130,14 @@ public class IdUtils {
     }
 
     protected static boolean isIdAvailable(AvailableIdsHolderBuilder availableIds) {
-        if (availableIds.getCursor() != null && availableIds.getEnd() != null)
+        if (availableIds.getCursor() != null && availableIds.getEnd() != null) {
             return availableIds.getCursor() < availableIds.getEnd();
+        }
         return false;
     }
 
     protected static String getLocalPoolName(String poolName) {
-        return (poolName + "." + BLADE_ID);
+        return poolName + "." + BLADE_ID;
     }
 
     protected static ChildPools createChildPool(String childPoolName) {
@@ -142,15 +146,17 @@ public class IdUtils {
 
     protected static AvailableIdsHolderBuilder getAvailableIdsHolderBuilder(IdPool pool) {
         AvailableIdsHolder availableIds = pool.getAvailableIdsHolder();
-        if (availableIds != null )
+        if (availableIds != null ) {
             return new AvailableIdsHolderBuilder(availableIds);
+        }
         return new AvailableIdsHolderBuilder();
     }
 
     protected static ReleasedIdsHolderBuilder getReleaseIdsHolderBuilder(IdPool pool) {
         ReleasedIdsHolder releasedIds = pool.getReleasedIdsHolder();
-        if (releasedIds != null)
+        if (releasedIds != null) {
             return new ReleasedIdsHolderBuilder(releasedIds);
+        }
         return new ReleasedIdsHolderBuilder();
     }
 
@@ -218,7 +224,7 @@ public class IdUtils {
          LockInput input = new LockInputBuilder().setLockName(poolName).build();
          Future<RpcResult<Void>> result = lockManager.lock(input);
          try {
-             if ((result != null) && (result.get().isSuccessful())) {
+             if (result != null && result.get().isSuccessful()) {
                  if (LOGGER.isDebugEnabled()) {
                      LOGGER.debug("Acquired lock {}", poolName);
                  }
@@ -235,7 +241,7 @@ public class IdUtils {
         UnlockInput input = new UnlockInputBuilder().setLockName(poolName).build();
         Future<RpcResult<Void>> result = lockManager.unlock(input);
         try {
-            if ((result != null) && (result.get().isSuccessful())) {
+            if (result != null && result.get().isSuccessful()) {
                 if (LOGGER.isDebugEnabled()) {
                     LOGGER.debug("Unlocked {}", poolName);
                 }
@@ -319,4 +325,4 @@ public class IdUtils {
     public static void removeFromPoolUpdatedMap(String localPoolName) {
         poolUpdatedMap.remove(localPoolName);
     }
-}
\ No newline at end of file
+}
index 8548afe700fa9e6fea9dbe321f11a57f0c2e6719..e0fbb2228638bea8a46bb48b1c2656cd85ff646f 100644 (file)
@@ -20,7 +20,8 @@ public class ReleasedIdHolder implements IdHolder, Serializable {
 
     private static final long serialVersionUID = 1L;
     private static final int INITIAL_INDEX = 0;
-    private AtomicLong availableIdCount = new AtomicLong();
+
+    private final AtomicLong availableIdCount = new AtomicLong();
 
     private long timeDelaySec;
     private List<DelayedIdEntry> delayedEntries;
@@ -137,4 +138,4 @@ public class ReleasedIdHolder implements IdHolder, Serializable {
     public void refreshDataStore(IdPoolBuilder idPoolBuilder) {
         IdUtils.syncReleaseIdHolder(this, idPoolBuilder);
     }
-}
\ No newline at end of file
+}
index 3a9ba351839b01f1b1d5e8d8663eb6c30565f19d..3716a997e40a43ec448aae823d5f5faee728d5c6 100644 (file)
@@ -31,11 +31,12 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class CleanUpJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(CleanUpJob.class);
-    private IdLocalPool idLocalPool;
-    private DataBroker broker;
-    private String parentPoolName;
-    private int blockSize;
-    private LockManagerService lockManager;
+
+    private final IdLocalPool idLocalPool;
+    private final DataBroker broker;
+    private final String parentPoolName;
+    private final int blockSize;
+    private final LockManagerService lockManager;
 
     public CleanUpJob(IdLocalPool idLocalPool, DataBroker broker,
             String parentPoolName, int blockSize, LockManagerService lockManager) {
@@ -78,7 +79,7 @@ public class CleanUpJob implements Callable<List<ListenableFuture<Void>>> {
                     LOG.debug("Releasing excesss Ids from local pool");
                 }
                 ReleasedIdHolder releasedIds = (ReleasedIdHolder) idLocalPool.getReleasedIds();
-                IdUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, totalAvailableIdCount - (blockSize * 2));
+                IdUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, totalAvailableIdCount - blockSize * 2);
                 IdHolderSyncJob job = new IdHolderSyncJob(idLocalPool.getPoolName(), releasedIds, broker);
                 DataStoreJobCoordinator.getInstance().enqueueJob(idLocalPool.getPoolName(), job, IdUtils.RETRY_COUNT);
                 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdInstanceIdentifier, releasedIdsParent.build());
@@ -87,4 +88,4 @@ public class CleanUpJob implements Callable<List<ListenableFuture<Void>>> {
             }
         }
     }
-}
\ No newline at end of file
+}
index c668301b2f57a00f0c9bb1f32bc4b2b592e65793..22ea07ffdd9a1cf88ea1eebeaec82dd4d070e7c8 100644 (file)
@@ -28,9 +28,10 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class IdHolderSyncJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(IdHolderSyncJob.class);
-    private String localPoolName;
-    private IdHolder idHolder;
-    private DataBroker broker;
+
+    private final String localPoolName;
+    private final IdHolder idHolder;
+    private final DataBroker broker;
 
     public IdHolderSyncJob(String localPoolName, IdHolder idHolder,
             DataBroker broker) {
@@ -55,4 +56,4 @@ public class IdHolderSyncJob implements Callable<List<ListenableFuture<Void>>> {
             }
             return futures;
     }
-}
\ No newline at end of file
+}
index 2d899bcbfdd5e8493dda3f7fb2427a629103bd3f..0adf86e58b5fa0ca09c064b0d519d3f090c1e63c 100644 (file)
@@ -28,10 +28,11 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class LocalPoolCreateJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(LocalPoolCreateJob.class);
-    private IdLocalPool idLocalPool;
-    private DataBroker broker;
-    private String parentPoolName;
-    private int blockSize;
+
+    private final IdLocalPool idLocalPool;
+    private final DataBroker broker;
+    private final String parentPoolName;
+    private final int blockSize;
 
     public LocalPoolCreateJob(IdLocalPool idLocalPool, DataBroker broker,
             String parentPoolName, int blockSize) {
@@ -58,4 +59,4 @@ public class LocalPoolCreateJob implements Callable<List<ListenableFuture<Void>>
         futures.add(tx.submit());
         return futures;
     }
-}
\ No newline at end of file
+}
index daba839098d8b66acf8205c841bc87ba67492e58..f696c2002e5e1ad0ca47ae42c0e0e24a1a0d5448 100644 (file)
@@ -26,8 +26,9 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class LocalPoolDeleteJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(LocalPoolDeleteJob.class);
-    private String poolName;
-    private DataBroker broker;
+
+    private final String poolName;
+    private final DataBroker broker;
 
     public LocalPoolDeleteJob(String poolName, DataBroker broker) {
         super();
@@ -47,4 +48,4 @@ public class LocalPoolDeleteJob implements Callable<List<ListenableFuture<Void>>
         futures.add(tx.submit());
         return futures;
     }
-}
\ No newline at end of file
+}
index 7c065b0e131bb7f99f54b61f348278b2194e5683..bc8aa48e247b156e0079c7911fda481b06897368 100644 (file)
@@ -22,11 +22,11 @@ import com.google.common.util.concurrent.ListenableFuture;
 
 public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>> {
 
-    String parentPoolName;
-    String localPoolName;
-    String idKey;
-    List<Long> newIdValues;
-    DataBroker broker;
+    private final String parentPoolName;
+    private final String localPoolName;
+    private final String idKey;
+    private final List<Long> newIdValues;
+    private final DataBroker broker;
 
     public UpdateIdEntryJob(String parentPoolName, String localPoolName,
             String idKey, List<Long> newIdValues, DataBroker broker) {
@@ -53,4 +53,4 @@ public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>>
         futures.add(tx.submit());
         return futures;
     }
-}
\ No newline at end of file
+}