Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 1 | package org.onosproject.core.impl; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 2 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 3 | import org.onosproject.core.IdBlock; |
| 4 | import org.onosproject.core.IdBlockStore; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 5 | |
| 6 | public class StoreBasedIdBlockAllocator implements IdBlockAllocator { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 7 | 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 | } |