Package net.spy.memcached
Class TapClient
- java.lang.Object
-
- net.spy.memcached.TapClient
-
public class TapClient extends java.lang.Object
A tap client for memcached.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.net.InetSocketAddress>
addrs
protected long
messagesRead
protected java.util.HashMap<TapStream,TapConnectionProvider>
omap
protected java.util.concurrent.BlockingQueue<java.lang.Object>
rqueue
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getMessagesRead()
The number of messages read by all of the tap streams created with this client.ResponseMessage
getNextMessage()
Gets the next tap message from the queue of received tap messages.ResponseMessage
getNextMessage(long time, java.util.concurrent.TimeUnit timeunit)
Gets the next tap message from the queue of received tap messages.boolean
hasMoreMessages()
Decides whether the client has received tap messages or will receive more messages in the future.void
shutdown()
Shuts down all tap streams that are currently running.private void
tapAck(TapConnectionProvider conn, MemcachedNode node, TapOpcode opcode, int opaque, OperationCallback cb)
TapStream
tapCustom(java.lang.String id, RequestMessage message)
Allows the user to specify a custom tap message.TapStream
tapDump(java.lang.String id)
Specifies a tap stream that will take a snapshot of items in memcached and send them through a tap stream.
-
-
-
Field Detail
-
rqueue
protected java.util.concurrent.BlockingQueue<java.lang.Object> rqueue
-
omap
protected final java.util.HashMap<TapStream,TapConnectionProvider> omap
-
messagesRead
protected long messagesRead
-
addrs
private java.util.List<java.net.InetSocketAddress> addrs
-
-
Constructor Detail
-
TapClient
public TapClient(java.net.InetSocketAddress... ia)
Creates a tap client against the specified servers. This type of TapClient will TAP the specified servers, but will not be able to react to changes in the number of cluster nodes. Using the constructor which bootstraps itself from the cluster REST interface is preferred.- Parameters:
ia
- the addresses of each node in the cluster.
-
TapClient
public TapClient(java.util.List<java.net.InetSocketAddress> addrs)
Creates a tap client against the specified servers. This type of TapClient will TAP the specified servers, but will not be able to react to changes in the number of cluster nodes. Using the constructor which bootstraps itself from the cluster REST interface is preferred.- Parameters:
addrs
- a list of addresses containing each node in the cluster.
-
-
Method Detail
-
getNextMessage
public ResponseMessage getNextMessage()
Gets the next tap message from the queue of received tap messages.- Returns:
- The tap message at the head of the queue or null if the queue is empty for more than one second.
-
getNextMessage
public ResponseMessage getNextMessage(long time, java.util.concurrent.TimeUnit timeunit)
Gets the next tap message from the queue of received tap messages.- Parameters:
time
- the amount of time to wait for a message.timeunit
- the unit of time to use.- Returns:
- The tap message at the head of the queue or null if the queue is empty for the given amount of time.
-
hasMoreMessages
public boolean hasMoreMessages()
Decides whether the client has received tap messages or will receive more messages in the future.- Returns:
- true if the client has tap responses or expects to have responses in the future. False otherwise.
-
tapCustom
public TapStream tapCustom(java.lang.String id, RequestMessage message) throws javax.naming.ConfigurationException, java.io.IOException
Allows the user to specify a custom tap message.- Parameters:
id
- the named tap id that can be used to resume a disconnected tap streammessage
- the custom tap message that will be used to initiate the tap stream.- Returns:
- the operation that controls the tap stream.
- Throws:
javax.naming.ConfigurationException
- a bad configuration was received from the memcached cluster.java.io.IOException
- if there are errors connecting to the cluster.
-
tapDump
public TapStream tapDump(java.lang.String id) throws java.io.IOException, javax.naming.ConfigurationException
Specifies a tap stream that will take a snapshot of items in memcached and send them through a tap stream.- Parameters:
id
- the named tap id that can be used to resume a disconnected tap stream- Returns:
- the operation that controls the tap stream.
- Throws:
javax.naming.ConfigurationException
- a bad configuration was received from the memcached cluster.java.io.IOException
- If there are errors connecting to the cluster.
-
tapAck
private void tapAck(TapConnectionProvider conn, MemcachedNode node, TapOpcode opcode, int opaque, OperationCallback cb)
-
shutdown
public void shutdown()
Shuts down all tap streams that are currently running.
-
getMessagesRead
public long getMessagesRead()
The number of messages read by all of the tap streams created with this client. This will include a count of all tap response types.- Returns:
- The number of messages read
-
-