blob: 3bd6bf6c7f848836c76db1fb3b00120621e46109 [file] [log] [blame]
Madan Jampani619453b2015-07-22 23:47:09 -07001/*
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 Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampanib5d72d52015-04-03 16:53:50 -070017
18import org.onosproject.store.service.AsyncAtomicCounter;
Madan Jampanib5d72d52015-04-03 16:53:50 -070019import org.onosproject.store.service.AtomicCounterBuilder;
20
Madan Jampanie17d3282016-02-03 15:30:57 -080021import static com.google.common.base.Preconditions.checkNotNull;
Madan Jampanib5d72d52015-04-03 16:53:50 -070022
23/**
24 * Default implementation of AtomicCounterBuilder.
25 */
Madan Jampanie17d3282016-02-03 15:30:57 -080026public class DefaultAtomicCounterBuilder extends AtomicCounterBuilder {
Madan Jampanib5d72d52015-04-03 16:53:50 -070027
Madan Jampanib5d72d52015-04-03 16:53:50 -070028 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 Jampanie17d3282016-02-03 15:30:57 -080037 public AsyncAtomicCounter build() {
38 Database database = partitionsDisabled() ? inMemoryDatabase : partitionedDatabase;
39 return new DefaultAsyncAtomicCounter(checkNotNull(name()), database, meteringEnabled());
Madan Jampanib5d72d52015-04-03 16:53:50 -070040 }
41}