com.google.code.yanf4j.core.impl
Class AbstractController

java.lang.Object
  extended by 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

Author:
dennis

Field Summary
protected  CodecFactory codecFactory
          Codec Factory
protected  Configuration configuration
           
protected  Dispatcher dispatchMessageDispatcher
           
protected  int dispatchMessageThreadCount
           
protected  Handler handler
          Event handler
protected  boolean handleReadWriteConcurrently
           
protected  java.net.InetSocketAddress localSocketAddress
          local bind address
protected static org.slf4j.Logger log
           
protected  Dispatcher readEventDispatcher
           
protected  int readThreadCount
          Read event processing thread count
protected  java.util.Set<Session> sessionSet
          Connected session set
protected  long sessionTimeout
           
protected  java.util.Map<SocketOption,java.lang.Object> socketOptions
          Socket options
protected  int soTimeout
           
protected  boolean started
          Status
protected  java.util.concurrent.CopyOnWriteArrayList<ControllerStateListener> stateListeners
          controller state listener list
protected  Statistics statistics
           
protected  long statisticsInterval
           
protected  Dispatcher writeEventDispatcher
           
protected  int writeThreadCount
           
 
Constructor Summary
AbstractController()
           
AbstractController(Configuration configuration)
           
AbstractController(Configuration configuration, CodecFactory codecFactory)
           
AbstractController(Configuration configuration, Handler handler, CodecFactory codecFactory)
           
 
Method Summary
 void addStateListener(ControllerStateListener listener)
           
 void bind(java.net.InetSocketAddress inetSocketAddress)
          Bind localhost address
protected  java.util.Queue<WriteMessage> buildQueue()
          Build write queue for session
 void checkStatisticsForRestart()
           
 CodecFactory getCodecFactory()
           
 Configuration getConfiguration()
           
 int getDispatchMessageThreadCount()
           
 Handler getHandler()
           
 java.net.InetSocketAddress getLocalSocketAddress()
           
 int getPort()
           
 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()
           
 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)
           
 void setDispatchMessageThreadCount(int dispatchMessageThreadPoolSize)
           
 void setHandler(Handler handler)
           
 void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
           
 void setLocalSocketAddress(java.net.InetSocketAddress inetSocketAddress)
           
 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)
           
 void setWriteThreadCount(int writeThreadCount)
           
 void start()
           
protected abstract  void start0()
           
 void stop()
           
protected abstract  void stop0()
           
 void unregisterSession(Session session)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 volatile 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 volatile 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

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 interface Controller

setDispatchMessageThreadCount

public final void setDispatchMessageThreadCount(int dispatchMessageThreadPoolSize)
Specified by:
setDispatchMessageThreadCount in interface Controller

getSessionIdleTimeout

public long getSessionIdleTimeout()
Specified by:
getSessionIdleTimeout in interface Controller

buildQueue

protected java.util.Queue<WriteMessage> buildQueue()
Build write queue for session

Returns:

setSessionIdleTimeout

public void setSessionIdleTimeout(long sessionIdleTimeout)
Specified by:
setSessionIdleTimeout in interface Controller

getSessionTimeout

public long getSessionTimeout()
Specified by:
getSessionTimeout in interface Controller

setSessionTimeout

public void setSessionTimeout(long sessionTimeout)
Specified by:
setSessionTimeout in interface Controller

getSoTimeout

public int getSoTimeout()
Specified by:
getSoTimeout in interface Controller

setSoTimeout

public void setSoTimeout(int timeout)
Specified by:
setSoTimeout in interface Controller

getReceiveThroughputLimit

public double getReceiveThroughputLimit()
Specified by:
getReceiveThroughputLimit in interface Controller

getSendThroughputLimit

public double getSendThroughputLimit()
Specified by:
getSendThroughputLimit in interface Controller

setReceiveThroughputLimit

public void setReceiveThroughputLimit(double receiveThroughputLimit)
Specified by:
setReceiveThroughputLimit in interface Controller

setSendThroughputLimit

public void setSendThroughputLimit(double sendThroughputLimit)
Specified by:
setSendThroughputLimit in interface Controller

getConfiguration

public Configuration getConfiguration()

setConfiguration

public void setConfiguration(Configuration configuration)

getLocalSocketAddress

public java.net.InetSocketAddress getLocalSocketAddress()
Specified by:
getLocalSocketAddress in interface Controller

setLocalSocketAddress

public void setLocalSocketAddress(java.net.InetSocketAddress inetSocketAddress)
Specified by:
setLocalSocketAddress in interface Controller

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 interface Controller

removeStateListener

public void removeStateListener(ControllerStateListener listener)
Specified by:
removeStateListener in interface Controller

isHandleReadWriteConcurrently

public boolean isHandleReadWriteConcurrently()
Specified by:
isHandleReadWriteConcurrently in interface Controller

setHandleReadWriteConcurrently

public void setHandleReadWriteConcurrently(boolean handleReadWriteConcurrently)
Specified by:
setHandleReadWriteConcurrently in interface Controller

getReadThreadCount

public int getReadThreadCount()
Specified by:
getReadThreadCount in interface Controller

setReadThreadCount

public void setReadThreadCount(int readThreadCount)
Specified by:
setReadThreadCount in interface Controller

getWriteThreadCount

public final int getWriteThreadCount()
Specified by:
getWriteThreadCount in interface Controller

setWriteThreadCount

public final void setWriteThreadCount(int writeThreadCount)
Specified by:
setWriteThreadCount in interface Controller

getHandler

public Handler getHandler()
Specified by:
getHandler in interface Controller

setHandler

public void setHandler(Handler handler)
Specified by:
setHandler in interface Controller

getPort

public int getPort()
Specified by:
getPort in interface Controller

start

public void start()
           throws java.io.IOException
Specified by:
start in interface Controller
Throws:
java.io.IOException

start0

protected abstract void start0()
                        throws java.io.IOException
Throws:
java.io.IOException

notifyStarted

public void notifyStarted()
Specified by:
notifyStarted in interface ControllerLifeCycle

isStarted

public boolean isStarted()
Specified by:
isStarted in interface Controller

getStatistics

public final Statistics getStatistics()
Specified by:
getStatistics in interface Controller

getCodecFactory

public final CodecFactory getCodecFactory()
Specified by:
getCodecFactory in interface Controller

setCodecFactory

public final void setCodecFactory(CodecFactory codecFactory)
Specified by:
setCodecFactory in interface Controller

notifyReady

public void notifyReady()
Specified by:
notifyReady in interface ControllerLifeCycle

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 interface Controller
Throws:
java.io.IOException

stop0

protected abstract void stop0()
                       throws java.io.IOException
Throws:
java.io.IOException

notifyException

public final void notifyException(java.lang.Throwable t)
Specified by:
notifyException in interface ControllerLifeCycle

notifyStopped

public final void notifyStopped()
Specified by:
notifyStopped in interface ControllerLifeCycle

notifyAllSessionClosed

public final void notifyAllSessionClosed()
Specified by:
notifyAllSessionClosed in interface ControllerLifeCycle

getSessionSet

public java.util.Set<Session> getSessionSet()

setSocketOption

public <T> void setSocketOption(SocketOption<T> socketOption,
                                T value)
Specified by:
setSocketOption in interface Controller

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


Copyright © 2011. All Rights Reserved.