JXTA

net.jxta.socket
Class JxtaServerSocket

java.lang.Object
  extended by java.net.ServerSocket
      extended by net.jxta.socket.JxtaServerSocket
All Implemented Interfaces:
EventListener, PipeMsgListener

public class JxtaServerSocket
extends ServerSocket
implements PipeMsgListener

JxtaServerSocket is a bi-directional Pipe that behaves very much like ServerSocket. It creates an inputpipe and listens for pipe connection requests. JxtaServerSocket also defines it own protocol. Requests arrive as a JXTA Message with the following elements:

<Cred> Credentials which can be used to determine trust </Cred>

<reqPipe> requestor's pipe advertisement </reqPipe>

<remPipe> Remote pipe advertisement </remPipe>

<reqPeer> Remote peer advertisement </reqPeer>

<stream> determine whether the connection is reliable, or not </stream>

<close> close request </close>

<data> Data </data>

JxtaServerSocket then creates a new private pipe, listens for messages on that pipe, resolves the requestor's pipe, and sends a <remPipe> private pipe created </remotePipe> advertisement back, where the remote side is resolved.

The accept() backlog defaults to 50 requests.

The timeout default to 60 seconds, i.e. blocking.


Field Summary
protected  int backlog
          The number of connect requests we will allow to become backlogged.
protected  boolean bound
           
protected static String closeAckValue
           
protected  boolean closed
           
protected static String closeReqValue
           
protected static String closeTag
           
protected static String credTag
           
protected static String dataTag
           
protected  PeerGroup group
          The PeerGroup
protected  Credential localCredential
          The credential we will present to connect requests.
protected static String MSG_ELEMENT_NAMESPACE
           
protected  PipeAdvertisement pipeAdv
          The pipe advertisement we are serving.
protected  BlockingQueue<Message> queue
           
protected static Message QUEUE_END_MESSAGE
          QUEUE_END_MESSAGE is used to signal that the queue has been closed.
protected static String remPeerTag
           
protected static String remPipeTag
           
protected static String reqPipeTag
           
protected  InputPipe serverPipe
          The input pipe on which we listen for connect requests.
protected static String streamTag
           
protected  long timeout
          The timeout for accept operations.
 
Constructor Summary
JxtaServerSocket()
          Default Constructor

A call to bind() is needed to finish initializing this object.

JxtaServerSocket(PeerGroup group, PipeAdvertisement pipeAdv)
          Constructs and binds a JxtaServerSocket to the specified pipe.
JxtaServerSocket(PeerGroup group, PipeAdvertisement pipeAdv, int backlog)
          Constructor for the JxtaServerSocket object
JxtaServerSocket(PeerGroup group, PipeAdvertisement pipeAdv, int backlog, int timeout)
          Constructor for the JxtaServerSocket object.
JxtaServerSocket(PeerGroup group, PipeAdvertisement pipeAdv, int backlog, int timeout, CredentialValidator credValidator)
          Constructor for the JxtaServerSocket object.
JxtaServerSocket(SocketAddress address)
          Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.
JxtaServerSocket(SocketAddress address, int backlog)
          Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.
JxtaServerSocket(SocketAddress address, int backlog, int timeout)
          Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.
 
Method Summary
 Socket accept()
          
 void bind(PeerGroup group, PipeAdvertisement pipeAdv)
          Binds the JxtaServerSocket to a specific pipe advertisement
 void bind(PeerGroup group, PipeAdvertisement pipeadv, int backlog)
          Binds the JxtaServerSocket to a specific pipe advertisement
 void bind(SocketAddress endpoint)
          

Used to bind a JxtaServerSocket created with the no-arg constructor.

 void bind(SocketAddress endpoint, int backlog)
          

Used to bind a JxtaServerSocket created with the no-arg constructor.

 void close()
          
protected  JxtaSocket createEphemeralSocket(PeerGroup group, PipeAdvertisement pipeAdv, PipeAdvertisement remoteEphemeralPipeAdv, PeerAdvertisement remotePeerAdv, Credential localCredential, Credential credential, boolean isReliable)
          Construct the emphemeral socket result from accept.
protected  void finalize()
          

Closes the JxtaServerPipe.

 PeerGroup getGroup()
          Gets the group associated with this JxtaServerSocket object
 SocketAddress getLocalSocketAddress()
           
 PipeAdvertisement getPipeAdv()
          Gets the PipeAdvertisement associated with this JxtaServerSocket object
 int getSoTimeout()
          
 boolean isBound()
          
 boolean isClosed()
          
 void pipeMsgEvent(PipeMsgEvent event)
          Called for each pipe message event that occurs.
 void setCredential(Credential localCredential)
          Sets the credential to be used by this socket connection.
 void setSoTimeout(int timeout)
          
 String toString()
          

