Project JXTA

net.jxta.socket
Class JxtaServerSocket

java.lang.Object
  extended byjava.net.ServerSocket
      extended bynet.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.


Field Summary
protected  int backlog
           
protected  boolean bound
           
protected  boolean closed
           
protected  String closeLock
           
static String closeTag
           
protected  boolean created
           
static String credTag
           
static String dataTag
           
protected  PeerGroup group
           
protected  StructuredDocument myCredentialDoc
           
static String nameSpace
           
protected  PipeAdvertisement pipeadv
           
protected  net.jxta.impl.util.UnbiasedQueue queue
           
static String remPeerTag
           
static String remPipeTag
           
static String reqPipeTag
           
protected  InputPipe serverPipe
           
static String streamTag
           
protected  int timeout
           
 
Constructor Summary
JxtaServerSocket()
          default Constructor backlog default of 50 timeout defaults to 60 seconds, i.e. blocking.
JxtaServerSocket(PeerGroup group, PipeAdvertisement pipeadv)
          Constructor for the JxtaServerSocket The backlog defaults to 50.
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 The timeout defaults to 0, i.e. blocking.
 
Method Summary
 Socket accept()
          Listens for a connection to be made to this socket and accepts it.
 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)
          Unsupported operation, an IOException will be thrown
 void bind(SocketAddress endpoint, int backlog)
          Unsupported operation, an IOException will be thrown
 void close()
          Closes this socket.
 PeerGroup getGroup()
          Gets the group associated with this JxtaServerSocket object
 PipeAdvertisement getPipeAdv()
          Gets the PipeAdvertisement associated with this JxtaServerSocket object
 int getSoTimeout()
          Gets the Timeout attribute of the JxtaServerSocket object, specified in milliseconds.
 boolean isBound()
          Returns the binding state of the JxtaServerSocket.
 boolean isClosed()
          Returns the closed state of the JxtaServerSocket.
protected static PipeAdvertisement newInputPipe(PeerGroup group, PipeAdvertisement pipeadv)
          Utility method newInputPipe is used to get new pipe advertisement (w/random pipe ID) from old one.
 void pipeMsgEvent(PipeMsgEvent event)
          when request messages arrive this method is called
protected  void sendResponseMessage(PeerGroup group, Messenger msgr, PipeAdvertisement pipeAd)
          Method sendResponseMessage get the createResponseMessage and sends it.
protected  void setBound()
          Sets the bound attribute of the JxtaServerSocket object
 void setCredentialDoc(StructuredDocument doc)
          Sets the connection credential doc If no credentials are set, the default group credential will be used
 void setSoTimeout(int timeout)
          Sets the Timeout attribute of the JxtaServerSocket, specified in milliseconds.
 String toString()
          
 
Methods inherited from class java.net.ServerSocket
getChannel, getInetAddress, getLocalPort, getLocalSocketAddress, getReceiveBufferSize, getReuseAddress, implAccept, setReceiveBufferSize, setReuseAddress, setSocketFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nameSpace

public static final String nameSpace
See Also:
Constant Field Values

credTag

public static final String credTag
See Also:
Constant Field Values

reqPipeTag

public static final String reqPipeTag
See Also:
Constant Field Values

remPeerTag

public static final String remPeerTag
See Also:
Constant Field Values

remPipeTag

public static final String remPipeTag
See Also:
Constant Field Values

dataTag

public static final String dataTag
See Also:
Constant Field Values

closeTag

public static final String closeTag
See Also:
Constant Field Values

streamTag

public static final String streamTag
See Also:
Constant Field Values

group

protected PeerGroup group

serverPipe

protected InputPipe serverPipe

pipeadv

protected PipeAdvertisement pipeadv

backlog

protected int backlog

timeout

protected int timeout

closeLock

protected String closeLock

queue

protected net.jxta.impl.util.UnbiasedQueue queue

created

protected boolean created

bound

protected boolean bound

closed

protected boolean closed

myCredentialDoc

protected StructuredDocument myCredentialDoc
Constructor Detail

JxtaServerSocket

public JxtaServerSocket()
                 throws IOException
default Constructor

backlog default of 50

timeout defaults to 60 seconds, i.e. blocking.

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


JxtaServerSocket

public JxtaServerSocket(PeerGroup group,
                        PipeAdvertisement pipeadv)
                 throws IOException
Constructor for the JxtaServerSocket

The backlog defaults to 50.

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

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

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(PeerGroup group,
                        PipeAdvertisement pipeadv,
                        int backlog,
                        int timeout)
                 throws IOException
Constructor for the JxtaServerSocket object

The timeout defaults to 0, i.e. blocking.

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
Method Detail

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
Unsupported operation, an IOException will be thrown

Throws:
IOException

bind

public void bind(SocketAddress endpoint,
                 int backlog)
          throws IOException
Unsupported operation, an IOException will be thrown

Throws:
IOException

accept

public Socket accept()
              throws IOException
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made, unless the timeout has been previously set.

Returns:
JxtaSocket
Throws:
IOException - if an I/O error occurs

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

close

public void close()
           throws IOException
Closes this socket. Closes this socket, erasing queue of connection requests.

Throws:
IOException - if an I/O error occurs

setBound

protected void setBound()
Sets the bound attribute of the JxtaServerSocket object


getSoTimeout

public int getSoTimeout()
                 throws IOException
Gets the Timeout attribute of the JxtaServerSocket object, specified in milliseconds.

Returns:
The socket timeout value, in milliseconds
Throws:
IOException - if an I/O error occurs

setSoTimeout

public void setSoTimeout(int timeout)
                  throws SocketException
Sets the Timeout attribute of the JxtaServerSocket, specified in milliseconds. A timeout of 0 blocks forever, by default timeout is set to 60000

Parameters:
timeout - The new soTimeout value
Throws:
IOException - if an I/O error occurs
SocketException

isClosed

public boolean isClosed()
Returns the closed state of the JxtaServerSocket.

Returns:
true if the socket has been closed

isBound

public boolean isBound()
Returns the binding state of the JxtaServerSocket.

Returns:
true if the ServerSocket successfully bound to an address

pipeMsgEvent

public void pipeMsgEvent(PipeMsgEvent event)
when request messages arrive this method is called

Specified by:
pipeMsgEvent in interface PipeMsgListener
Parameters:
event - the pipe message event

sendResponseMessage

protected void sendResponseMessage(PeerGroup group,
                                   Messenger msgr,
                                   PipeAdvertisement pipeAd)
                            throws IOException
Method sendResponseMessage get the createResponseMessage and sends it.

Parameters:
group -
msgr -
pipeAd -
Returns:
Message The value of createResponseMessage that was sent, or null
Throws:
IOException

newInputPipe

protected static PipeAdvertisement newInputPipe(PeerGroup group,
                                                PipeAdvertisement pipeadv)
Utility method newInputPipe is used to get new pipe advertisement (w/random pipe ID) from old one.

Called by JxtaSocket to make pipe (name -> name.remote) for open message

Called by JxtaServerSocket to make pipe (name.remote -> name.remote.remote) for response message

Parameters:
group -
pipeadv - to get the basename and type from
Returns:
PipeAdvertisement a new pipe advertisement

setCredentialDoc

public void setCredentialDoc(StructuredDocument doc)
Sets the connection credential doc If no credentials are set, the default group credential will be used

Parameters:
doc - Credential StructuredDocument

toString

public String toString()


JXTA J2SE