blob: 2c92ff70ca6a1d742f1b3dcbedc74dd48e5ae642 [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 MatchActionIdGeneratorWithIdBlockAllocator
13 implements MatchActionIdGenerator {
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 MatchActionIdGeneratorWithIdBlockAllocator(IdBlockAllocator allocator) {
24 this.allocator = checkNotNull(allocator);
25 this.idBlock = allocator.allocateUniqueIdBlock();
26 }
27
28 @Override
29 public synchronized MatchActionId getNewId() {
30 try {
31 return new MatchActionId(idBlock.getNextId());
32 } catch (UnavailableIdException e) {
33 idBlock = allocator.allocateUniqueIdBlock();
34 return new MatchActionId(idBlock.getNextId());
35 }
36 }
37}