This output is suitable for debugging but should not be parsed.

 
Methods inherited from class java.net.ServerSocket
getChannel, getInetAddress, getLocalPort, getReceiveBufferSize, getReuseAddress, implAccept, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSocketFactory
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MSG_ELEMENT_NAMESPACE

protected static final String MSG_ELEMENT_NAMESPACE
See Also:
Constant Field Values

credTag

protected static final String credTag
See Also:
Constant Field Values

reqPipeTag

protected static final String reqPipeTag
See Also:
Constant Field Values

remPeerTag

protected static final String remPeerTag
See Also:
Constant Field Values

remPipeTag

protected static final String remPipeTag
See Also:
Constant Field Values

dataTag

protected static final String dataTag
See Also:
Constant Field Values

closeTag

protected static final String closeTag
See Also:
Constant Field Values

closeReqValue

protected static final String closeReqValue
See Also:
Constant Field Values

closeAckValue

protected static final String closeAckValue
See Also:
Constant Field Values

streamTag

protected static final String streamTag
See Also:
Constant Field Values

QUEUE_END_MESSAGE

protected static final Message QUEUE_END_MESSAGE
QUEUE_END_MESSAGE is used to signal that the queue has been closed.


group

protected PeerGroup group
The PeerGroup


pipeAdv

protected PipeAdvertisement pipeAdv
The pipe advertisement we are serving.


serverPipe

protected InputPipe serverPipe
The input pipe on which we listen for connect requests.


localCredential

protected Credential localCredential
The credential we will present to connect requests.


backlog

protected int backlog
The number of connect requests we will allow to become backlogged.


timeout

protected long timeout
The timeout for accept operations.


queue

protected BlockingQueue<Message> queue

bound

protected volatile boolean bound

closed

protected volatile boolean closed
Constructor Detail

JxtaServerSocket

public JxtaServerSocket()
                 throws IOException
Default Constructor

A call to bind() is needed to finish initializing this object.

Throws:
IOException - if an io error occurs

JxtaServerSocket

public JxtaServerSocket(SocketAddress address)
                 throws IOException
Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.

Parameters:
address - an instance of JxtaSocketAddress
Throws:
IOException - if an io error occurs
See Also:
JxtaSocketAddress

JxtaServerSocket

public JxtaServerSocket(PeerGroup group,
                        PipeAdvertisement pipeAdv)
                 throws IOException
Constructs and binds a JxtaServerSocket to the specified pipe.

Parameters:
group - JXTA PeerGroup
pipeAdv - PipeAdvertisement on which pipe requests are accepted
Throws:
IOException - if an I/O error occurs

JxtaServerSocket

public JxtaServerSocket(SocketAddress address,
                        int backlog)
                 throws IOException
Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.

Parameters:
address - an instance of JxtaSocketAddress
backlog - the size of the backlog queue
Throws:
IOException - if an I/O error occurs
See Also:
JxtaSocketAddress

JxtaServerSocket

public JxtaServerSocket(PeerGroup group,
                        PipeAdvertisement pipeAdv,
                        int backlog)
                 throws IOException
Constructor for the JxtaServerSocket object

Parameters:
group - JXTA PeerGroup
pipeAdv - PipeAdvertisement on which pipe requests are accepted
backlog - the maximum length of the queue.
Throws:
IOException - if an I/O error occurs

JxtaServerSocket

public JxtaServerSocket(SocketAddress address,
                        int backlog,
                        int timeout)
                 throws IOException
Constructs and binds a JxtaServerSocket using a JxtaSocketAddress as the address.

Parameters:
address - an instance of JxtaSocketAddress
backlog - the size of the backlog queue
timeout - connection timeout in milliseconds
Throws:
IOException - if an I/O error occurs
See Also:
JxtaSocketAddress

JxtaServerSocket

public JxtaServerSocket(PeerGroup group,
                        PipeAdvertisement pipeAdv,
                        int backlog,
                        int timeout)
                 throws IOException
Constructor for the JxtaServerSocket object.

Parameters:
group - JXTA PeerGroup
pipeAdv - PipeAdvertisement on which pipe requests are accepted
backlog - the maximum length of the queue.
timeout - the specified timeout, in milliseconds
Throws:
IOException - if an I/O error occurs

JxtaServerSocket

