Jordan Halterman | c955df7 | 2017-02-04 20:43:28 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present 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 | */ |
| 16 | package org.onosproject.store.primitives.resources.impl; |
| 17 | |
| 18 | import io.atomix.copycat.client.CopycatClient; |
| 19 | import io.atomix.resource.AbstractResource; |
| 20 | import io.atomix.resource.ResourceTypeInfo; |
| 21 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.AddAndGet; |
| 22 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Clear; |
| 23 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.DecrementAndGet; |
| 24 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Get; |
| 25 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.GetAndAdd; |
| 26 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.GetAndDecrement; |
| 27 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.GetAndIncrement; |
| 28 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.IncrementAndGet; |
| 29 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.IsEmpty; |
| 30 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Put; |
| 31 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.PutIfAbsent; |
| 32 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Remove; |
| 33 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.RemoveValue; |
| 34 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Replace; |
| 35 | import org.onosproject.store.primitives.resources.impl.AtomixAtomicCounterMapCommands.Size; |
| 36 | import org.onosproject.store.service.AsyncAtomicCounterMap; |
| 37 | |
| 38 | import java.util.Properties; |
| 39 | import java.util.concurrent.CompletableFuture; |
| 40 | |
| 41 | /** |
| 42 | * {@code AsyncAtomicCounterMap} implementation backed by Atomix. |
| 43 | */ |
| 44 | @ResourceTypeInfo(id = -157, factory = AtomixAtomicCounterMapFactory.class) |
| 45 | public class AtomixAtomicCounterMap extends AbstractResource<AtomixAtomicCounterMap> |
| 46 | implements AsyncAtomicCounterMap<String> { |
| 47 | |
| 48 | public AtomixAtomicCounterMap(CopycatClient client, Properties options) { |
| 49 | super(client, options); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String name() { |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public CompletableFuture<Long> incrementAndGet(String key) { |
| 59 | return client.submit(new IncrementAndGet(key)); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public CompletableFuture<Long> decrementAndGet(String key) { |
| 64 | return client.submit(new DecrementAndGet(key)); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public CompletableFuture<Long> getAndIncrement(String key) { |
| 69 | return client.submit(new GetAndIncrement(key)); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public CompletableFuture<Long> getAndDecrement(String key) { |
| 74 | return client.submit(new GetAndDecrement(key)); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public CompletableFuture<Long> addAndGet(String key, long delta) { |
| 79 | return client.submit(new AddAndGet(key, delta)); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public CompletableFuture<Long> getAndAdd(String key, long delta) { |
| 84 | return client.submit(new GetAndAdd(key, delta)); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public CompletableFuture<Long> get(String key) { |
| 89 | return client.submit(new Get(key)); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public CompletableFuture<Long> put(String key, long newValue) { |
| 94 | return client.submit(new Put(key, newValue)); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public CompletableFuture<Long> putIfAbsent(String key, long newValue) { |
| 99 | return client.submit(new PutIfAbsent(key, newValue)); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public CompletableFuture<Boolean> replace(String key, long expectedOldValue, long newValue) { |
| 104 | return client.submit(new Replace(key, expectedOldValue, newValue)); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public CompletableFuture<Long> remove(String key) { |
| 109 | return client.submit(new Remove(key)); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public CompletableFuture<Boolean> remove(String key, long value) { |
| 114 | return client.submit(new RemoveValue(key, value)); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public CompletableFuture<Integer> size() { |
| 119 | return client.submit(new Size()); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public CompletableFuture<Boolean> isEmpty() { |
| 124 | return client.submit(new IsEmpty()); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public CompletableFuture<Void> clear() { |
| 129 | return client.submit(new Clear()); |
| 130 | } |
| 131 | } |