com.aelitis.azureus.core.networkmanager.impl.tcp
Class LightweightTCPTransport

java.lang.Object
  extended by com.aelitis.azureus.core.networkmanager.impl.tcp.LightweightTCPTransport
All Implemented Interfaces:
Transport, TransportBase

public class LightweightTCPTransport
extends java.lang.Object
implements Transport

This class is essentially a socket channel wrapper to support working with az message encoders/decoders.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.aelitis.azureus.core.networkmanager.Transport
Transport.ConnectListener
 
Field Summary
 
Fields inherited from interface com.aelitis.azureus.core.networkmanager.Transport
TRANSPORT_MODE_FAST, TRANSPORT_MODE_NORMAL, TRANSPORT_MODE_TURBO
 
Constructor Summary
LightweightTCPTransport(ProtocolEndpoint pe, TransportHelperFilter filter)
           
 
Method Summary
 void bindConnection(NetworkConnection connection)
           
 void close(java.lang.String reason)
          Close the transport connection.
 void connectedInbound()
          Indicate that inbound connection is complete
 void connectOutbound(java.nio.ByteBuffer initial_data, Transport.ConnectListener listener, int priority)
          Kick off an outbound connection
 java.lang.String getDescription()
          Get a textual description for this transport.
 java.lang.String getEncryption(boolean verbose)
          Return a textual description of the encryption for this transport
 int getMssSize()
           
 java.lang.String getProtocol()
           
 java.net.InetSocketAddress getRemoteAddress()
           
 java.nio.channels.SocketChannel getSocketChannel()
           
 TransportEndpoint getTransportEndpoint()
          Get the socket channel used by the transport.
 int getTransportMode()
          Get the transport's speed mode.
 TransportStartpoint getTransportStartpoint()
           
 boolean isEncrypted()
           
 long isReadyForRead(EventWaiter waiter)
          Is the transport ready to read, i.e.
 boolean isReadyForWrite(EventWaiter waiter)
          Is the transport ready to write, i.e.
 boolean isSOCKS()
           
 boolean isTCP()
           
 long read(java.nio.ByteBuffer[] buffers, int array_offset, int length)
          Read data from the transport into the given buffers.
 void setAlreadyRead(java.nio.ByteBuffer bytes_already_read)
          Inject the given already-read data back into the read stream.
 void setReadyForRead()
          fake a wakeup so that a read cycle is attempted
 void setTrace(boolean on)
           
 void setTransportMode(int mode)
          Set the transport to the given speed mode.
 void unbindConnection(NetworkConnection connection)
           
 long write(java.nio.ByteBuffer[] buffers, int array_offset, int length)
          Write data to the transport from the given buffers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LightweightTCPTransport

public LightweightTCPTransport(ProtocolEndpoint pe,
                               TransportHelperFilter filter)
Method Detail

getTransportEndpoint

public TransportEndpoint getTransportEndpoint()
Description copied from interface: Transport
Get the socket channel used by the transport.

Specified by:
getTransportEndpoint in interface Transport
Returns:
the socket channel

getTransportStartpoint

public TransportStartpoint getTransportStartpoint()
Specified by:
getTransportStartpoint in interface Transport

write

public long write(java.nio.ByteBuffer[] buffers,
                  int array_offset,
                  int length)
           throws java.io.IOException
Description copied from interface: Transport
Write data to the transport from the given buffers. NOTE: Works like GatheringByteChannel.

Specified by:
write in interface Transport
Parameters:
buffers - from which bytes are to be retrieved
array_offset - offset within the buffer array of the first buffer from which bytes are to be retrieved
length - maximum number of buffers to be accessed
Returns:
number of bytes written
Throws:
java.io.IOException - on write error

read

public long read(java.nio.ByteBuffer[] buffers,
                 int array_offset,
                 int length)
          throws java.io.IOException
Description copied from interface: Transport
Read data from the transport into the given buffers. NOTE: Works like ScatteringByteChannel.

Specified by:
read in interface Transport
Parameters:
buffers - into which bytes are to be placed
array_offset - offset within the buffer array of the first buffer into which bytes are to be placed
length - maximum number of buffers to be accessed
Returns:
number of bytes read
Throws:
java.io.IOException - on read error

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()

getRemoteAddress

public java.net.InetSocketAddress getRemoteAddress()

getDescription

public java.lang.String getDescription()
Description copied from interface: TransportBase
Get a textual description for this transport.

Specified by:
getDescription in interface TransportBase
Returns:
description

close

public void close(java.lang.String reason)
Description copied from interface: Transport
Close the transport connection.

Specified by:
close in interface Transport

getMssSize

public int getMssSize()
Specified by:
getMssSize in interface Transport

setAlreadyRead

public void setAlreadyRead(java.nio.ByteBuffer bytes_already_read)
Description copied from interface: Transport
Inject the given already-read data back into the read stream.

Specified by:
setAlreadyRead in interface Transport
Parameters:
bytes_already_read - data

isReadyForWrite

public boolean isReadyForWrite(EventWaiter waiter)
Description copied from interface: TransportBase
Is the transport ready to write, i.e. will a write request result in >0 bytes written.

Specified by:
isReadyForWrite in interface TransportBase
Returns:
true if the transport is write ready, false if not yet ready

isReadyForRead

public long isReadyForRead(EventWaiter waiter)
Description copied from interface: TransportBase
Is the transport ready to read, i.e. will a read request result in >0 bytes read.

Specified by:
isReadyForRead in interface TransportBase
Returns:
0 if the transport is read ready, ms since last ready or created if never ready

setReadyForRead

public void setReadyForRead()
Description copied from interface: Transport
fake a wakeup so that a read cycle is attempted

Specified by:
setReadyForRead in interface Transport

connectOutbound

public void connectOutbound(java.nio.ByteBuffer initial_data,
                            Transport.ConnectListener listener,
                            int priority)
Description copied from interface: Transport
Kick off an outbound connection

Specified by:
connectOutbound in interface Transport

connectedInbound

public void connectedInbound()
Description copied from interface: Transport
Indicate that inbound connection is complete

Specified by:
connectedInbound in interface Transport

setTransportMode

public void setTransportMode(int mode)
Description copied from interface: Transport
Set the transport to the given speed mode.

Specified by:
setTransportMode in interface Transport
Parameters:
mode - to change to

getTransportMode

public int getTransportMode()
Description copied from interface: Transport
Get the transport's speed mode.

Specified by:
getTransportMode in interface Transport
Returns:
current mode

setTrace

public void setTrace(boolean on)
Specified by:
setTrace in interface Transport

getEncryption

public java.lang.String getEncryption(boolean verbose)
Description copied from interface: Transport
Return a textual description of the encryption for this transport

Specified by:
getEncryption in interface Transport
Returns:

isEncrypted

public boolean isEncrypted()
Specified by:
isEncrypted in interface Transport

isTCP

public boolean isTCP()
Specified by:
isTCP in interface TransportBase

isSOCKS

public boolean isSOCKS()
Specified by:
isSOCKS in interface Transport

getProtocol

public java.lang.String getProtocol()
Specified by:
getProtocol in interface Transport

bindConnection

public void bindConnection(NetworkConnection connection)
Specified by:
bindConnection in interface Transport

unbindConnection

public void unbindConnection(NetworkConnection connection)
Specified by:
unbindConnection in interface Transport