net.spy.memcached
Class TapConnectionProvider

java.lang.Object
  extended by java.lang.Thread
      extended by net.spy.memcached.compat.SpyThread
          extended by net.spy.memcached.TapConnectionProvider
All Implemented Interfaces:
Runnable, ConnectionObserver, Reconfigurable

public class TapConnectionProvider
extends SpyThread
implements ConnectionObserver, Reconfigurable


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TapConnectionProvider(InetSocketAddress... ia)
          Get a memcache client operating on the specified memcached locations.
TapConnectionProvider(List<InetSocketAddress> addrs)
          Get a memcache client over the specified memcached locations.
TapConnectionProvider(List<URI> baseList, String bucketName, String usr, String pwd)
          Get a MemcachedClient based on the REST response from a Membase server.
 
Method Summary
 boolean addObserver(ConnectionObserver obs)
          Add a connection observer.
 void connectionEstablished(SocketAddress sa, int reconnectCount)
          A connection has just successfully been established on the given socket.
 void connectionLost(SocketAddress sa)
          A connection was just lost on the given socket.
 void reconfigure(Bucket bucket)
          Call on a configuration update
 boolean removeObserver(ConnectionObserver obs)
          Remove a connection observer.
 void run()
          Infinitely loop processing IO.
 void shutdown()
          Shut down immediately.
 boolean shutdown(long timeout, TimeUnit unit)
          Shut down this client gracefully.
 boolean waitForQueues(long timeout, TimeUnit unit)
          Wait for the queues to die down.
 
Methods inherited from class net.spy.memcached.compat.SpyThread
getLogger
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TapConnectionProvider

public TapConnectionProvider(InetSocketAddress... ia)
                      throws IOException
Get a memcache client operating on the specified memcached locations.

Parameters:
ia - the memcached locations
Throws:
IOException - if connections cannot be established

TapConnectionProvider

public TapConnectionProvider(List<InetSocketAddress> addrs)
                      throws IOException
Get a memcache client over the specified memcached locations.

Parameters:
addrs - the socket addrs
Throws:
IOException - if connections cannot be established

TapConnectionProvider

public TapConnectionProvider(List<URI> baseList,
                             String bucketName,
                             String usr,
                             String pwd)
                      throws IOException,
                             ConfigurationException
Get a MemcachedClient based on the REST response from a Membase server.

Parameters:
baseList -
bucketName -
usr -
pwd -
Throws:
IOException
ConfigurationException
Method Detail

run

public void run()
Infinitely loop processing IO.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

addObserver

public boolean addObserver(ConnectionObserver obs)
Add a connection observer. If connections are already established, your observer will be called with the address and -1.

Parameters:
obs - the ConnectionObserver you wish to add
Returns:
true if the observer was added.

removeObserver

public boolean removeObserver(ConnectionObserver obs)
Remove a connection observer.

Parameters:
obs - the ConnectionObserver you wish to add
Returns:
true if the observer existed, but no longer does

connectionEstablished

public void connectionEstablished(SocketAddress sa,
                                  int reconnectCount)
Description copied from interface: ConnectionObserver
A connection has just successfully been established on the given socket.

Specified by:
connectionEstablished in interface ConnectionObserver
Parameters:
sa - the address of the node whose connection was established
reconnectCount - the number of attempts before the connection was established

connectionLost

public void connectionLost(SocketAddress sa)
Description copied from interface: ConnectionObserver
A connection was just lost on the given socket.

Specified by:
connectionLost in interface ConnectionObserver
Parameters:
sa - the address of the node whose connection was lost

reconfigure

public void reconfigure(Bucket bucket)
Description copied from interface: Reconfigurable
Call on a configuration update

Specified by:
reconfigure in interface Reconfigurable
Parameters:
bucket - updated vbucket configuration

shutdown

public void shutdown()
Shut down immediately.


shutdown

public boolean shutdown(long timeout,
                        TimeUnit unit)
Shut down this client gracefully.

Parameters:
timeout - the amount of time for shutdown
unit - the TimeUnit for the timeout
Returns:
result of the shutdown request

waitForQueues

public boolean waitForQueues(long timeout,
                             TimeUnit unit)
Wait for the queues to die down.

Parameters:
timeout - the amount of time time for shutdown
unit - the TimeUnit for the timeout
Returns:
result of the request for the wait
Throws:
IllegalStateException - in the rare circumstance where queue is too full to accept any more requests