blob: dfa0fb3c88970332c39a8150340b95855527d7f5 [file] [log] [blame]
Madan Jampani762246d2015-07-21 15:40:59 -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
18/**
19 * Distributed version of java.util.concurrent.atomic.AtomicReference.
20 *
21 * @param <V> value type
22 */
23public interface AtomicValue<V> {
24
25 /**
26 * Atomically sets the value to the given updated value if the current value is equal to the expected value.
27 * <p>
28 * IMPORTANT: Equality is based on the equality of the serialized byte[] representations.
29 * <p>
30 * @param expect the expected value
31 * @param update the new value
32 * @return true if successful. false return indicates that the actual value was not equal to the expected value.
33 */
34 boolean compareAndSet(V expect, V update);
35
36 /**
37 * Gets the current value.
38 * @return current value
39 */
40 V get();
41
42 /**
43 * Atomically sets to the given value and returns the old value.
44 * @param value the new value
45 * @return previous value
46 */
47 V getAndSet(V value);
48
49 /**
50 * Sets to the given value.
51 * @param value new value
52 */
53 void set(V value);
54
55 /**
56 * Registers the specified listener to be notified whenever the atomic value is updated.
57 *
58 * @param listener listener to notify about events
59 */
60 void addListener(AtomicValueEventListener<V> listener);
61
62 /**
63 * Unregisters the specified listener such that it will no longer
64 * receive atomic value update notifications.
65 *
66 * @param listener listener to unregister
67 */
68 void removeListener(AtomicValueEventListener<V> listener);
69}