Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 1 | package org.onlab.onos.core.impl; |
| 2 | |
| 3 | import org.onlab.onos.core.IdBlock; |
| 4 | import org.onlab.onos.core.IdBlockStore; |
| 5 | |
| 6 | public class StoreBasedIdBlockAllocator implements IdBlockAllocator { |
| 7 | private long blockTop; |
| 8 | private static final long BLOCK_SIZE = 0x1000000L; |
| 9 | |
| 10 | private final IdBlockStore store; |
| 11 | private final String topic; |
| 12 | |
| 13 | public StoreBasedIdBlockAllocator(String topic, IdBlockStore store) { |
| 14 | this.topic = topic; |
| 15 | this.store = store; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Returns a block of IDs which are unique and unused. |
| 20 | * Range of IDs is fixed size and is assigned incrementally as this method |
| 21 | * called. |
| 22 | * |
| 23 | * @return an IdBlock containing a set of unique IDs |
| 24 | */ |
| 25 | @Override |
| 26 | public synchronized IdBlock allocateUniqueIdBlock() { |
| 27 | return store.getIdBlock(topic); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public IdBlock allocateUniqueIdBlock(long range) { |
| 32 | throw new UnsupportedOperationException("Not supported yet"); |
| 33 | } |
| 34 | } |