Yuta HIGUCHI | 598e57e | 2014-06-16 21:19:01 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.core.datastore.hazelcast; |
| 2 | |
| 3 | import com.hazelcast.core.HazelcastInstance; |
| 4 | import com.hazelcast.core.IAtomicLong; |
| 5 | |
| 6 | import net.onrc.onos.core.util.distributed.DistributedAtomicLong; |
| 7 | |
| 8 | /** |
| 9 | * Hazelcast implementation of DistributedAtomicLong. |
| 10 | */ |
| 11 | public class HZDistributedAtomicLong implements DistributedAtomicLong { |
| 12 | private final IAtomicLong hzAtomicLong; |
| 13 | |
| 14 | // TODO remove dependency HZClient if possible |
| 15 | /** |
| 16 | * Creates or Gets the DistributedAtomicLong instance. |
| 17 | * |
| 18 | * @param client client to use |
| 19 | * @param name the name of the DistributedAtomicLong instance |
| 20 | */ |
| 21 | public HZDistributedAtomicLong(HZClient client, String name) { |
| 22 | this(client.getHZInstance(), name); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Creates or Gets the DistributedAtomicLong instance. |
| 27 | * |
| 28 | * @param instance HazelcastInstance to use |
| 29 | * @param name the name of the DistributedAtomicLong instance. |
| 30 | */ |
| 31 | public HZDistributedAtomicLong(HazelcastInstance instance, String name) { |
| 32 | hzAtomicLong = instance.getAtomicLong(name); |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public long get() { |
| 37 | return hzAtomicLong.get(); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public long addAndGet(long delta) { |
| 42 | return hzAtomicLong.addAndGet(delta); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void set(long newValue) { |
| 47 | hzAtomicLong.set(newValue); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public long incrementAndGet() { |
| 52 | return hzAtomicLong.incrementAndGet(); |
| 53 | } |
| 54 | } |