Project 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

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

<Cred> to determine whether requestor has the proper access to be granted a connection </Cred>

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

<remPipe> remote pipe advertisement </remPipe>

<reqPeer> remote peer advertisement </reqPeer>

<reliable> Reliability setting ("true", or "false") </reliable>

<data> data </data>

JxtaServerPipe then creates a new private pipe, and listens for messages on that pipe resolves the Requestor's pipe, and sends private pipecreated advertisement back, where the remove side resolves back.


Field Summary
protected static String closeTag
           
protected static String credTag
           
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 timeout defaults to 60 seconds, i.e. blocking.
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).
 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)
          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.
 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, by default this JxtaServerPipe's timeout is set to 60000 ms
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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

myCredentialDoc

protected StructuredDocument myCredentialDoc
Constructor Detail

JxtaServerPipe

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

backlog default of 50

timeout defaults 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

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 - the specified timeout, in milliseconds
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.
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:
JxtaBiDiPipe
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, by default this JxtaServerPipe's timeout is set to 60000 ms

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 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)
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 -
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

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

JXTA J2SE