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 CodecFactory
Codec Factoryprotected Configuration
protected Dispatcher
protected int
protected Handler
Event handlerprotected boolean
private boolean
protected InetSocketAddress
local bind addressprotected static final org.slf4j.Logger
protected Dispatcher
protected int
Read event processing thread countConnected session setprotected long
private Thread
protected Map
<SocketOption, Object> Socket optionsprotected int
protected boolean
Statusprotected CopyOnWriteArrayList
<ControllerStateListener> controller state listener listprotected Statistics
protected long
protected Dispatcher
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractController
(Configuration configuration) AbstractController
(Configuration configuration, CodecFactory codecFactory) AbstractController
(Configuration configuration, Handler handler, CodecFactory codecFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStateListener
(ControllerStateListener listener) void
bind
(InetSocketAddress inetSocketAddress) Bind localhost addressprotected Queue
<WriteMessage> Build write queue for sessionvoid
private final void
final CodecFactory
final int
int
getPort()
(package private) Dispatcher
int
double
double
long
long
<T> T
getSocketOption
(SocketOption<T> socketOption) int
final Statistics
final int
private void
init
(Configuration configuration, Handler handler, CodecFactory codecFactory) boolean
boolean
final void
final void
void
void
final void
void
onAccept
(SelectionKey sk) void
onConnect
(SelectionKey key) final void
registerSession
(Session session) void
removeStateListener
(ControllerStateListener listener) final void
setCodecFactory
(CodecFactory codecFactory) void
setConfiguration
(Configuration configuration) (package private) void
setDispatchMessageDispatcher
(Dispatcher dispatcher) final void
setDispatchMessageThreadCount
(int dispatchMessageThreadPoolSize) void
setHandler
(Handler handler) void
setHandleReadWriteConcurrently
(boolean handleReadWriteConcurrently) void
setLocalSocketAddress
(InetSocketAddress inetSocketAddress) (package private) void
setReadEventDispatcher
(Dispatcher dispatcher) void
setReadThreadCount
(int readThreadCount) void
setReceiveThroughputLimit
(double receiveThroughputLimit) void
setSendThroughputLimit
(double sendThroughputLimit) void
setSessionIdleTimeout
(long sessionIdleTimeout) void
setSessionTimeout
(long sessionTimeout) <T> void
setSocketOption
(SocketOption<T> socketOption, T value) void
setSocketOptions
(Map<SocketOption, Object> socketOptions) void
setSoTimeout
(int timeout) (package private) void
setStarted
(boolean started) private void
setStatisticsConfig
(Configuration configuration) (package private) void
setWriteEventDispatcher
(Dispatcher dispatcher) final void
setWriteThreadCount
(int writeThreadCount) void
start()
protected abstract void
start0()
private final void
void
stop()
protected abstract void
stop0()
private final void
private final void
final void
unregisterSession
(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:
getDispatchMessageThreadCount
in interfaceController
-
setDispatchMessageThreadCount
public final void setDispatchMessageThreadCount(int dispatchMessageThreadPoolSize) - Specified by:
setDispatchMessageThreadCount
in interfaceController
-
getSessionIdleTimeout
public long getSessionIdleTimeout()- Specified by:
getSessionIdleTimeout
in interfaceController
-
buildQueue
Build write queue for session- Returns:
-
setSessionIdleTimeout
public void setSessionIdleTimeout(long sessionIdleTimeout) - Specified by:
setSessionIdleTimeout
in interfaceController
-
getSessionTimeout
public long getSessionTimeout()- Specified by:
getSessionTimeout
in interfaceController
-
setSessionTimeout
public void setSessionTimeout(long sessionTimeout) - Specified by:
setSessionTimeout
in interfaceController
-
getSoTimeout
public int getSoTimeout()- Specified by:
getSoTimeout
in interfaceController
-
setSoTimeout
public void setSoTimeout(int timeout) - Specified by:
setSoTimeout
in interfaceController
-
getReceiveThroughputLimit
public double getReceiveThroughputLimit()- Specified by:
getReceiveThroughputLimit
in interfaceController
-
getSendThroughputLimit
public double getSendThroughputLimit()- Specified by:
getSendThroughputLimit
in interfaceController
-
setReceiveThroughputLimit
public void setReceiveThroughputLimit(double receiveThroughputLimit) - Specified by:
setReceiveThroughputLimit
in interfaceController
-
setSendThroughputLimit
public void setSendThroughputLimit(double sendThroughputLimit) - Specified by:
setSendThroughputLimit
in interfaceController
-
init
-
setStarted
void setStarted(boolean started) -
setStatisticsConfig
-
getConfiguration
-
setConfiguration
-
getLocalSocketAddress
- Specified by:
getLocalSocketAddress
in interfaceController
-
setLocalSocketAddress
- Specified by:
setLocalSocketAddress
in interfaceController
-
onAccept
- Throws:
IOException
-
onConnect
- Throws:
IOException
-
addStateListener
- Specified by:
addStateListener
in interfaceController
-
removeStateListener
- Specified by:
removeStateListener
in interfaceController
-
isHandleReadWriteConcurrently
public boolean isHandleReadWriteConcurrently()- Specified by:
isHandleReadWriteConcurrently
in interfaceController
-
setHandleReadWriteConcurrently
public void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently) - Specified by:
setHandleReadWriteConcurrently
in interfaceController
-
getReadThreadCount
public int getReadThreadCount()- Specified by:
getReadThreadCount
in interfaceController
-
setReadThreadCount
public void setReadThreadCount(int readThreadCount) - Specified by:
setReadThreadCount
in interfaceController
-
getWriteThreadCount
public final int getWriteThreadCount()- Specified by:
getWriteThreadCount
in interfaceController
-
setWriteThreadCount
public final void setWriteThreadCount(int writeThreadCount) - Specified by:
setWriteThreadCount
in interfaceController
-
getHandler
- Specified by:
getHandler
in interfaceController
-
setHandler
- Specified by:
setHandler
in interfaceController
-
getPort
public int getPort()- Specified by:
getPort
in interfaceController
-
start
- Specified by:
start
in interfaceController
- Throws:
IOException
-
start0
- Throws:
IOException
-
setDispatchMessageDispatcher
-
getReadEventDispatcher
Dispatcher getReadEventDispatcher() -
setReadEventDispatcher
-
setWriteEventDispatcher
-
startStatistics
private final void startStatistics() -
notifyStarted
public void notifyStarted()- Specified by:
notifyStarted
in interfaceControllerLifeCycle
-
isStarted
public boolean isStarted()- Specified by:
isStarted
in interfaceController
-
getStatistics
- Specified by:
getStatistics
in interfaceController
-
getCodecFactory
- Specified by:
getCodecFactory
in interfaceController
-
setCodecFactory
- Specified by:
setCodecFactory
in interfaceController
-
notifyReady
public void notifyReady()- Specified by:
notifyReady
in interfaceControllerLifeCycle
-
unregisterSession
-
checkStatisticsForRestart
public void checkStatisticsForRestart() -
registerSession
-
stop
- Specified by:
stop
in interfaceController
- Throws:
IOException
-
stop0
- Throws:
IOException
-
stopDispatcher
private final void stopDispatcher() -
stopStatistics
private final void stopStatistics() -
clearStateListeners
private final void clearStateListeners() -
notifyException
- Specified by:
notifyException
in interfaceControllerLifeCycle
-
notifyStopped
public final void notifyStopped()- Specified by:
notifyStopped
in interfaceControllerLifeCycle
-
notifyAllSessionClosed
public final void notifyAllSessionClosed()- Specified by:
notifyAllSessionClosed
in interfaceControllerLifeCycle
-
getSessionSet
-
setSocketOption
- Specified by:
setSocketOption
in interfaceController
-
getSocketOption
-
bind
Bind localhost address- Parameters:
inetSocketAddress
-- Throws:
IOException
-