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