Madan Jampani | 619453b | 2015-07-22 23:47:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Madan Jampani | f4c8850 | 2016-01-21 12:35:36 -0800 | [diff] [blame] | 16 | package org.onosproject.store.primitives.impl; |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.store.service.AsyncAtomicCounter; |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 19 | import org.onosproject.store.service.AtomicCounterBuilder; |
| 20 | |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 21 | import static com.google.common.base.Preconditions.checkNotNull; |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Default implementation of AtomicCounterBuilder. |
| 25 | */ |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 26 | public class DefaultAtomicCounterBuilder extends AtomicCounterBuilder { |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 27 | |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 28 | private final Database partitionedDatabase; |
| 29 | private final Database inMemoryDatabase; |
| 30 | |
| 31 | public DefaultAtomicCounterBuilder(Database inMemoryDatabase, Database partitionedDatabase) { |
| 32 | this.inMemoryDatabase = inMemoryDatabase; |
| 33 | this.partitionedDatabase = partitionedDatabase; |
| 34 | } |
| 35 | |
| 36 | @Override |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 37 | public AsyncAtomicCounter build() { |
| 38 | Database database = partitionsDisabled() ? inMemoryDatabase : partitionedDatabase; |
| 39 | return new DefaultAsyncAtomicCounter(checkNotNull(name()), database, meteringEnabled()); |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 40 | } |
| 41 | } |