blob: d1d5240cac341ca62d9d36109868c2599c8550ef [file] [log] [blame]
Ray Milkey9ed4b962014-08-20 15:43:40 -07001package net.onrc.onos.core.matchaction;
2
3import net.onrc.onos.core.util.IdBlock;
4import net.onrc.onos.core.util.IdBlockAllocator;
5import net.onrc.onos.core.util.UnavailableIdException;
6
7import static com.google.common.base.Preconditions.checkNotNull;
8
9/**
10 * Generates a global unique MatchActionIdId.
11 */
12public class MatchActionOperationsIdGeneratorWithIdBlockAllocator
13 implements MatchActionOperationsIdGenerator {
14
15 private final IdBlockAllocator allocator;
16 private IdBlock idBlock;
17
18 /**
19 * Creates a FlowId generator instance using specified ID block allocator.
20 *
21 * @param allocator the ID block allocator to be used
22 */
23 public MatchActionOperationsIdGeneratorWithIdBlockAllocator(IdBlockAllocator allocator) {
24 this.allocator = checkNotNull(allocator);
25 this.idBlock = allocator.allocateUniqueIdBlock();
26 }
27
28 @Override
29 public synchronized MatchActionOperationsId getNewId() {
30 try {
31 return new MatchActionOperationsId(idBlock.getNextId());
32 } catch (UnavailableIdException e) {
33 idBlock = allocator.allocateUniqueIdBlock();
34 return new MatchActionOperationsId(idBlock.getNextId());
35 }
36 }
37}