Package com.google.code.yanf4j.core.impl
Class AbstractController
- java.lang.Object
-
- com.google.code.yanf4j.core.impl.AbstractController
-
- All Implemented Interfaces:
Controller,ControllerLifeCycle
- Direct Known Subclasses:
NioController
public abstract class AbstractController extends java.lang.Object implements Controller, ControllerLifeCycle
Base controller
-
-
Field Summary
Fields Modifier and Type Field Description protected CodecFactorycodecFactoryCodec Factoryprotected Configurationconfigurationprotected DispatcherdispatchMessageDispatcherprotected intdispatchMessageThreadCountprotected HandlerhandlerEvent handlerprotected booleanhandleReadWriteConcurrentlyprivate booleanisHutdownHookCalledprotected java.net.InetSocketAddresslocalSocketAddresslocal bind addressprotected static org.slf4j.Loggerlogprotected DispatcherreadEventDispatcherprotected intreadThreadCountRead event processing thread countprotected java.util.Set<Session>sessionSetConnected session setprotected longsessionTimeoutprivate java.lang.ThreadshutdownHookThreadprotected java.util.Map<SocketOption,java.lang.Object>socketOptionsSocket optionsprotected intsoTimeoutprotected booleanstartedStatusprotected java.util.concurrent.CopyOnWriteArrayList<ControllerStateListener>stateListenerscontroller state listener listprotected Statisticsstatisticsprotected longstatisticsIntervalprotected DispatcherwriteEventDispatcherprotected intwriteThreadCount
-
Constructor Summary
Constructors Constructor Description AbstractController()AbstractController(Configuration configuration)AbstractController(Configuration configuration, CodecFactory codecFactory)AbstractController(Configuration configuration, Handler handler, CodecFactory codecFactory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddStateListener(ControllerStateListener listener)voidbind(java.net.InetSocketAddress inetSocketAddress)Bind localhost addressprotected java.util.Queue<WriteMessage>buildQueue()Build write queue for sessionvoidcheckStatisticsForRestart()private voidclearStateListeners()CodecFactorygetCodecFactory()ConfigurationgetConfiguration()intgetDispatchMessageThreadCount()HandlergetHandler()java.net.InetSocketAddressgetLocalSocketAddress()intgetPort()(package private) DispatchergetReadEventDispatcher()intgetReadThreadCount()doublegetReceiveThroughputLimit()doublegetSendThroughputLimit()longgetSessionIdleTimeout()java.util.Set<Session>getSessionSet()longgetSessionTimeout()<T> TgetSocketOption(SocketOption<T> socketOption)intgetSoTimeout()StatisticsgetStatistics()intgetWriteThreadCount()private voidinit(Configuration configuration, Handler handler, CodecFactory codecFactory)booleanisHandleReadWriteConcurrently()booleanisStarted()voidnotifyAllSessionClosed()voidnotifyException(java.lang.Throwable t)voidnotifyReady()voidnotifyStarted()voidnotifyStopped()voidonAccept(java.nio.channels.SelectionKey sk)voidonConnect(java.nio.channels.SelectionKey key)voidregisterSession(Session session)voidremoveStateListener(ControllerStateListener listener)voidsetCodecFactory(CodecFactory codecFactory)voidsetConfiguration(Configuration configuration)(package private) voidsetDispatchMessageDispatcher(Dispatcher dispatcher)voidsetDispatchMessageThreadCount(int dispatchMessageThreadPoolSize)voidsetHandler(Handler handler)voidsetHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)voidsetLocalSocketAddress(java.net.InetSocketAddress inetSocketAddress)(package private) voidsetReadEventDispatcher(Dispatcher dispatcher)voidsetReadThreadCount(int readThreadCount)voidsetReceiveThroughputLimit(double receiveThroughputLimit)voidsetSendThroughputLimit(double sendThroughputLimit)voidsetSessionIdleTimeout(long sessionIdleTimeout)voidsetSessionTimeout(long sessionTimeout)<T> voidsetSocketOption(SocketOption<T> socketOption, T value)voidsetSocketOptions(java.util.Map<SocketOption,java.lang.Object> socketOptions)voidsetSoTimeout(int timeout)(package private) voidsetStarted(boolean started)private voidsetStatisticsConfig(Configuration configuration)(package private) voidsetWriteEventDispatcher(Dispatcher dispatcher)voidsetWriteThreadCount(int writeThreadCount)voidstart()protected abstract voidstart0()private voidstartStatistics()voidstop()protected abstract voidstop0()private voidstopDispatcher()private voidstopStatistics()voidunregisterSession(Session session)
-
-
-
Field Detail
-
statistics
protected Statistics statistics
-
statisticsInterval
protected long statisticsInterval
-
log
protected static final org.slf4j.Logger log
-
stateListeners
protected java.util.concurrent.CopyOnWriteArrayList<ControllerStateListener> stateListeners
controller state listener list
-
handler
protected Handler handler
Event handler
-
codecFactory
protected CodecFactory codecFactory
Codec Factory
-
started
protected volatile boolean started
Status
-
localSocketAddress
protected java.net.InetSocketAddress localSocketAddress
local bind address
-
readThreadCount
protected int readThreadCount
Read event processing thread count
-
writeThreadCount
protected int writeThreadCount
-
dispatchMessageThreadCount
protected int dispatchMessageThreadCount
-
configuration
protected Configuration configuration
-
readEventDispatcher
protected Dispatcher readEventDispatcher
-
dispatchMessageDispatcher
protected Dispatcher dispatchMessageDispatcher
-
writeEventDispatcher
protected Dispatcher writeEventDispatcher
-
sessionTimeout
protected long sessionTimeout
-
handleReadWriteConcurrently
protected boolean handleReadWriteConcurrently
-
soTimeout
protected int soTimeout
-
socketOptions
protected java.util.Map<SocketOption,java.lang.Object> socketOptions
Socket options
-
sessionSet
protected java.util.Set<Session> sessionSet
Connected session set
-
shutdownHookThread
private java.lang.Thread shutdownHookThread
-
isHutdownHookCalled
private volatile boolean isHutdownHookCalled
-
-
Constructor Detail
-
AbstractController
public AbstractController()
-
AbstractController
public AbstractController(Configuration configuration)
-
AbstractController
public AbstractController(Configuration configuration, CodecFactory codecFactory)
-
AbstractController
public AbstractController(Configuration configuration, Handler handler, CodecFactory codecFactory)
-
-
Method Detail
-
setSocketOptions
public void setSocketOptions(java.util.Map<SocketOption,java.lang.Object> socketOptions)
-
getDispatchMessageThreadCount
public final int getDispatchMessageThreadCount()
- Specified by:
getDispatchMessageThreadCountin interfaceController
-
setDispatchMessageThreadCount
public final void setDispatchMessageThreadCount(int dispatchMessageThreadPoolSize)
- Specified by:
setDispatchMessageThreadCountin interfaceController
-
getSessionIdleTimeout
public long getSessionIdleTimeout()
- Specified by:
getSessionIdleTimeoutin interfaceController
-
buildQueue
protected java.util.Queue<WriteMessage> buildQueue()
Build write queue for session- Returns:
-
setSessionIdleTimeout
public void setSessionIdleTimeout(long sessionIdleTimeout)
- Specified by:
setSessionIdleTimeoutin interfaceController
-
getSessionTimeout
public long getSessionTimeout()
- Specified by:
getSessionTimeoutin interfaceController
-
setSessionTimeout
public void setSessionTimeout(long sessionTimeout)
- Specified by:
setSessionTimeoutin interfaceController
-
getSoTimeout
public int getSoTimeout()
- Specified by:
getSoTimeoutin interfaceController
-
setSoTimeout
public void setSoTimeout(int timeout)
- Specified by:
setSoTimeoutin interfaceController
-
getReceiveThroughputLimit
public double getReceiveThroughputLimit()
- Specified by:
getReceiveThroughputLimitin interfaceController
-
getSendThroughputLimit
public double getSendThroughputLimit()
- Specified by:
getSendThroughputLimitin interfaceController
-
setReceiveThroughputLimit
public void setReceiveThroughputLimit(double receiveThroughputLimit)
- Specified by:
setReceiveThroughputLimitin interfaceController
-
setSendThroughputLimit
public void setSendThroughputLimit(double sendThroughputLimit)
- Specified by:
setSendThroughputLimitin interfaceController
-
init
private void init(Configuration configuration, Handler handler, CodecFactory codecFactory)
-
setStarted
void setStarted(boolean started)
-
setStatisticsConfig
private void setStatisticsConfig(Configuration configuration)
-
getConfiguration
public Configuration getConfiguration()
-
setConfiguration
public void setConfiguration(Configuration configuration)
-
getLocalSocketAddress
public java.net.InetSocketAddress getLocalSocketAddress()
- Specified by:
getLocalSocketAddressin interfaceController
-
setLocalSocketAddress
public void setLocalSocketAddress(java.net.InetSocketAddress inetSocketAddress)
- Specified by:
setLocalSocketAddressin interfaceController
-
onAccept
public void onAccept(java.nio.channels.SelectionKey sk) throws java.io.IOException- Throws:
java.io.IOException
-
onConnect
public void onConnect(java.nio.channels.SelectionKey key) throws java.io.IOException- Throws:
java.io.IOException
-
addStateListener
public void addStateListener(ControllerStateListener listener)
- Specified by:
addStateListenerin interfaceController
-
removeStateListener
public void removeStateListener(ControllerStateListener listener)
- Specified by:
removeStateListenerin interfaceController
-
isHandleReadWriteConcurrently
public boolean isHandleReadWriteConcurrently()
- Specified by:
isHandleReadWriteConcurrentlyin interfaceController
-
setHandleReadWriteConcurrently
public void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
- Specified by:
setHandleReadWriteConcurrentlyin interfaceController
-
getReadThreadCount
public int getReadThreadCount()
- Specified by:
getReadThreadCountin interfaceController
-
setReadThreadCount
public void setReadThreadCount(int readThreadCount)
- Specified by:
setReadThreadCountin interfaceController
-
getWriteThreadCount
public final int getWriteThreadCount()
- Specified by:
getWriteThreadCountin interfaceController
-
setWriteThreadCount
public final void setWriteThreadCount(int writeThreadCount)
- Specified by:
setWriteThreadCountin interfaceController
-
getHandler
public Handler getHandler()
- Specified by:
getHandlerin interfaceController
-
setHandler
public void setHandler(Handler handler)
- Specified by:
setHandlerin interfaceController
-
getPort
public int getPort()
- Specified by:
getPortin interfaceController
-
start
public void start() throws java.io.IOException- Specified by:
startin interfaceController- Throws:
java.io.IOException
-
start0
protected abstract void start0() throws java.io.IOException- Throws:
java.io.IOException
-
setDispatchMessageDispatcher
void setDispatchMessageDispatcher(Dispatcher dispatcher)
-
getReadEventDispatcher
Dispatcher getReadEventDispatcher()
-
setReadEventDispatcher
void setReadEventDispatcher(Dispatcher dispatcher)
-
setWriteEventDispatcher
void setWriteEventDispatcher(Dispatcher dispatcher)
-
startStatistics
private final void startStatistics()
-
notifyStarted
public void notifyStarted()
- Specified by:
notifyStartedin interfaceControllerLifeCycle
-
isStarted
public boolean isStarted()
- Specified by:
isStartedin interfaceController
-
getStatistics
public final Statistics getStatistics()
- Specified by:
getStatisticsin interfaceController
-
getCodecFactory
public final CodecFactory getCodecFactory()
- Specified by:
getCodecFactoryin interfaceController
-
setCodecFactory
public final void setCodecFactory(CodecFactory codecFactory)
- Specified by:
setCodecFactoryin interfaceController
-
notifyReady
public void notifyReady()
- Specified by:
notifyReadyin interfaceControllerLifeCycle
-
unregisterSession
public final void unregisterSession(Session session)
-
checkStatisticsForRestart
public void checkStatisticsForRestart()
-
registerSession
public final void registerSession(Session session)
-
stop
public void stop() throws java.io.IOException- Specified by:
stopin interfaceController- Throws:
java.io.IOException
-
stop0
protected abstract void stop0() throws java.io.IOException- Throws:
java.io.IOException
-
stopDispatcher
private final void stopDispatcher()
-
stopStatistics
private final void stopStatistics()
-
clearStateListeners
private final void clearStateListeners()
-
notifyException
public final void notifyException(java.lang.Throwable t)
- Specified by:
notifyExceptionin interfaceControllerLifeCycle
-
notifyStopped
public final void notifyStopped()
- Specified by:
notifyStoppedin interfaceControllerLifeCycle
-
notifyAllSessionClosed
public final void notifyAllSessionClosed()
- Specified by:
notifyAllSessionClosedin interfaceControllerLifeCycle
-
getSessionSet
public java.util.Set<Session> getSessionSet()
-
setSocketOption
public <T> void setSocketOption(SocketOption<T> socketOption, T value)
- Specified by:
setSocketOptionin interfaceController
-
getSocketOption
public <T> T getSocketOption(SocketOption<T> socketOption)
-
bind
public void bind(java.net.InetSocketAddress inetSocketAddress) throws java.io.IOExceptionBind localhost address- Parameters:
inetSocketAddress-- Throws:
java.io.IOException
-
-