Extract common ID generation logic using IdBlockAllocator
- Define IdGenerator<T> interface
- Implement AbstractIdBlockAllocatorBasedIdGenerator<T>, which
has the common logic for the existing IntentId, FlowId, MatchActionId,
and MatchActionOperationsId generator implementations.
Change-Id: I7aeea249df1710719760ed477bffe62853577e0f
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsIdGeneratorWithIdBlockAllocator.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsIdGeneratorWithIdBlockAllocator.java
index d1d5240..fd9efdc 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsIdGeneratorWithIdBlockAllocator.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsIdGeneratorWithIdBlockAllocator.java
@@ -1,37 +1,26 @@
package net.onrc.onos.core.matchaction;
-import net.onrc.onos.core.util.IdBlock;
+import net.onrc.onos.core.util.AbstractBlockAllocatorBasedIdGenerator;
import net.onrc.onos.core.util.IdBlockAllocator;
-import net.onrc.onos.core.util.UnavailableIdException;
-import static com.google.common.base.Preconditions.checkNotNull;
/**
* Generates a global unique MatchActionIdId.
*/
public class MatchActionOperationsIdGeneratorWithIdBlockAllocator
- implements MatchActionOperationsIdGenerator {
+ extends AbstractBlockAllocatorBasedIdGenerator<MatchActionOperationsId> {
- private final IdBlockAllocator allocator;
- private IdBlock idBlock;
+ /**
+ * Creates a FlowId generator instance using specified ID block allocator.
+ *
+ * @param allocator the ID block allocator to be used
+ */
+ public MatchActionOperationsIdGeneratorWithIdBlockAllocator(IdBlockAllocator allocator) {
+ super(allocator);
+ }
- /**
- * Creates a FlowId generator instance using specified ID block allocator.
- *
- * @param allocator the ID block allocator to be used
- */
- public MatchActionOperationsIdGeneratorWithIdBlockAllocator(IdBlockAllocator allocator) {
- this.allocator = checkNotNull(allocator);
- this.idBlock = allocator.allocateUniqueIdBlock();
- }
-
- @Override
- public synchronized MatchActionOperationsId getNewId() {
- try {
- return new MatchActionOperationsId(idBlock.getNextId());
- } catch (UnavailableIdException e) {
- idBlock = allocator.allocateUniqueIdBlock();
- return new MatchActionOperationsId(idBlock.getNextId());
- }
- }
+ @Override
+ protected MatchActionOperationsId convertFrom(long value) {
+ return new MatchActionOperationsId(value);
+ }
}