com.mooapi.server
Class MooIoHandler

java.lang.Object
  extended by com.mooapi.server.MooIoHandler
All Implemented Interfaces:
org.apache.mina.common.IoHandler

public class MooIoHandler
extends java.lang.Object
implements org.apache.mina.common.IoHandler

Apache MINA IoHandler implementation for the MooAPI server.

Author:
Steve Taylor

Constructor Summary
MooIoHandler()
          Delegate initialization to the relevant property setters.
MooIoHandler(MooServer mooServer, java.lang.String motd, int inputBufferSize, int idleTime)
          Initialize this handler.
 
Method Summary
 void exceptionCaught(org.apache.mina.common.IoSession session, java.lang.Throwable cause)
          Log an exception thrown by a MooAPI connection and close the connection.
 int getIdleTime()
          Get the time, in milliseconds, to wait before polling for incoming connections.
 int getInputBufferSize()
          Get the input buffer size in bytes.
 MooServer getMooServer()
          Get the MooAPI server instance.
 void messageReceived(org.apache.mina.common.IoSession session, java.lang.Object message)
          Convert the incoming byte stream into a MooAPI command and process it.
 void messageSent(org.apache.mina.common.IoSession session, java.lang.Object message)
          This is called by MINA to handle outgoing data.
 void sessionClosed(org.apache.mina.common.IoSession session)
          Remove the MooAPI connection associated with the MINA connection.
 void sessionCreated(org.apache.mina.common.IoSession session)
          Initialize the incoming connection.
 void sessionIdle(org.apache.mina.common.IoSession session, org.apache.mina.common.IdleStatus status)
          Called by MINA.
 void sessionOpened(org.apache.mina.common.IoSession session)
          Create a MooAPI connection from the inbound MINA connection.
 void setIdleTime(int idleTime)
          Set the time, in milliseconds, to wait before polling for incoming connections.
 void setInputBufferSize(int receiveBufferSize)
          Set the input buffer size in bytes.
 void setMooServer(MooServer mooServer)
          Set the MooAPI server instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MooIoHandler

public MooIoHandler(MooServer mooServer,
                    java.lang.String motd,
                    int inputBufferSize,
                    int idleTime)
Initialize this handler.

Parameters:
mooServer - A MooAPI server instance.
motd - The message of the day.
receiveBufferSize - The input buffer size in bytes.
idleTime - The time, in milliseconds, to wait before polling for incoming connections.

MooIoHandler

public MooIoHandler()
Delegate initialization to the relevant property setters.

Method Detail

getMooServer

public MooServer getMooServer()
Get the MooAPI server instance.

Returns:
The MooAPI server.

setMooServer

public void setMooServer(MooServer mooServer)
Set the MooAPI server instance. This is an initialization method.

Parameters:
mooServer - A MooAPI server instance.

getInputBufferSize

public int getInputBufferSize()
Get the input buffer size in bytes.

Returns:
The input buffer size in bytes.

setInputBufferSize

public void setInputBufferSize(int receiveBufferSize)
Set the input buffer size in bytes. This is an initialization method.

Parameters:
receiveBufferSize - The input buffer size in bytes.

getIdleTime

public int getIdleTime()
Get the time, in milliseconds, to wait before polling for incoming connections.

Returns:
The idle time in milliseconds.

setIdleTime

public void setIdleTime(int idleTime)
Set the time, in milliseconds, to wait before polling for incoming connections.

Parameters:
idleTime - The idle time in milliseconds.

sessionCreated

public void sessionCreated(org.apache.mina.common.IoSession session)
                    throws java.lang.Exception
Initialize the incoming connection. This is called by MINA when an incoming connection is established.

Specified by:
sessionCreated in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
Throws:
java.lang.Exception

sessionOpened

public void sessionOpened(org.apache.mina.common.IoSession session)
                   throws java.lang.Exception
Create a MooAPI connection from the inbound MINA connection.

Specified by:
sessionOpened in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
Throws:
java.lang.Exception

sessionClosed

public void sessionClosed(org.apache.mina.common.IoSession session)
                   throws java.lang.Exception
Remove the MooAPI connection associated with the MINA connection.

Specified by:
sessionClosed in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
Throws:
java.lang.Exception

sessionIdle

public void sessionIdle(org.apache.mina.common.IoSession session,
                        org.apache.mina.common.IdleStatus status)
                 throws java.lang.Exception
Called by MINA. Does nothing.

Specified by:
sessionIdle in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
status -
Throws:
java.lang.Exception

exceptionCaught

public void exceptionCaught(org.apache.mina.common.IoSession session,
                            java.lang.Throwable cause)
                     throws java.lang.Exception
Log an exception thrown by a MooAPI connection and close the connection. This is called by MINA to handle exceptions thrown as a result of handling connections.

Specified by:
exceptionCaught in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
cause - The exception that was thrown.
Throws:
java.lang.Exception

messageReceived

public void messageReceived(org.apache.mina.common.IoSession session,
                            java.lang.Object message)
                     throws java.lang.Exception
Convert the incoming byte stream into a MooAPI command and process it. This is called by MINA to handle incoming data.

Specified by:
messageReceived in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
message - The incoming message.
Throws:
java.lang.Exception

messageSent

public void messageSent(org.apache.mina.common.IoSession session,
                        java.lang.Object message)
                 throws java.lang.Exception
This is called by MINA to handle outgoing data. It fires an output event in the server handler.

Specified by:
messageSent in interface org.apache.mina.common.IoHandler
Parameters:
session - A MINA connection.
message - An outgoing message.
Throws:
java.lang.Exception


Copyright © 2009. All Rights Reserved.