Package net.spy.memcached
Interface MemcachedNode
-
- All Known Implementing Classes:
AsciiMemcachedNodeImpl
,BinaryMemcachedNodeImpl
,MemcachedNodeROImpl
,TCPMemcachedNodeImpl
public interface MemcachedNode
Interface defining a connection to a memcached server.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addOp(Operation op)
Add an operation to the queue.void
authComplete()
Let the node know that auth is complete.void
completedRead()
Notify node of successful read.void
connected()
Notify this node that it has reconnected.void
copyInputQueue()
Move all of the operations delivered via addOperation into the internal write queue.java.util.Collection<Operation>
destroyInputQueue()
Extract all queued items for this node destructively.void
fillWriteBuffer(boolean optimizeGets)
Fill the write buffer with data from the next operations in the queue.void
fixupOps()
Fix up the selection ops on the selection key.int
getBytesRemainingToWrite()
Get the number of bytes remaining to write.java.nio.channels.SocketChannel
getChannel()
Get the SocketChannel for this connection.MemcachedConnection
getConnection()
int
getContinuousTimeout()
Operation
getCurrentReadOp()
Get the operation at the top of the queue that is requiring input.Operation
getCurrentWriteOp()
Get the operation at the top of the queue that has information available to write.java.nio.ByteBuffer
getRbuf()
Get the buffer used for reading data from this node.int
getReconnectCount()
Get the current reconnect count.int
getSelectionOps()
Compute the appropriate selection operations for the channel this MemcachedNode holds to the server.java.nio.channels.SelectionKey
getSk()
Get the selection key from this node.java.net.SocketAddress
getSocketAddress()
Get the SocketAddress of the server to which this node is connected.java.nio.ByteBuffer
getWbuf()
Get the buffer used for writing data to this node.boolean
hasReadOp()
True if an operation is available to read.boolean
hasWriteOp()
True if an operation is available to write.void
insertOp(Operation o)
Insert an operation to the beginning of the queue.boolean
isActive()
True if this node isactive.
i.e.boolean
isAuthenticated()
True if this node isauthenticated.
long
lastReadDelta()
Milliseconds since last successful read.void
reconnecting()
Notify this node that it will be reconnecting.void
registerChannel(java.nio.channels.SocketChannel ch, java.nio.channels.SelectionKey selectionKey)
Register a channel with this node.Operation
removeCurrentReadOp()
Remove the operation at the top of the queue that is requiring input.Operation
removeCurrentWriteOp()
Remove the operation at the top of the queue that has information available to write.void
setChannel(java.nio.channels.SocketChannel to)
Set the SocketChannel this node uses.void
setConnection(MemcachedConnection connection)
void
setContinuousTimeout(boolean timedOut)
Count 'time out' exceptions to drop connections that fail perpetually.void
setSk(java.nio.channels.SelectionKey to)
Set the selection key for this node.void
setupForAuth()
Tell a node to set up for authentication.void
setupResend()
Clear the queue of currently processing operations by either cancelling them or setting them up to be reapplied after a reconnect.void
transitionWriteItem()
Transition the current write item into a read state.int
writeSome()
Write some bytes and return the number of bytes written.
-
-
-
Method Detail
-
copyInputQueue
void copyInputQueue()
Move all of the operations delivered via addOperation into the internal write queue.
-
destroyInputQueue
java.util.Collection<Operation> destroyInputQueue()
Extract all queued items for this node destructively. This is useful for redistributing items.
-
setupResend
void setupResend()
Clear the queue of currently processing operations by either cancelling them or setting them up to be reapplied after a reconnect.
-
fillWriteBuffer
void fillWriteBuffer(boolean optimizeGets)
Fill the write buffer with data from the next operations in the queue.- Parameters:
optimizeGets
- if true, combine sequential gets into a single multi-key get
-
transitionWriteItem
void transitionWriteItem()
Transition the current write item into a read state.
-
getCurrentReadOp
Operation getCurrentReadOp()
Get the operation at the top of the queue that is requiring input.
-
removeCurrentReadOp
Operation removeCurrentReadOp()
Remove the operation at the top of the queue that is requiring input.
-
getCurrentWriteOp
Operation getCurrentWriteOp()
Get the operation at the top of the queue that has information available to write.
-
removeCurrentWriteOp
Operation removeCurrentWriteOp()
Remove the operation at the top of the queue that has information available to write.
-
hasReadOp
boolean hasReadOp()
True if an operation is available to read.
-
hasWriteOp
boolean hasWriteOp()
True if an operation is available to write.
-
addOp
void addOp(Operation op)
Add an operation to the queue. Authentication operations should never be added to the queue, but this is not checked.
-
insertOp
void insertOp(Operation o)
Insert an operation to the beginning of the queue. This method is meant to be invoked rarely.
-
getSelectionOps
int getSelectionOps()
Compute the appropriate selection operations for the channel this MemcachedNode holds to the server.
-
getRbuf
java.nio.ByteBuffer getRbuf()
Get the buffer used for reading data from this node.
-
getWbuf
java.nio.ByteBuffer getWbuf()
Get the buffer used for writing data to this node.
-
getSocketAddress
java.net.SocketAddress getSocketAddress()
Get the SocketAddress of the server to which this node is connected.
-
isActive
boolean isActive()
True if this node isactive.
i.e. is is currently connected and expected to be able to process requests
-
isAuthenticated
boolean isAuthenticated()
True if this node isauthenticated.
-
lastReadDelta
long lastReadDelta()
Milliseconds since last successful read.
-
completedRead
void completedRead()
Notify node of successful read. This is used so the node can keep track of any internal debugging or state it cares about on read.
-
reconnecting
void reconnecting()
Notify this node that it will be reconnecting.
-
connected
void connected()
Notify this node that it has reconnected.
-
getReconnectCount
int getReconnectCount()
Get the current reconnect count.
-
registerChannel
void registerChannel(java.nio.channels.SocketChannel ch, java.nio.channels.SelectionKey selectionKey)
Register a channel with this node.
-
setChannel
void setChannel(java.nio.channels.SocketChannel to)
Set the SocketChannel this node uses.
-
getChannel
java.nio.channels.SocketChannel getChannel()
Get the SocketChannel for this connection.
-
setSk
void setSk(java.nio.channels.SelectionKey to)
Set the selection key for this node.
-
getSk
java.nio.channels.SelectionKey getSk()
Get the selection key from this node.
-
getBytesRemainingToWrite
int getBytesRemainingToWrite()
Get the number of bytes remaining to write.
-
writeSome
int writeSome() throws java.io.IOException
Write some bytes and return the number of bytes written.- Returns:
- the number of bytes written
- Throws:
java.io.IOException
- if there's a problem writing
-
fixupOps
void fixupOps()
Fix up the selection ops on the selection key.
-
authComplete
void authComplete()
Let the node know that auth is complete. Typically this would mean the node can start processing and accept new operations to its input queue.
-
setupForAuth
void setupForAuth()
Tell a node to set up for authentication. Typically this would mean blocking additions to the queue. In a reconnect situation this may mean putting any queued operations on hold to get to an auth complete state.
-
setContinuousTimeout
void setContinuousTimeout(boolean timedOut)
Count 'time out' exceptions to drop connections that fail perpetually.- Parameters:
timedOut
-
-
getContinuousTimeout
int getContinuousTimeout()
-
getConnection
MemcachedConnection getConnection()
-
setConnection
void setConnection(MemcachedConnection connection)
-
-