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);
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) {
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());
}
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) {
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();
}
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);
}
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);
}
public static void removeFromPoolUpdatedMap(String localPoolName) {
poolUpdatedMap.remove(localPoolName);
}
-}
\ No newline at end of file
+}
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;
public void refreshDataStore(IdPoolBuilder idPoolBuilder) {
IdUtils.syncReleaseIdHolder(this, idPoolBuilder);
}
-}
\ No newline at end of file
+}
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) {
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());
}
}
}
-}
\ No newline at end of file
+}
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) {
}
return futures;
}
-}
\ No newline at end of file
+}
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) {
futures.add(tx.submit());
return futures;
}
-}
\ No newline at end of file
+}
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();
futures.add(tx.submit());
return futures;
}
-}
\ No newline at end of file
+}
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) {
futures.add(tx.submit());
return futures;
}
-}
\ No newline at end of file
+}