blob: 01209be2a7e9320f498161b91fc8738bdec528ff [file] [log] [blame]
Ray Milkey24e60b32015-08-12 11:39:54 -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 */
16package org.onosproject.store.service;
17
Ray Milkey24e60b32015-08-12 11:39:54 -070018import java.util.concurrent.atomic.AtomicLong;
19
20/**
21 * Test implementation of atomic counter.
22 */
23public final class TestAtomicCounter implements AtomicCounter {
24 final AtomicLong value;
25
26 private TestAtomicCounter() {
27 value = new AtomicLong();
28 }
29
30 @Override
31 public long incrementAndGet() {
32 return value.incrementAndGet();
33 }
34
35 @Override
36 public long getAndIncrement() {
37 return value.getAndIncrement();
38 }
39
40 @Override
41 public long getAndAdd(long delta) {
42 return value.getAndAdd(delta);
43 }
44
45 @Override
46 public long addAndGet(long delta) {
47 return value.addAndGet(delta);
48 }
49
50 @Override
51 public long get() {
52 return value.get();
53 }
54
55 public static AtomicCounterBuilder builder() {
56 return new Builder();
57 }
58
59 public static class Builder implements AtomicCounterBuilder {
60 @Override
61 public AtomicCounterBuilder withName(String name) {
62 return this;
63 }
64
65 @Override
66 public AtomicCounterBuilder withPartitionsDisabled() {
67 return this;
68 }
69
70 @Override
Ray Milkey24e60b32015-08-12 11:39:54 -070071 public AtomicCounterBuilder withMeteringDisabled() {
72 return this;
73 }
74
75 @Override
Ray Milkey24e60b32015-08-12 11:39:54 -070076 public AsyncAtomicCounter buildAsyncCounter() {
77 throw new UnsupportedOperationException("Async Counter is not supported");
78 }
79
80 @Override
81 public AtomicCounter build() {
82 return new TestAtomicCounter();
83 }
84 }
85}