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 CodecFactory
codecFactory
Codec Factoryprotected Configuration
configuration
protected Dispatcher
dispatchMessageDispatcher
protected int
dispatchMessageThreadCount
protected Handler
handler
Event handlerprotected boolean
handleReadWriteConcurrently
private boolean
isHutdownHookCalled
protected java.net.InetSocketAddress
localSocketAddress
local bind addressprotected static org.slf4j.Logger
log
protected Dispatcher
readEventDispatcher
protected int
readThreadCount
Read event processing thread countprotected java.util.Set<Session>
sessionSet
Connected session setprotected long
sessionTimeout
private java.lang.Thread
shutdownHookThread
protected java.util.Map<SocketOption,java.lang.Object>
socketOptions
Socket optionsprotected int
soTimeout
protected boolean
started
Statusprotected java.util.concurrent.CopyOnWriteArrayList<ControllerStateListener>
stateListeners
controller state listener listprotected Statistics
statistics
protected long
statisticsInterval
protected Dispatcher
writeEventDispatcher
protected int
writeThreadCount
-
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 void
addStateListener(ControllerStateListener listener)
void
bind(java.net.InetSocketAddress inetSocketAddress)
Bind localhost addressprotected java.util.Queue<WriteMessage>
buildQueue()
Build write queue for sessionvoid
checkStatisticsForRestart()
private void
clearStateListeners()
CodecFactory
getCodecFactory()
Configuration
getConfiguration()
int
getDispatchMessageThreadCount()
Handler
getHandler()
java.net.InetSocketAddress
getLocalSocketAddress()
int
getPort()
(package private) Dispatcher
getReadEventDispatcher()
int
getReadThreadCount()
double
getReceiveThroughputLimit()
double
getSendThroughputLimit()
long
getSessionIdleTimeout()
java.util.Set<Session>
getSessionSet()
long
getSessionTimeout()
<T> T
getSocketOption(SocketOption<T> socketOption)
int
getSoTimeout()
Statistics
getStatistics()
int
getWriteThreadCount()
private void
init(Configuration configuration, Handler handler, CodecFactory codecFactory)
boolean
isHandleReadWriteConcurrently()
boolean
isStarted()
void
notifyAllSessionClosed()
void
notifyException(java.lang.Throwable t)
void
notifyReady()
void
notifyStarted()
void
notifyStopped()
void
onAccept(java.nio.channels.SelectionKey sk)
void
onConnect(java.nio.channels.SelectionKey key)
void
registerSession(Session session)
void
removeStateListener(ControllerStateListener listener)
void
setCodecFactory(CodecFactory codecFactory)
void
setConfiguration(Configuration configuration)
(package private) void
setDispatchMessageDispatcher(Dispatcher dispatcher)
void
setDispatchMessageThreadCount(int dispatchMessageThreadPoolSize)
void
setHandler(Handler handler)
void
setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
void
setLocalSocketAddress(java.net.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(java.util.Map<SocketOption,java.lang.Object> socketOptions)
void
setSoTimeout(int timeout)
(package private) void
setStarted(boolean started)
private void
setStatisticsConfig(Configuration configuration)
(package private) void
setWriteEventDispatcher(Dispatcher dispatcher)
void
setWriteThreadCount(int writeThreadCount)
void
start()
protected abstract void
start0()
private void
startStatistics()
void
stop()
protected abstract void
stop0()
private void
stopDispatcher()
private void
stopStatistics()
void
unregisterSession(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:
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
protected java.util.Queue<WriteMessage> 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
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:
getLocalSocketAddress
in interfaceController
-
setLocalSocketAddress
public void setLocalSocketAddress(java.net.InetSocketAddress inetSocketAddress)
- Specified by:
setLocalSocketAddress
in 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:
addStateListener
in interfaceController
-
removeStateListener
public void removeStateListener(ControllerStateListener listener)
- 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
public Handler getHandler()
- Specified by:
getHandler
in interfaceController
-
setHandler
public void setHandler(Handler handler)
- Specified by:
setHandler
in interfaceController
-
getPort
public int getPort()
- Specified by:
getPort
in interfaceController
-
start
public void start() throws java.io.IOException
- Specified by:
start
in 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:
notifyStarted
in interfaceControllerLifeCycle
-
isStarted
public boolean isStarted()
- Specified by:
isStarted
in interfaceController
-
getStatistics
public final Statistics getStatistics()
- Specified by:
getStatistics
in interfaceController
-
getCodecFactory
public final CodecFactory getCodecFactory()
- Specified by:
getCodecFactory
in interfaceController
-
setCodecFactory
public final void setCodecFactory(CodecFactory codecFactory)
- Specified by:
setCodecFactory
in interfaceController
-
notifyReady
public void notifyReady()
- Specified by:
notifyReady
in 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:
stop
in 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:
notifyException
in interfaceControllerLifeCycle
-
notifyStopped
public final void notifyStopped()
- Specified by:
notifyStopped
in interfaceControllerLifeCycle
-
notifyAllSessionClosed
public final void notifyAllSessionClosed()
- Specified by:
notifyAllSessionClosed
in interfaceControllerLifeCycle
-
getSessionSet
public java.util.Set<Session> getSessionSet()
-
setSocketOption
public <T> void setSocketOption(SocketOption<T> socketOption, T value)
- Specified by:
setSocketOption
in interfaceController
-
getSocketOption
public <T> T getSocketOption(SocketOption<T> socketOption)
-
bind
public void bind(java.net.InetSocketAddress inetSocketAddress) throws java.io.IOException
Bind localhost address- Parameters:
inetSocketAddress
-- Throws:
java.io.IOException
-
-