org.alliance.core.comm.networklayers.tcpnio
Class TCPNIONetworkLayer

java.lang.Object
  extended by org.alliance.core.comm.networklayers.tcpnio.TCPNIONetworkLayer
All Implemented Interfaces:
java.lang.Runnable

public class TCPNIONetworkLayer
extends java.lang.Object
implements java.lang.Runnable

TCP NIO implementation of network handling. To change to other network handling this class can be reimplemented. If threading is to be added to this model it should not run several threads of this class - a thread pool should be used to handle the packets received from this class. Running several selectors is tricky and should be avoided (and might be a can of worms). User: maciek Date: 2005-dec-26 Time: 12:08:16


Constructor Summary
TCPNIONetworkLayer(NetworkManager netMan)
           
 
Method Summary
 void addInterestForWrite(java.lang.Object key)
           
 void close(java.lang.Object key)
           
 void connect(java.lang.String host, int port, AuthenticatedConnection connection)
           
 Packet createPacketForReceive()
           
 Packet createPacketForSend()
           
 int getNumberOfPendingConnections()
           
 java.net.SocketAddress getSocketAddressFor(Connection connection)
           
 java.net.Socket getSocketFor(Connection connection)
           
 void invokeLater(java.lang.Runnable r)
           
 void removeConnection(java.lang.Object key)
           
 void removeInterestForWrite(java.lang.Object key)
           
 void run()
           
 int send(java.lang.Object key, byte[] buf)
           
 int send(java.lang.Object key, byte[] buf, int offset, int length)
           
 int send(java.lang.Object key, java.nio.ByteBuffer buf)
           
 int send(java.lang.Object key, java.nio.ByteBuffer buf, int bytesToSend)
           
 int send(java.lang.Object key, Packet p)
          Packet must have been prepared for send using "Packet.prepareForSend"!
 void shutdown()
           
 void start()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPNIONetworkLayer

public TCPNIONetworkLayer(NetworkManager netMan)
                   throws java.io.IOException
Throws:
java.io.IOException
Method Detail

start

public void start()

shutdown

public void shutdown()
              throws java.io.IOException
Throws:
java.io.IOException

connect

public void connect(java.lang.String host,
                    int port,
                    AuthenticatedConnection connection)
             throws java.io.IOException
Throws:
java.io.IOException

send

public int send(java.lang.Object key,
                java.nio.ByteBuffer buf,
                int bytesToSend)
         throws java.io.IOException
Throws:
java.io.IOException

send

public int send(java.lang.Object key,
                java.nio.ByteBuffer buf)
         throws java.io.IOException
Throws:
java.io.IOException

send

public int send(java.lang.Object key,
                Packet p)
         throws java.io.IOException
Packet must have been prepared for send using "Packet.prepareForSend"!

Throws:
java.io.IOException

send

public int send(java.lang.Object key,
                byte[] buf)
         throws java.io.IOException
Throws:
java.io.IOException

send

public int send(java.lang.Object key,
                byte[] buf,
                int offset,
                int length)
         throws java.io.IOException
Throws:
java.io.IOException

removeConnection

public void removeConnection(java.lang.Object key)

createPacketForSend

public Packet createPacketForSend()

createPacketForReceive

public Packet createPacketForReceive()

run

public void run()
Specified by:
run in interface java.lang.Runnable

invokeLater

public void invokeLater(java.lang.Runnable r)

addInterestForWrite

public void addInterestForWrite(java.lang.Object key)

removeInterestForWrite

public void removeInterestForWrite(java.lang.Object key)

getSocketAddressFor

public java.net.SocketAddress getSocketAddressFor(Connection connection)

getSocketFor

public java.net.Socket getSocketFor(Connection connection)

close

public void close(java.lang.Object key)

getNumberOfPendingConnections

public int getNumberOfPendingConnections()