CASMutator< T > Class Reference

Inherits net::spy::SpyObject.

Collaboration diagram for CASMutator< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

cas (final String key, final T initial, int initialExp, final CASMutation< T > m) throws Exception
 CASMutator (MemcachedClient c, Transcoder< T > tc)
 CASMutator (MemcachedClient c, Transcoder< T > tc, int max_tries)

Private Attributes

final MemcachedClient client
final int max
final Transcoder< T > transcoder

Static Private Attributes

static final int MAX_TRIES = 8192


Detailed Description

Object that provides mutation via CAS over a given memcache client.

Example usage (reinventing incr):

 // Get or create a client.
 MemcachedClient client=[...];

 // Get a Transcoder.
 Transcoder<Long> tc = new LongTranscoder();

 // Get a mutator instance that uses that client.
 CASMutator<Long> mutator=new CASMutator<Long>(client, tc);

 // Get a mutation that knows what to do when a value is found.
 CASMutation<Long> mutation=new CASMutation<Long>() {
     public Long getNewValue(Long current) {
         return current + 1;
     }
 };

 // Do a mutation.
 long currentValue=mutator.cas(someKey, 0L, 0, mutation);
 

Constructor & Destructor Documentation

CASMutator ( MemcachedClient  c,
Transcoder< T >  tc,
int  max_tries 
)

Construct a CASMutator that uses the given client.

Parameters:
c the client
tc the Transcoder to use
max_tries the maximum number of attempts to get a CAS to succeed

CASMutator ( MemcachedClient  c,
Transcoder< T >  tc 
)

Construct a CASMutator that uses the given client.

Parameters:
c the client
tc the Transcoder to use
max_tries the maximum number of attempts to get a CAS to succeed


Member Function Documentation

T cas ( final String  key,
final T  initial,
int  initialExp,
final CASMutation< T >  m 
) throws Exception

CAS a new value in for a key.

Parameters:
key the key to be CASed
initial the value to use when the object is not cached
initialExp the expiration time to use when initializing
m the mutation to perform on an object if a value exists for the key
Returns:
the new value that was set


Member Data Documentation

final MemcachedClient client [private]

final int max [private]

final int MAX_TRIES = 8192 [static, private]

final Transcoder<T> transcoder [private]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:37 2012 for Project Wonder by  doxygen 1.5.8