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 Object implements Controller, ControllerLifeCycle
Base controller- Author:
- dennis
-
-
Field Summary
Fields Modifier and Type Field Description protected CodecFactorycodecFactoryCodec Factoryprotected Configurationconfigurationprotected DispatcherdispatchMessageDispatcherprotected intdispatchMessageThreadCountprotected HandlerhandlerEvent handlerprotected booleanhandleReadWriteConcurrentlyprotected InetSocketAddresslocalSocketAddresslocal bind addressprotected static org.slf4j.Loggerlogprotected DispatcherreadEventDispatcherprotected intreadThreadCountRead event processing thread countprotected Set<Session>sessionSetConnected session setprotected longsessionTimeoutprotected Map<SocketOption,Object>socketOptionsSocket optionsprotected intsoTimeoutprotected booleanstartedStatusprotected 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
-
-
-
Field Detail
-
statistics
protected Statistics statistics
-
statisticsInterval
protected long statisticsInterval
-
log
protected static final org.slf4j.Logger log
-
stateListeners
protected 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 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 Map<SocketOption,Object> socketOptions
Socket options
-
-
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(Map<SocketOption,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 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
-
getConfiguration
public Configuration getConfiguration()
-
setConfiguration
public void setConfiguration(Configuration configuration)
-
getLocalSocketAddress
public InetSocketAddress getLocalSocketAddress()
- Specified by:
getLocalSocketAddressin interfaceController
-
setLocalSocketAddress
public void setLocalSocketAddress(InetSocketAddress inetSocketAddress)
- Specified by:
setLocalSocketAddressin interfaceController
-
onAccept
public void onAccept(SelectionKey sk) throws IOException
- Throws:
IOException
-
onConnect
public void onConnect(SelectionKey key) throws IOException
- Throws:
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 IOException- Specified by:
startin interfaceController- Throws:
IOException
-
start0
protected abstract void start0() throws IOException- Throws:
IOException
-
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 IOException- Specified by:
stopin interfaceController- Throws:
IOException
-
stop0
protected abstract void stop0() throws IOException- Throws:
IOException
-
notifyException
public final void notifyException(Throwable t)
- Specified by:
notifyExceptionin interfaceControllerLifeCycle
-
notifyStopped
public final void notifyStopped()
- Specified by:
notifyStoppedin interfaceControllerLifeCycle
-
notifyAllSessionClosed
public final void notifyAllSessionClosed()
- Specified by:
notifyAllSessionClosedin interfaceControllerLifeCycle
-
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(InetSocketAddress inetSocketAddress) throws IOException
Bind localhost address- Parameters:
inetSocketAddress-- Throws:
IOException
-
-