Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | /** |
| 19 | * Distributed version of java.util.concurrent.atomic.AtomicReference. |
| 20 | * |
| 21 | * @param <V> value type |
| 22 | */ |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 23 | public interface AtomicValue<V> extends DistributedPrimitive { |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 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 | } |