org.fossilec.odettej.transport.tcp
Class TCPTransport

java.lang.Object
  extended by org.fossilec.odettej.transport.tcp.TCPTransport
All Implemented Interfaces:
Transport
Direct Known Subclasses:
MoreDataBitTransport

public class TCPTransport
extends java.lang.Object
implements Transport

Provide OdetteJ with a TCP/IP transportation layer based on Odette FTP, implementing the Transport interface.

Used to create new transportion layer or encapsulating a existing opened socket channel to provide its functionalities.

Author:
Rafael Marins
See Also:
Transport

Constructor Summary
TCPTransport()
          Default constructor method.
TCPTransport(java.nio.channels.SocketChannel channel)
          Creates a new class instance providing an existing SocketChannel.
 
Method Summary
 boolean connect(NetworkAddress address)
          Setup a network connection with another Odette FTP entity.
 boolean connect(java.lang.String address)
          Setup a network connection with another Odette FTP entity.
 void disconnect()
          Terminate the ongoing connection.
protected  java.nio.channels.SocketChannel getChannel()
          Gets channel used in streaming with TCP connection.
 java.lang.String getLocalAddress()
          Returns local address used to fulfill Odette FTP session variables.
 java.lang.String getRemoteAddress()
          Returns remote address used to fulfill Odette FTP session variables.
 boolean isConnected()
          Tells whether the underlying transport is connected.
 int receive(java.nio.ByteBuffer dest)
          Receive a sequence of bytes from the TCP socket channel.
 int send(java.nio.ByteBuffer buffer)
          Send a sequence of bytes through this transport implementation, using a TCP/IP socket channel, from the given buffer.
 int send(java.nio.ByteBuffer[] buffers)
          Sent a sequence of bytes through this transport implementation, using a TCP/IP socket channel, from a subsequence of the given buffers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPTransport

public TCPTransport()
Default constructor method. Create a new instance of SocketChannel for its use.

Throws:
OdetteFTPException

TCPTransport

public TCPTransport(java.nio.channels.SocketChannel channel)
             throws OdetteFTPException
Creates a new class instance providing an existing SocketChannel. This channel is opened in connection with another Odette FTP entity. It's useful when using OdetteJ for server mode operations.

Parameters:
channel - opened socket channel.
Throws:
OdetteFTPException
Method Detail

getChannel

protected java.nio.channels.SocketChannel getChannel()
                                              throws OdetteFTPException
Gets channel used in streaming with TCP connection. Create a new SocketChannel if not set.

Returns:
a channel.
Throws:
OdetteFTPException

connect

public boolean connect(NetworkAddress address)
                throws OdetteFTPException
Setup a network connection with another Odette FTP entity.

Specified by:
connect in interface Transport
Parameters:
address - InternetAddress type address providing the network location to connect.
Returns:
true when connection is established with success, otherwise return false.
Throws:
ConnectionException - transport already connected
AddressException - unresolved address or unsupported address type
OdetteFTPException - unexpected error
See Also:
Transport.connect(NetworkAddress)

connect

public boolean connect(java.lang.String address)
                throws OdetteFTPException
Setup a network connection with another Odette FTP entity.

Specified by:
connect in interface Transport
Parameters:
address - A String representation of the TCP/IP network location of the target Odette FTP peer. The value is parsed using InternetAddress object.
Returns:
true when connection is established with success, otherwise return false.
Throws:
ConnectionException - transport already connected
AddressException - unresolved address or unsupported address type
OdetteFTPException - unexpected error
See Also:
Transport.connect(String)

disconnect

public void disconnect()
                throws OdetteFTPException
Terminate the ongoing connection. Once the connection is ended, it's not avaiable for further communication activity.

Specified by:
disconnect in interface Transport
Throws:
OdetteFTPException - unexpected error
See Also:
Transport.disconnect()

send

public int send(java.nio.ByteBuffer buffer)
         throws OdetteFTPException
Send a sequence of bytes through this transport implementation, using a TCP/IP socket channel, from the given buffer.

An attempt is made to send up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Specified by:
send in interface Transport
Parameters:
src - The buffer from which bytes are to be retrieved
Returns:
The number of bytes sent, possibly zero
Throws:
NotConnectedException - Transport not yet connected
OdetteFTPException - unexpected exception
See Also:
Transport.send(ByteBuffer)

send

public int send(java.nio.ByteBuffer[] buffers)
         throws OdetteFTPException
Sent a sequence of bytes through this transport implementation, using a TCP/IP socket channel, from a subsequence of the given buffers.

Specified by:
send in interface Transport
Parameters:
srcs - The sequence of buffers from which bytes are to be retrieved
Returns:
The number of overall bytes sent, possibly zero
Throws:
NotConnectedException - Transport not yet connected
OdetteFTPException - unexpected exception
See Also:
Transport.send(ByteBuffer[])

receive

public int receive(java.nio.ByteBuffer dest)
            throws OdetteFTPException
Receive a sequence of bytes from the TCP socket channel.

An attempt is made to receive up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Specified by:
receive in interface Transport
Parameters:
dst - The buffer into which bytes are to be transferred
Returns:
The number of bytes received, possibly zero, or -1 if the channel has reached end-of-stream
Throws:
NotConnectedException - Transport not yet connected
OdetteFTPException - Thrown by unexpected exception
See Also:
Transport.receive(ByteBuffer)

isConnected

public boolean isConnected()
                    throws OdetteFTPException
Tells whether the underlying transport is connected.

Specified by:
isConnected in interface Transport
Returns:
true if this transport implementation is connected.
Throws:
OdetteFTPException
See Also:
Transport.isConnected()

getLocalAddress

public java.lang.String getLocalAddress()
                                 throws OdetteFTPException
Returns local address used to fulfill Odette FTP session variables. On the Initiator side, it compose the "odette.calling-address " property. The Responder Odette FTP entity use this method to fill the "odette.called-address" property.

Specified by:
getLocalAddress in interface Transport
Returns:
String representing the local address of the underlying network protocol, as expected by session variables.
Throws:
OdetteFTPException
See Also:
Transport.getLocalAddress()

getRemoteAddress

public java.lang.String getRemoteAddress()
                                  throws OdetteFTPException
Returns remote address used to fulfill Odette FTP session variables. On the Initiator side, it's used in the "odette.called-address ". The Responder Odette FTP entity use this method to fill the "odette.calling-address" property.

Specified by:
getRemoteAddress in interface Transport
Returns:
String representing the remote address of the underlying network protocol, as expected by session variables.
Throws:
OdetteFTPException
See Also:
Transport.getRemoteAddress()


Copyright © 2005 ObjectWeb Consortium. All Rights Reserved.