Package net.rubyeye.xmemcached
Class Counter
- java.lang.Object
-
- net.rubyeye.xmemcached.Counter
-
public final class Counter extends java.lang.ObjectCounter,encapsulate the incr/decr methods.
-
-
Field Summary
Fields Modifier and Type Field Description private longinitialValueprivate java.lang.Stringkeyprivate MemcachedClientmemcachedClient
-
Constructor Summary
Constructors Constructor Description Counter(MemcachedClient memcachedClient, java.lang.String key, long initialValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(long delta)Add value and get the resultlongdecrementAndGet()Decrease value by onebooleanequals(java.lang.Object obj)longget()Get current valuejava.lang.StringgetKey()inthashCode()longincrementAndGet()Increase value by onevoidset(long value)Set counter's value to expected.
-
-
-
Field Detail
-
memcachedClient
private final MemcachedClient memcachedClient
-
key
private final java.lang.String key
-
initialValue
private final long initialValue
-
-
Constructor Detail
-
Counter
public Counter(MemcachedClient memcachedClient, java.lang.String key, long initialValue)
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getKey
public final java.lang.String getKey()
-
get
public long get() throws MemcachedException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionGet current value- Returns:
- Throws:
MemcachedExceptionjava.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
set
public void set(long value) throws MemcachedException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionSet counter's value to expected.- Parameters:
value-- Throws:
MemcachedExceptionjava.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
incrementAndGet
public long incrementAndGet() throws MemcachedException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionIncrease value by one- Returns:
- Throws:
MemcachedExceptionjava.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
decrementAndGet
public long decrementAndGet() throws MemcachedException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionDecrease value by one- Returns:
- Throws:
MemcachedExceptionjava.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
addAndGet
public long addAndGet(long delta) throws MemcachedException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionAdd value and get the result- Parameters:
delta-- Returns:
- Throws:
MemcachedExceptionjava.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
-