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
Base controller
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CodecFactoryCodec Factoryprotected Configurationprotected Dispatcherprotected intprotected HandlerEvent handlerprotected booleanprivate booleanprotected InetSocketAddresslocal bind addressprotected static final org.slf4j.Loggerprotected Dispatcherprotected intRead event processing thread countConnected session setprotected longprivate Threadprotected Map<SocketOption, Object> Socket optionsprotected intprotected booleanStatusprotected CopyOnWriteArrayList<ControllerStateListener> controller state listener listprotected Statisticsprotected longprotected Dispatcherprotected int -
Constructor Summary
ConstructorsConstructorDescriptionAbstractController(Configuration configuration) AbstractController(Configuration configuration, CodecFactory codecFactory) AbstractController(Configuration configuration, Handler handler, CodecFactory codecFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(ControllerStateListener listener) voidbind(InetSocketAddress inetSocketAddress) Bind localhost addressprotected Queue<WriteMessage> Build write queue for sessionvoidprivate final voidfinal CodecFactoryfinal intintgetPort()(package private) Dispatcherintdoubledoublelonglong<T> TgetSocketOption(SocketOption<T> socketOption) intfinal Statisticsfinal intprivate voidinit(Configuration configuration, Handler handler, CodecFactory codecFactory) booleanbooleanfinal voidfinal voidvoidvoidfinal voidvoidonAccept(SelectionKey sk) voidonConnect(SelectionKey key) final voidregisterSession(Session session) voidremoveStateListener(ControllerStateListener listener) final voidsetCodecFactory(CodecFactory codecFactory) voidsetConfiguration(Configuration configuration) (package private) voidsetDispatchMessageDispatcher(Dispatcher dispatcher) final voidsetDispatchMessageThreadCount(int dispatchMessageThreadPoolSize) voidsetHandler(Handler handler) voidsetHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) voidsetLocalSocketAddress(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(Map<SocketOption, Object> socketOptions) voidsetSoTimeout(int timeout) (package private) voidsetStarted(boolean started) private voidsetStatisticsConfig(Configuration configuration) (package private) voidsetWriteEventDispatcher(Dispatcher dispatcher) final voidsetWriteThreadCount(int writeThreadCount) voidstart()protected abstract voidstart0()private final voidvoidstop()protected abstract voidstop0()private final voidprivate final voidfinal voidunregisterSession(Session session)
-
Field Details
-
statistics
-
statisticsInterval
protected long statisticsInterval -
log
protected static final org.slf4j.Logger log -
stateListeners
controller state listener list -
handler
Event handler -
codecFactory
Codec Factory -
started
protected volatile boolean startedStatus -
localSocketAddress
local bind address -
readThreadCount
protected int readThreadCountRead event processing thread count -
writeThreadCount
protected int writeThreadCount -
dispatchMessageThreadCount
protected int dispatchMessageThreadCount -
configuration
-
readEventDispatcher
-
dispatchMessageDispatcher
-
writeEventDispatcher
-
sessionTimeout
protected long sessionTimeout -
handleReadWriteConcurrently
protected boolean handleReadWriteConcurrently -
soTimeout
protected int soTimeout -
socketOptions
Socket options -
sessionSet
Connected session set -
shutdownHookThread
-
isHutdownHookCalled
private volatile boolean isHutdownHookCalled
-
-
Constructor Details
-
AbstractController
public AbstractController() -
AbstractController
-
AbstractController
-
AbstractController
-
-
Method Details
-
setSocketOptions
-
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
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
-
setStarted
void setStarted(boolean started) -
setStatisticsConfig
-
getConfiguration
-
setConfiguration
-
getLocalSocketAddress
- Specified by:
getLocalSocketAddressin interfaceController
-
setLocalSocketAddress
- Specified by:
setLocalSocketAddressin interfaceController
-
onAccept
- Throws:
IOException
-
onConnect
- Throws:
IOException
-
addStateListener
- Specified by:
addStateListenerin interfaceController
-
removeStateListener
- 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
- Specified by:
getHandlerin interfaceController
-
setHandler
- Specified by:
setHandlerin interfaceController
-
getPort
public int getPort()- Specified by:
getPortin interfaceController
-
start
- Specified by:
startin interfaceController- Throws:
IOException
-
start0
- Throws:
IOException
-
setDispatchMessageDispatcher
-
getReadEventDispatcher
Dispatcher getReadEventDispatcher() -
setReadEventDispatcher
-
setWriteEventDispatcher
-
startStatistics
private final void startStatistics() -
notifyStarted
public void notifyStarted()- Specified by:
notifyStartedin interfaceControllerLifeCycle
-
isStarted
public boolean isStarted()- Specified by:
isStartedin interfaceController
-
getStatistics
- Specified by:
getStatisticsin interfaceController
-
getCodecFactory
- Specified by:
getCodecFactoryin interfaceController
-
setCodecFactory
- Specified by:
setCodecFactoryin interfaceController
-
notifyReady
public void notifyReady()- Specified by:
notifyReadyin interfaceControllerLifeCycle
-
unregisterSession
-
checkStatisticsForRestart
public void checkStatisticsForRestart() -
registerSession
-
stop
- Specified by:
stopin interfaceController- Throws:
IOException
-
stop0
- Throws:
IOException
-
stopDispatcher
private final void stopDispatcher() -
stopStatistics
private final void stopStatistics() -
clearStateListeners
private final void clearStateListeners() -
notifyException
- Specified by:
notifyExceptionin interfaceControllerLifeCycle
-
notifyStopped
public final void notifyStopped()- Specified by:
notifyStoppedin interfaceControllerLifeCycle
-
notifyAllSessionClosed
public final void notifyAllSessionClosed()- Specified by:
notifyAllSessionClosedin interfaceControllerLifeCycle
-
getSessionSet
-
setSocketOption
- Specified by:
setSocketOptionin interfaceController
-
getSocketOption
-
bind
Bind localhost address- Parameters:
inetSocketAddress-- Throws:
IOException
-