blob: 67d33ed4242e65bb9541ae5567c3b2c4904af437 [file] [log] [blame]
Brian O'Connorabafb502014-12-02 22:26:20 -08001package org.onosproject.core.impl;
Brian O'Connor520c0522014-11-23 23:50:47 -08002
Brian O'Connorabafb502014-12-02 22:26:20 -08003import org.onosproject.core.IdBlock;
4import org.onosproject.core.IdBlockStore;
Brian O'Connor520c0522014-11-23 23:50:47 -08005
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}