JXTA

net.jxta.util
Class JxtaServerPipe

java.lang.Object
  extended by net.jxta.util.JxtaServerPipe
All Implemented Interfaces:
EventListener, PipeMsgListener

public class JxtaServerPipe
extends Object
implements PipeMsgListener

The server side of a JxtaBiDiPipe. The intent of this object is accept connection requests. JxtaServerPipe follows the same pattern as java.net.ServerSocket, without it no connection can be established.


Field Summary
protected static String closeTag
           
protected  BlockingQueue<JxtaBiDiPipe> connectionQueue
           
protected static String credTag
           
protected static String directSupportedTag
           
protected  StructuredDocument myCredentialDoc
           
protected static String nameSpace
           
protected static String reliableTag
           
protected static String remPeerTag
           
protected static String remPipeTag
           
protected static String reqPipeTag
           
 
Constructor Summary
JxtaServerPipe(PeerGroup group, PipeAdvertisement pipeadv)
          Default constructor for the JxtaServerPipe

backlog default of 50 call to accept() for this ServerPipe will block for only this amount of time.

JxtaServerPipe(PeerGroup group, PipeAdvertisement pipeadv, int backlog)
          Constructor for the JxtaServerPipe object
JxtaServerPipe(PeerGroup group, PipeAdvertisement pipeadv, int backlog, int timeout)
          Constructor for the JxtaServerPipe
 
Method Summary
 JxtaBiDiPipe accept()
          Listens for a connection to be made to this socket and accepts it.
 void bind(PeerGroup group, PipeAdvertisement pipeadv)
          Binds the JxtaServerPipe to a specific pipe advertisement
 void bind(PeerGroup group, PipeAdvertisement pipeadv, int backlog)
          Binds the JxtaServerPipe to a specific pipe advertisement
 void close()
          Closes this JxtaServerPipe (closes the underlying input pipe).
protected  void finalize()
          

Closes the JxtaServerPipe.

 StructuredDocument getCredentialDoc()
          get the credential doc
 PeerGroup getGroup()
          Gets the group associated with this JxtaServerPipe
 PipeAdvertisement getPipeAdv()
          Gets the PipeAdvertisement associated with this JxtaServerPipe
 int getPipeTimeout()
          Gets the Timeout attribute of the JxtaServerPipe
 boolean isBound()
          Returns the binding state of the JxtaServerPipe.
 boolean isClosed()
          Returns the closed state of the JxtaServerPipe.
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)
          Called for each pipe message event that occurs.
protected  void sendResponseMessage(PeerGroup group, Messenger msgr, PipeAdvertisement pipeAd)
          Method sendResponseMessage get the createResponseMessage and sends it.
 void setCredentialDoc(StructuredDocument doc)
          Sets the connection credential doc If no credentials are set, the default group credential will be used
 void setPipeTimeout(int timeout)
          Sets the Timeout attribute of the JxtaServerPipe a timeout of 0 blocks forever.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameSpace

protected static final String 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

closeTag

protected static final String closeTag
See Also:
Constant Field Values

reliableTag

protected static final String reliableTag
See Also:
Constant Field Values

directSupportedTag

protected static final String directSupportedTag
See Also:
Constant Field Values

connectionQueue

protected BlockingQueue<JxtaBiDiPipe> connectionQueue

myCredentialDoc

protected StructuredDocument myCredentialDoc
Constructor Detail

JxtaServerPipe

public JxtaServerPipe(PeerGroup group,
                      PipeAdvertisement pipeadv)
               throws IOException
Default constructor for the JxtaServerPipe

backlog default of 50

call to accept() for this ServerPipe will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the ServerPipe is still valid.

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

JxtaServerPipe

public JxtaServerPipe(PeerGroup group,
                      PipeAdvertisement pipeadv,
                      int backlog,
                      int timeout)
               throws IOException
Constructor for the JxtaServerPipe

Parameters:
group - JXTA PeerGroup
pipeadv - PipeAdvertisement on which pipe requests are accepted
backlog - the maximum length of the queue.
timeout - call to accept() for this ServerPipe will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the ServerPipe is still valid.
Throws:
IOException - if an I/O error occurs

JxtaServerPipe

public JxtaServerPipe(PeerGroup group,
                      PipeAdvertisement pipeadv,
                      int backlog)
               throws IOException
Constructor for the JxtaServerPipe object

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

bind

public void bind(PeerGroup group,
                 PipeAdvertisement pipeadv)
          throws IOException
Binds the JxtaServerPipe 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 JxtaServerPipe 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

accept

public JxtaBiDiPipe accept()
                    throws IOException
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

Returns:
the connection accepted, null otherwise
Throws:
IOException - if an I/O error occurs

getGroup

public PeerGroup getGroup()
Gets the group associated with this JxtaServerPipe

Returns:
The group value

getPipeAdv

public PipeAdvertisement getPipeAdv()
Gets the PipeAdvertisement associated with this JxtaServerPipe

Returns:
The pipeAdv value

close

public void close()
           throws IOException
Closes this JxtaServerPipe (closes the underlying input pipe).

Throws:
IOException - if an I/O error occurs

getPipeTimeout

public int getPipeTimeout()
                   throws IOException
Gets the Timeout attribute of the JxtaServerPipe

Returns:
The soTimeout value
Throws:
IOException - if an I/O error occurs

setPipeTimeout

public void setPipeTimeout(int timeout)
                    throws SocketException
Sets the Timeout attribute of the JxtaServerPipe a timeout of 0 blocks forever.

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

isClosed

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

Returns:
true if the socket has been closed

isBound

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

Returns:
true if the ServerSocket successfully bound to an address

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.

sendResponseMessage

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

Parameters:
group - the peer group
msgr - the remote node messenger
pipeAd - the pipe advertisement
Throws:
IOException - for failures sending the response message.

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 - the peer group
pipeadv - to get the basename and type from
Returns:
PipeAdvertisement a new pipe advertisement

getCredentialDoc

public StructuredDocument getCredentialDoc()
get the credential doc

Returns:
Credential StructuredDocument

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

finalize

protected void finalize()
                 throws Throwable

Closes the JxtaServerPipe.

Overrides:
finalize in class Object
Throws:
Throwable

JXSE