p2ps.imp.endpoint.TCP
Class TCPInputEndpoint

java.lang.Object
  extended byp2ps.imp.endpoint.TCP.TCPInputEndpoint
All Implemented Interfaces:
Endpoint, EndpointMessageListener, ServerEndpoint, TCPEndpointSchemes

public class TCPInputEndpoint
extends java.lang.Object
implements ServerEndpoint, EndpointMessageListener, TCPEndpointSchemes

A class that acts as a wrapper for multiple TCP input socket.

Version:
$Revision: 295 $
Author:
Ian Wang

Nested Class Summary
 class TCPInputEndpoint.TCPServerSocketThread
           
 
Field Summary
 
Fields inherited from interface p2ps.imp.endpoint.TCP.TCPEndpointSchemes
TCP_STANDARD
 
Constructor Summary
TCPInputEndpoint(java.lang.String scheme, int port, MessageProtocolHandlerFactory factory)
          Creates a standard TCP socket for the specified scheme/port
TCPInputEndpoint(java.lang.String scheme, int port, MessageProtocolHandlerFactory factory, java.util.Map properties)
          Creates a standard TCP socket for the specified scheme/port
TCPInputEndpoint(java.lang.String scheme, MessageProtocolHandlerFactory factory)
          Creates a standard UDP socket for an available port
TCPInputEndpoint(java.lang.String scheme, MessageProtocolHandlerFactory factory, java.util.Map properties)
          Creates a standard UDP socket for an available port
 
Method Summary
 void addEndpointMessageListener(EndpointMessageListener listener)
          Adds a data message listener to the specified pipe
 void addServerEndpointListener(ServerEndpointListener listener)
          Add a listener to be notified when new connections are opened.
 void close()
          Closes the socket
protected  ServerSocket createServerSocket(java.net.SocketAddress addr, java.util.Map properties)
           
 void dataMessageReceived(DataMessageEvent event)
          Called when the endpoint receives a data message
 java.net.URI getEndpointURI()
           
 java.net.URI getSendURI()
           
 void init()
          initializes the endpoint
 boolean isClosed()
           
 boolean isInputEndpoint()
           
 boolean isOutputEndpoint()
           
 void notifyNewConnectionn(Endpoint replyendpoint)
          handle the specified Data Message received on the specified endpoint
 void removeEndpointMessageListener(EndpointMessageListener listener)
          Removes the specified data message listener from the pipe
 void removeServerEndpointListener(ServerEndpointListener listener)
          Remove a server endpoint listener.
 void send(byte[] message)
          Send a message from the socket
 void send(java.lang.String sendid, byte[] message)
          Sends a message from the endpoint to the address the endpoint is bound to, along with the send id for this message.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TCPInputEndpoint

public TCPInputEndpoint(java.lang.String scheme,
                        MessageProtocolHandlerFactory factory)
                 throws java.io.IOException
Creates a standard UDP socket for an available port


TCPInputEndpoint

public TCPInputEndpoint(java.lang.String scheme,
                        MessageProtocolHandlerFactory factory,
                        java.util.Map properties)
                 throws java.io.IOException
Creates a standard UDP socket for an available port


TCPInputEndpoint

public TCPInputEndpoint(java.lang.String scheme,
                        int port,
                        MessageProtocolHandlerFactory factory)
                 throws java.io.IOException
Creates a standard TCP socket for the specified scheme/port


TCPInputEndpoint

public TCPInputEndpoint(java.lang.String scheme,
                        int port,
                        MessageProtocolHandlerFactory factory,
                        java.util.Map properties)
                 throws java.io.IOException
Creates a standard TCP socket for the specified scheme/port

Method Detail

createServerSocket

protected ServerSocket createServerSocket(java.net.SocketAddress addr,
                                          java.util.Map properties)
                                   throws java.io.IOException
Returns:
a server socket bound to the specified socket address
Throws:
java.io.IOException

init

public void init()
          throws java.io.IOException
initializes the endpoint

Specified by:
init in interface Endpoint
Throws:
java.io.IOException

addEndpointMessageListener

public void addEndpointMessageListener(EndpointMessageListener listener)
Adds a data message listener to the specified pipe

Specified by:
addEndpointMessageListener in interface Endpoint

removeEndpointMessageListener

public void removeEndpointMessageListener(EndpointMessageListener listener)
Removes the specified data message listener from the pipe

Specified by:
removeEndpointMessageListener in interface Endpoint

addServerEndpointListener

public void addServerEndpointListener(ServerEndpointListener listener)
Add a listener to be notified when new connections are opened.

Specified by:
addServerEndpointListener in interface ServerEndpoint

removeServerEndpointListener

public void removeServerEndpointListener(ServerEndpointListener listener)
Remove a server endpoint listener.

Specified by:
removeServerEndpointListener in interface ServerEndpoint

getEndpointURI

public java.net.URI getEndpointURI()
Specified by:
getEndpointURI in interface Endpoint
Returns:
the transport protocol for this socket

getSendURI

public java.net.URI getSendURI()
Specified by:
getSendURI in interface Endpoint
Returns:
the address being sent to by this endpoint (if known)

isInputEndpoint

public boolean isInputEndpoint()
Specified by:
isInputEndpoint in interface Endpoint
Returns:
true if this endpoint is input enabled

isOutputEndpoint

public boolean isOutputEndpoint()
Specified by:
isOutputEndpoint in interface Endpoint
Returns:
true if this endpoint is output enabled

send

public void send(byte[] message)
          throws java.io.IOException
Send a message from the socket

Specified by:
send in interface Endpoint
Throws:
java.io.IOException

send

public void send(java.lang.String sendid,
                 byte[] message)
          throws java.io.IOException
Sends a message from the endpoint to the address the endpoint is bound to, along with the send id for this message.

Specified by:
send in interface Endpoint
Throws:
java.io.IOException

dataMessageReceived

public void dataMessageReceived(DataMessageEvent event)
Called when the endpoint receives a data message

Specified by:
dataMessageReceived in interface EndpointMessageListener

notifyNewConnectionn

public void notifyNewConnectionn(Endpoint replyendpoint)
handle the specified Data Message received on the specified endpoint


close

public void close()
           throws java.io.IOException
Closes the socket

Specified by:
close in interface Endpoint
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Specified by:
isClosed in interface Endpoint
Returns:
true is the socket is closed

toString

public java.lang.String toString()