blob: 26a5040c69125b1eda77338e230845c8ebfeb3d1 [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
andreafd912ac2015-10-02 14:58:35 -070051 public void set(long value) {
52 this.value.set(value);
53 }
54
55 @Override
Ray Milkey24e60b32015-08-12 11:39:54 -070056 public long get() {
57 return value.get();
58 }
59
60 public static AtomicCounterBuilder builder() {
61 return new Builder();
62 }
63
64 public static class Builder implements AtomicCounterBuilder {
65 @Override
66 public AtomicCounterBuilder withName(String name) {
67 return this;
68 }
69
70 @Override
71 public AtomicCounterBuilder withPartitionsDisabled() {
72 return this;
73 }
74
75 @Override
Ray Milkey24e60b32015-08-12 11:39:54 -070076 public AtomicCounterBuilder withMeteringDisabled() {
77 return this;
78 }
79
80 @Override
Ray Milkey24e60b32015-08-12 11:39:54 -070081 public AsyncAtomicCounter buildAsyncCounter() {
82 throw new UnsupportedOperationException("Async Counter is not supported");
83 }
84
85 @Override
86 public AtomicCounter build() {
87 return new TestAtomicCounter();
88 }
89 }
90}