info.jedi.net
Class MailDaemon

java.lang.Object
  |
  +--info.jedi.net.MailDaemon

public class MailDaemon
extends java.lang.Object

Class MailDaemon is the center of the JEDI system. It's function is to find the appropriate handler for incoming packets on the port it is associated with. Up to 256 handlers can be registered. Creating a MailDaemon automatically sets up threads to service incoming packets, a ResourceHandler, and handlers for Ping, Reliable, and Remote Method Call packets. The MailDaemon provides methods to get a packet of a certain type from a socket, to handle it once created, and to manage the handlers in the 256 handler slots.

See Also:
PacketHandler, DefaultPacketHandler, PingHandler, RMCHandler, ReceiveThread

Field Summary
static int DEFAULT_PORT
          The default port the MailDaemon is created at is 8273
 
Constructor Summary
MailDaemon()
          Creates a MailDaemon at the default port.
MailDaemon(int port)
          Creates a MailDaemon at a particular port.
 
Method Summary
 void addHandler(PacketHandler handler, int index)
          Adds a handler to the list of packet handlers at the index given.
static MailDaemon getDefault()
          Returns the default MailDaemon--the last one to be created
 PingHandler getPingHandler()
          Returns the PingHandler for this MailDaemon
 ReliableHandler getReliableHandler()
          Returns the ReliableHandler for this MailDaemon
 RMCHandler getRMCHandler()
          Returns the RMCHandler for this MailDaemon
 UDPSender getUDPSender()
          Returns the UDPSender for this MailDaemon
 void handle(InputPacket packet)
          Handles a packet until one of the handlers returns a finished flag.
 PacketHandler handlers(int index)
          Returns the handler at the index given.
 InputPacket receivePacket(java.net.DatagramSocket socket, int TYPE_TO_CATCH)
          Gets a packet from a particular socket and processes it until it comes to a packet-part of type TYPE_TO_CATCH.
 ResourceHandler resourceHandler()
          Returns the ResourceHandler associated with this MailDaemon
 void send(java.net.DatagramPacket packet)
          Sends a packet at the socket associated with this MailDaemon.
 java.net.DatagramSocket socket()
          Returns the socket associated with this MailDaemon
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port the MailDaemon is created at is 8273
Constructor Detail

MailDaemon

public MailDaemon()
           throws java.net.SocketException
Creates a MailDaemon at the default port. Creates a ResourceHandler, a socket listening at that port, and Default handlers for each slot (includes a handler for ping, reliable, and remote message packets)
Throws:
java.net.SocketException - if the default port is in use.

MailDaemon

public MailDaemon(int port)
           throws java.net.SocketException
Creates a MailDaemon at a particular port. Creates a ResourceHandler, a socket listening at that port, and Default handlers for each slot (includes a handler for ping, reliable, and remote message packets)
Parameters:
port - the port this MailDaemon will listen on
Throws:
java.net.SocketException - if this port is in use.
Method Detail

receivePacket

public InputPacket receivePacket(java.net.DatagramSocket socket,
                                 int TYPE_TO_CATCH)
                          throws java.io.IOException
Gets a packet from a particular socket and processes it until it comes to a packet-part of type TYPE_TO_CATCH. It will continue to process packets until it finds one of the correct type.
Throws:
java.io.IOException - if there is an error receiving or processing a packet.

handle

public void handle(InputPacket packet)
            throws java.io.IOException
Handles a packet until one of the handlers returns a finished flag.
Throws:
java.io.IOException - if there is an IO error while handling this packet.

send

public void send(java.net.DatagramPacket packet)
          throws java.io.IOException
Sends a packet at the socket associated with this MailDaemon.
Throws:
java.io.IOException - if there is a socket error.

addHandler

public void addHandler(PacketHandler handler,
                       int index)
Adds a handler to the list of packet handlers at the index given. Index must be between 0 and 255.

handlers

public PacketHandler handlers(int index)
Returns the handler at the index given. Index must be between 0 and 255

getReliableHandler

public ReliableHandler getReliableHandler()
Returns the ReliableHandler for this MailDaemon

getRMCHandler

public RMCHandler getRMCHandler()
Returns the RMCHandler for this MailDaemon

getPingHandler

public PingHandler getPingHandler()
Returns the PingHandler for this MailDaemon

socket

public java.net.DatagramSocket socket()
Returns the socket associated with this MailDaemon

resourceHandler

public ResourceHandler resourceHandler()
Returns the ResourceHandler associated with this MailDaemon

getUDPSender

public UDPSender getUDPSender()
Returns the UDPSender for this MailDaemon

getDefault

public static MailDaemon getDefault()
                             throws java.net.SocketException
Returns the default MailDaemon--the last one to be created