net.gleamynode.netty2
Class SessionServer

java.lang.Object
  extended bynet.gleamynode.netty2.SessionServer

public class SessionServer
extends Object

Listens to the TCP/IP port, accepts the incoming connections, and starts the corresponding Sessions. Usage:

 SessionServer server = new SessionServer();
 server.setIoProcessor(ioProcessor);
 server.setEventDispatcher(eventDispatcher);
 server.setMessageRecognizer(myMessageRecognizer);
 server.setBindAddress(new InetSocketAddress(8080));
 server.addSessionListener(mySessionListener);
 server.start();
 

Version:
$Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 $
Author:
Trustin Lee (http://gleamynode.net/)

Constructor Summary
SessionServer()
          Creates a new instance.
 
Method Summary
 void addSessionListener(SessionListener listener)
          Subscribe a SessionListenerto receive incoming events from the new session.
 int getBacklog()
          Returns the backlog value of the server socket.
 SocketAddress getBindAddress()
          Returns the socket address this server listens on.
 SessionConfig getDefaultConfig()
          Returns the default configuration of newly created sessions.
 EventDispatcher getEventDispatcher()
          Returns the EventDispatcherthat will be passed to newly created sessions' constructor.
 ExceptionMonitor getExceptionMonitor()
          Returns the ExceptionMonitor.
 IoProcessor getIoProcessor()
          Returns the IoProcessorthat will be passed to newly created sessions' constructor.
 MessageRecognizer getMessageRecognizer()
          Returns the MessageRecognizerthat will be passed to newly created sessions' constructor.
 String getThreadName()
          Returns the name of the server thread.
 int getThreadPriority()
          Returns the priority of the server thread.
 boolean isStarted()
          Returns true if this server is started.
 void removeSessionListener(SessionListener listener)
          Unsubscribe a SessionListenerto stop receiving incoming events from the new session.
 void setBacklog(int backLog)
          Sets the backlog value of the server socket.
 void setBindAddress(SocketAddress bindAddress)
          Sets the socket address this server listens on.
 void setDefaultConfig(SessionConfig defaultConfig)
          Sets the default configuration of newly created sessions.
 void setEventDispatcher(EventDispatcher eventDispatcher)
          Sets the EventDispatcherthat will be passed to newly created sessions' constructor.
 void setExceptionMonitor(ExceptionMonitor monitor)
          Sets the ExceptionMonitor.
 void setIoProcessor(IoProcessor ioProcessor)
          Sets the IoProcessorthat will be passed to newly created sessions' constructor.
 void setMessageRecognizer(MessageRecognizer messageRecognizer)
          Sets the MessageRecognizerthat will be passed to newly created sessions' constructor.
 void setThreadName(String threadName)
          Sets the name of the server thread.
 void setThreadPriority(int threadPriority)
          Sets the priority of the server thread.
 void start()
          Starts accepting the incoming connections.
 void stop()
          Stops accepting the incoming connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionServer

public SessionServer()
Creates a new instance.

Method Detail

getBindAddress

public SocketAddress getBindAddress()
Returns the socket address this server listens on.


setBindAddress

public void setBindAddress(SocketAddress bindAddress)
Sets the socket address this server listens on.

Throws:
IllegalStateException - if the server is already running.

getBacklog

public int getBacklog()
Returns the backlog value of the server socket.


setBacklog

public void setBacklog(int backLog)
Sets the backlog value of the server socket.

Throws:
IllegalStateException - if the server is already running.

getDefaultConfig

public SessionConfig getDefaultConfig()
Returns the default configuration of newly created sessions.


setDefaultConfig

public void setDefaultConfig(SessionConfig defaultConfig)
Sets the default configuration of newly created sessions.


getEventDispatcher

public EventDispatcher getEventDispatcher()
Returns the EventDispatcherthat will be passed to newly created sessions' constructor.


setEventDispatcher

public void setEventDispatcher(EventDispatcher eventDispatcher)
Sets the EventDispatcherthat will be passed to newly created sessions' constructor.

Throws:
IllegalStateException - if the server is already running.

getIoProcessor

public IoProcessor getIoProcessor()
Returns the IoProcessorthat will be passed to newly created sessions' constructor.


setIoProcessor

public void setIoProcessor(IoProcessor ioProcessor)
Sets the IoProcessorthat will be passed to newly created sessions' constructor.

Throws:
IllegalStateException - if the server is already running.

getMessageRecognizer

public MessageRecognizer getMessageRecognizer()
Returns the MessageRecognizerthat will be passed to newly created sessions' constructor.


setMessageRecognizer

public void setMessageRecognizer(MessageRecognizer messageRecognizer)
Sets the MessageRecognizerthat will be passed to newly created sessions' constructor.


getThreadName

public String getThreadName()
Returns the name of the server thread.


setThreadName

public void setThreadName(String threadName)
Sets the name of the server thread.


getThreadPriority

public int getThreadPriority()
Returns the priority of the server thread.


setThreadPriority

public void setThreadPriority(int threadPriority)
Sets the priority of the server thread.


isStarted

public boolean isStarted()
Returns true if this server is started.


addSessionListener

public void addSessionListener(SessionListener listener)
Subscribe a SessionListenerto receive incoming events from the new session.


removeSessionListener

public void removeSessionListener(SessionListener listener)
Unsubscribe a SessionListenerto stop receiving incoming events from the new session.


getExceptionMonitor

public ExceptionMonitor getExceptionMonitor()
Returns the ExceptionMonitor.


setExceptionMonitor

public void setExceptionMonitor(ExceptionMonitor monitor)
Sets the ExceptionMonitor. Any uncaught exceptions will be forwarded to the specified ExceptionMonitor

Throws:
NullPointerException - if monitor is null.

start

public void start()
           throws IOException
Starts accepting the incoming connections.

Throws:
IOException - if failed to open the server socket
IllegalStateException - if some properties are not specified

stop

public void stop()
Stops accepting the incoming connections.



Copyright © 2004-2007 Trustin Lee. All Rights Reserved.