games.strategy.net.nio
Class NIOSocket

java.lang.Object
  extended by games.strategy.net.nio.NIOSocket
All Implemented Interfaces:
IErrorReporter

public class NIOSocket
extends java.lang.Object
implements IErrorReporter

The threads needed for a group of sockets using NIO. One thread reds socket data, one thread writes socket data and one thread deserializes (decodes) packets read by the read thread. serializing (encoding) objects to be written across the network is done by threads calling this object.

Author:
sgb

Constructor Summary
NIOSocket(IObjectStreamFactory factory, NIOSocketListener listener, java.lang.String name)
           
 
Method Summary
 void add(java.nio.channels.SocketChannel channel, QuarantineConversation conversation)
          Add this channel.
 void close(java.nio.channels.SocketChannel channel)
          Close the channel, and clean up any data associated with it
 void error(java.nio.channels.SocketChannel channel, java.lang.Exception e)
          An io error occured while reading or writing to the socket, and it should be removed from the network
 void send(java.nio.channels.SocketChannel to, MessageHeader header)
           
 void shutDown()
          Stop our threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NIOSocket

public NIOSocket(IObjectStreamFactory factory,
                 NIOSocketListener listener,
                 java.lang.String name)
Method Detail

shutDown

public void shutDown()
Stop our threads. This does not close the sockets we are connected to.


send

public void send(java.nio.channels.SocketChannel to,
                 MessageHeader header)

add

public void add(java.nio.channels.SocketChannel channel,
                QuarantineConversation conversation)
Add this channel. The channel will either be unquarantined, or an error will be reported


error

public void error(java.nio.channels.SocketChannel channel,
                  java.lang.Exception e)
Description copied from interface: IErrorReporter
An io error occured while reading or writing to the socket, and it should be removed from the network

Specified by:
error in interface IErrorReporter

close

public void close(java.nio.channels.SocketChannel channel)
Close the channel, and clean up any data associated with it