public JxtaServerSocket(PeerGroup group,
                        PipeAdvertisement pipeAdv,
                        int backlog,
                        int timeout,
                        CredentialValidator credValidator)
                 throws IOException
Constructor for the JxtaServerSocket object.

Parameters:
group - JXTA PeerGroup
pipeAdv - PipeAdvertisement on which pipe requests are accepted
backlog - the maximum length of the queue.
timeout - the specified timeout, in milliseconds
credValidator - the CredentialValidator
Throws:
IOException - if an I/O error occurs
Method Detail

finalize

protected void finalize()
                 throws Throwable

Closes the JxtaServerPipe.

Overrides:
finalize in class Object
Throws:
Throwable

accept

public Socket accept()
              throws IOException

Overrides:
accept in class ServerSocket
Throws:
IOException

bind

public void bind(PeerGroup group,
                 PipeAdvertisement pipeAdv)
          throws IOException
Binds the JxtaServerSocket to a specific pipe advertisement

Parameters:
group - JXTA PeerGroup
pipeAdv - PipeAdvertisement on which pipe requests are accepted
Throws:
IOException - if an I/O error occurs

bind

public void bind(PeerGroup group,
                 PipeAdvertisement pipeadv,
                 int backlog)
          throws IOException
Binds the JxtaServerSocket to a specific pipe advertisement

Parameters:
group - JXTA PeerGroup
pipeadv - PipeAdvertisement on which pipe requests are accepted
backlog - the maximum length of the queue.
Throws:
IOException - if an I/O error occurs

bind

public void bind(SocketAddress endpoint)
          throws IOException

Used to bind a JxtaServerSocket created with the no-arg constructor.

Overrides:
bind in class ServerSocket
Throws:
IOException

bind

public void bind(SocketAddress endpoint,
                 int backlog)
          throws IOException

Used to bind a JxtaServerSocket created with the no-arg constructor.

Overrides:
bind in class ServerSocket
Throws:
IOException

close

public void close()
           throws IOException

Overrides:
close in class ServerSocket
Throws:
IOException

getLocalSocketAddress

public SocketAddress getLocalSocketAddress()
Overrides:
getLocalSocketAddress in class ServerSocket
Returns:
the server socket's JxtaSocketAddress
See Also:
ServerSocket.getLocalSocketAddress()

getSoTimeout

public int getSoTimeout()
                 throws IOException

Overrides:
getSoTimeout in class ServerSocket
Throws:
IOException

setSoTimeout

public void setSoTimeout(int timeout)
                  throws SocketException

Overrides:
setSoTimeout in class ServerSocket
Throws:
SocketException

isBound

public boolean isBound()

Overrides:
isBound in class ServerSocket

isClosed

public boolean isClosed()

Overrides:
isClosed in class ServerSocket

getGroup

public PeerGroup getGroup()
Gets the group associated with this JxtaServerSocket object

Returns:
The group value

getPipeAdv

public PipeAdvertisement getPipeAdv()
Gets the PipeAdvertisement associated with this JxtaServerSocket object

Returns:
The pipeAdv value

pipeMsgEvent

public void pipeMsgEvent(PipeMsgEvent event)
Called for each pipe message event that occurs.

Specified by:
pipeMsgEvent in interface PipeMsgListener
Parameters:
event - The event being received.

createEphemeralSocket

protected JxtaSocket createEphemeralSocket(PeerGroup group,
                                           PipeAdvertisement pipeAdv,
                                           PipeAdvertisement remoteEphemeralPipeAdv,
                                           PeerAdvertisement remotePeerAdv,
                                           Credential localCredential,
                                           Credential credential,
                                           boolean isReliable)
                                    throws IOException
Construct the emphemeral socket result from accept. This method exists primarily so that sub-classes can substitute a different JxtaSocket sub-class.

Parameters:
group - The peer group for the socket.
pipeAdv - The public pipe advertisement.
remoteEphemeralPipeAdv - The pipe advertisement of the remote peer's ephemeral pipe.
remotePeerAdv - The peer advertisement of the remote peer.
localCredential - Our credential.
credential - The credential of the remote peer.
isReliable - if true, uses the reliability library in non-direct mode
Returns:
The new JxtaSocket instance.
Throws:
IOException - if an io error occurs

setCredential

public void setCredential(Credential localCredential)
Sets the credential to be used by this socket connection. If no credentials are set, the default group credential will be used.

Parameters:
localCredential - The credential to be used for connection responses or null if the default credential is to be used.

toString

public String toString()

This output is suitable for debugging but should not be parsed. All of the information is available through other means.

Overrides:
toString in class ServerSocket

JXSE