com.maverick.nio
Class Daemon

java.lang.Object
  extended by com.maverick.nio.Daemon

public abstract class Daemon
extends Object

This class provides an abstract daemon for servicing any number of protocol contexts.

Author:
Lee David Painter

Constructor Summary
Daemon()
          Constructs the Daemon.
 
Method Summary
protected abstract  void configure(DaemonContext context)
          Called before the server is started so that you can configure the server to your own requirements.
 DaemonContext getContext()
          Get the context for this Daemon.
 EventService getEventService()
          Get the event service this daemon uses.
 boolean isStarted()
          Get whether the daemon is currently started
protected  void onShutdown()
           
protected  void onStart()
           
 void registerAcceptor(ClientAcceptor acceptor, ServerSocketChannel socketChannel)
          Register a client acceptor with the daemon.
 void registerConnector(ClientConnector connector, SocketChannel socketChannel)
          Register a client connector with the daemon.
 void registerHandler(SocketHandler handler, SelectableChannel channel)
          Register a socket handler with the daemon.
 void registerHandler(SocketHandler handler, SelectableChannel channel, SelectorThread thread)
          Register a socket handler with the daemon.
 void removeAcceptor(ListeningInterface li)
           
 void setEventService(EventService eventService)
          Set the event service this daemon uses.
 void shutdown()
          Shutdown the server.
protected  boolean startListeningInterface(ListeningInterface li)
           
 boolean startup()
          Starts the daemon, first calling the #configure(ConfigurationContext) method to allow your server to configure itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Daemon

public Daemon()
Constructs the Daemon.

Method Detail

getContext

public DaemonContext getContext()
Get the context for this Daemon.

Returns:
DaemonContext

getEventService

public EventService getEventService()
Get the event service this daemon uses. By default, this daemon instance will use its own private event service.

Returns:
event service

setEventService

public void setEventService(EventService eventService)
Set the event service this daemon uses. By default, this daemon instance will use its own private event service.

Parameters:
eventService - event service

startup

public boolean startup()
                throws IOException
Starts the daemon, first calling the #configure(ConfigurationContext) method to allow your server to configure itself.

Returns:
true if at least one interface started, otherwise false.
Throws:
IOException

onStart

protected void onStart()
                throws IOException
Throws:
IOException

startListeningInterface

protected boolean startListeningInterface(ListeningInterface li)
                                   throws IOException
Throws:
IOException

removeAcceptor

public void removeAcceptor(ListeningInterface li)

isStarted

public boolean isStarted()
Get whether the daemon is currently started

Returns:
started

shutdown

public void shutdown()
Shutdown the server. This does not exit the JVM


onShutdown

protected void onShutdown()

registerConnector

public void registerConnector(ClientConnector connector,
                              SocketChannel socketChannel)
                       throws IOException
Register a client connector with the daemon.

Parameters:
connector - ClientConnector
socketChannel - SocketChannel
Throws:
IOException

registerAcceptor

public void registerAcceptor(ClientAcceptor acceptor,
                             ServerSocketChannel socketChannel)
                      throws IOException
Register a client acceptor with the daemon.

Parameters:
acceptor - ClientAcceptor
socketChannel - ServerSocketChannel
Throws:
IOException

registerHandler

public void registerHandler(SocketHandler handler,
                            SelectableChannel channel)
                     throws IOException
Register a socket handler with the daemon.

Parameters:
handler - SocketHandler
channel - SelectableChannel
Throws:
IOException

registerHandler

public void registerHandler(SocketHandler handler,
                            SelectableChannel channel,
                            SelectorThread thread)
                     throws IOException
Register a socket handler with the daemon.

Parameters:
handler - SocketHandler
channel - SelectableChannel
thread - SelectorThread
Throws:
IOException

configure

protected abstract void configure(DaemonContext context)
                           throws IOException
Called before the server is started so that you can configure the server to your own requirements.

Parameters:
context -
Throws:
IOException


Copyright © 2012. All Rights Reserved.