Package net.rubyeye.xmemcached.impl
Class MemcachedConnector
java.lang.Object
com.google.code.yanf4j.core.impl.AbstractController
com.google.code.yanf4j.nio.impl.NioController
com.google.code.yanf4j.nio.impl.SocketChannelController
net.rubyeye.xmemcached.impl.MemcachedConnector
- All Implemented Interfaces:
Controller
,ControllerLifeCycle
,SelectionKeyHandler
,Connector
Connected session manager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
Inner state listenner,manage session monitor.(package private) class
Session monitor for healing sessions. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BufferAllocator
private final CommandFactory
private int
private boolean
private boolean
private final FlowControl
private long
private final MemcachedOptimizer
protected Protocol
private final Random
private final Set
<InetSocketAddress> protected MemcachedSessionComparator
protected MemcachedSessionLocator
protected final ConcurrentHashMap
<InetSocketAddress, Queue<Session>> private final MemcachedConnector.SessionMonitor
private boolean
private final ConcurrentHashMap
<InetSocketAddress, List<Session>> private final DelayQueue
<ReconnectRequest> Fields inherited from class com.google.code.yanf4j.nio.impl.SocketChannelController
soLingerOn
Fields inherited from class com.google.code.yanf4j.nio.impl.NioController
selectorManager, selectorPoolSize
Fields inherited from class com.google.code.yanf4j.core.impl.AbstractController
codecFactory, configuration, dispatchMessageDispatcher, dispatchMessageThreadCount, handler, handleReadWriteConcurrently, localSocketAddress, log, readEventDispatcher, readThreadCount, sessionSet, sessionTimeout, socketOptions, soTimeout, started, stateListeners, statistics, statisticsInterval, writeEventDispatcher, writeThreadCount
-
Constructor Summary
ConstructorsConstructorDescriptionMemcachedConnector
(Configuration configuration, MemcachedSessionLocator locator, MemcachedSessionComparator comparator, BufferAllocator allocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addMainSession
(Session session, InetSocketAddress lastReolvedAddr, InetSocketAddressWrapper addrWrapper) void
addSession
(Session session) private void
addStandbySession
(Session session, InetSocketAddress mainNodeAddress, InetSocketAddress lastResolvedMainAddr, InetSocketAddressWrapper addrWrapper) void
addToWatingQueue
(ReconnectRequest request) protected Queue
<WriteMessage> Build write queue for sessionprotected NioSession
private void
cancelKey
(SelectionKey key) void
closeChannel
(Selector selector) connect
(InetSocketAddressWrapper addressWrapper) protected MemcachedTCPSession
createSession
(SocketChannel socketChannel, InetSocketAddressWrapper wrapper) protected void
doStart()
Inner startupfinal Session
findSessionByKey
(String key) private MemcachedSession
findStandbySession
(MemcachedSession session) long
Returns the noreply operations flow control manager.Get session by InetSocketAddressgetSessionListBySocketAddress
(InetSocketAddress inetSocketAddress) Returns main node's standby session list.void
onConnect
(SelectionKey key) void
Make all connection sending a quit command to memcachedprivate void
removeMainSession
(Session session) void
removeReconnectRequest
(InetSocketAddress inetSocketAddress) void
removeSession
(Session session) private void
removeStandbySession
(Session session, InetSocketAddress mainNodeAddr) void
setBufferAllocator
(BufferAllocator allocator) final void
setConnectionPoolSize
(int poolSize) void
setEnableHealSession
(boolean enableHealSession) void
setFailureMode
(boolean failureMode) final void
setHealSessionInterval
(long healConnectionInterval) void
setMergeFactor
(int mergeFactor) void
setOptimizeGet
(boolean optimiezeGet) void
setOptimizeMergeBuffer
(boolean optimizeMergeBuffer) void
setSessionComparator
(MemcachedSessionComparator sessionComparator) void
setSessionLocator
(MemcachedSessionLocator sessionLocator) void
final void
Methods inherited from class com.google.code.yanf4j.nio.impl.SocketChannelController
configureSocketChannel, dispatchReadEvent, dispatchWriteEvent, setSoLinger
Methods inherited from class com.google.code.yanf4j.nio.impl.NioController
bind, buildSessionConfig, closeSelectionKey, getSelectorManager, getSelectorPoolSize, initialSelectorManager, onRead, onWrite, setSelectorPoolSize, start0, stop0
Methods inherited from class com.google.code.yanf4j.core.impl.AbstractController
addStateListener, bind, checkStatisticsForRestart, getCodecFactory, getConfiguration, getDispatchMessageThreadCount, getHandler, getLocalSocketAddress, getPort, getReadThreadCount, getReceiveThroughputLimit, getSendThroughputLimit, getSessionIdleTimeout, getSessionTimeout, getSocketOption, getSoTimeout, getStatistics, getWriteThreadCount, isHandleReadWriteConcurrently, isStarted, notifyAllSessionClosed, notifyException, notifyReady, notifyStarted, notifyStopped, onAccept, registerSession, removeStateListener, setCodecFactory, setConfiguration, setDispatchMessageThreadCount, setHandler, setHandleReadWriteConcurrently, setLocalSocketAddress, setReadThreadCount, setReceiveThroughputLimit, setSendThroughputLimit, setSessionIdleTimeout, setSessionTimeout, setSocketOption, setSocketOptions, setSoTimeout, setWriteThreadCount, start, stop, unregisterSession
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.rubyeye.xmemcached.networking.Connector
setSocketOptions
Methods inherited from interface com.google.code.yanf4j.core.Controller
addStateListener, getCodecFactory, getDispatchMessageThreadCount, getHandler, getLocalSocketAddress, getPort, getReadThreadCount, getReceiveThroughputLimit, getSendThroughputLimit, getSessionIdleTimeout, getSessionTimeout, getSoTimeout, getStatistics, getWriteThreadCount, isHandleReadWriteConcurrently, isStarted, removeStateListener, setCodecFactory, setDispatchMessageThreadCount, setHandler, setHandleReadWriteConcurrently, setLocalSocketAddress, setReadThreadCount, setReceiveThroughputLimit, setSendThroughputLimit, setSessionIdleTimeout, setSessionTimeout, setSocketOption, setSoTimeout, setWriteThreadCount, start, stop
Methods inherited from interface com.google.code.yanf4j.nio.SelectionKeyHandler
onAccept
-
Field Details
-
waitingQueue
-
bufferAllocator
-
removedAddrSet
-
optimiezer
-
healSessionInterval
private long healSessionInterval -
connectionPoolSize
private int connectionPoolSize -
protocol
-
enableHealSession
private boolean enableHealSession -
commandFactory
-
failureMode
private boolean failureMode -
standbySessionMap
-
flowControl
-
shuttingDown
private volatile boolean shuttingDown -
sessionLocator
-
sessionComparator
-
sessionMap
-
random
-
sessionMonitor
-
-
Constructor Details
-
MemcachedConnector
public MemcachedConnector(Configuration configuration, MemcachedSessionLocator locator, MemcachedSessionComparator comparator, BufferAllocator allocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations)
-
-
Method Details
-
shuttingDown
public void shuttingDown() -
setSessionLocator
- Specified by:
setSessionLocator
in interfaceConnector
-
setSessionComparator
- Specified by:
setSessionComparator
in interfaceConnector
-
setEnableHealSession
public void setEnableHealSession(boolean enableHealSession) - Specified by:
setEnableHealSession
in interfaceConnector
-
getReconnectRequestQueue
- Specified by:
getReconnectRequestQueue
in interfaceConnector
-
getSessionSet
- Specified by:
getSessionSet
in interfaceConnector
- Overrides:
getSessionSet
in classAbstractController
-
setHealSessionInterval
public final void setHealSessionInterval(long healConnectionInterval) - Specified by:
setHealSessionInterval
in interfaceConnector
-
getHealSessionInterval
public long getHealSessionInterval()- Specified by:
getHealSessionInterval
in interfaceConnector
-
setOptimizeGet
public void setOptimizeGet(boolean optimiezeGet) - Specified by:
setOptimizeGet
in interfaceConnector
-
setOptimizeMergeBuffer
public void setOptimizeMergeBuffer(boolean optimizeMergeBuffer) - Specified by:
setOptimizeMergeBuffer
in interfaceConnector
-
getProtocol
-
addSession
-
addMainSession
private void addMainSession(Session session, InetSocketAddress lastReolvedAddr, InetSocketAddressWrapper addrWrapper) -
addStandbySession
private void addStandbySession(Session session, InetSocketAddress mainNodeAddress, InetSocketAddress lastResolvedMainAddr, InetSocketAddressWrapper addrWrapper) -
getSessionListBySocketAddress
-
removeReconnectRequest
- Specified by:
removeReconnectRequest
in interfaceConnector
-
updateSessions
public final void updateSessions()- Specified by:
updateSessions
in interfaceConnector
-
removeSession
- Specified by:
removeSession
in interfaceConnector
-
removeMainSession
-
removeStandbySession
-
doStart
Description copied from class:NioController
Inner startup- Specified by:
doStart
in classNioController
- Throws:
IOException
-
onConnect
- Specified by:
onConnect
in interfaceSelectionKeyHandler
- Overrides:
onConnect
in classAbstractController
- Throws:
IOException
-
cancelKey
- Throws:
IOException
-
createSession
protected MemcachedTCPSession createSession(SocketChannel socketChannel, InetSocketAddressWrapper wrapper) -
addToWatingQueue
- Specified by:
addToWatingQueue
in interfaceConnector
-
connect
-
closeChannel
- Specified by:
closeChannel
in interfaceSelectionKeyHandler
- Throws:
IOException
-
send
- Specified by:
send
in interfaceConnector
- Throws:
MemcachedException
-
findStandbySession
-
getStandbySessionListByMainNodeAddr
Returns main node's standby session list.- Specified by:
getStandbySessionListByMainNodeAddr
in interfaceConnector
- Parameters:
addr
-- Returns:
-
findSessionByKey
-
getSessionByAddress
Get session by InetSocketAddress- Specified by:
getSessionByAddress
in interfaceConnector
- Parameters:
addr
-- Returns:
-
setConnectionPoolSize
public final void setConnectionPoolSize(int poolSize) - Specified by:
setConnectionPoolSize
in interfaceConnector
-
setMergeFactor
public void setMergeFactor(int mergeFactor) - Specified by:
setMergeFactor
in interfaceConnector
-
getNoReplyOpsFlowControl
Description copied from interface:Connector
Returns the noreply operations flow control manager.- Specified by:
getNoReplyOpsFlowControl
in interfaceConnector
- Returns:
-
buildSession
- Overrides:
buildSession
in classSocketChannelController
-
buildQueue
Build write queue for session- Overrides:
buildQueue
in classAbstractController
- Returns:
-
getBufferAllocator
-
quitAllSessions
public void quitAllSessions()Description copied from interface:Connector
Make all connection sending a quit command to memcached- Specified by:
quitAllSessions
in interfaceConnector
-
setFailureMode
public void setFailureMode(boolean failureMode) - Specified by:
setFailureMode
in interfaceConnector
-
setBufferAllocator
- Specified by:
setBufferAllocator
in interfaceConnector
-
getServerAddresses
-