|
JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.util.JxtaBiDiPipe
public class JxtaBiDiPipe
JxtaBiDiPipe is a pair of UnicastPipe channels that implements a bidirectional pipe. By default, JxtaBiDiPipe operates in reliable mode, unless otherwise specified, in addition, messages must not exceed the Endpoint MTU size of 64K, exceed the MTU will lead to unexpected behavior.
It highly recommended that an application message listener is specified, not doing so, may lead to message loss in the event the internal queue is overflowed. Sending messages vissendMessage(Message)
from within a
PipeMsgListener
may result in a deadlock due to contention
between the sending and receiving portions of BiDi pipes.
JxtaBiDiPipe, whenever possible, will attempt to utilize direct tcp messengers,
which leads to improved performance.
Field Summary | |
---|---|
protected Object |
acceptLock
|
protected boolean |
bound
|
protected boolean |
closed
|
protected Object |
closeLock
|
protected OutputPipe |
connectOutpipe
|
protected Credential |
credential
|
protected StructuredDocument |
credentialDoc
|
protected boolean |
dequeued
|
protected boolean |
direct
If true then we are using a reliable direct messenger to the
remote peer. |
protected PipeEventListener |
eventListener
|
protected Object |
finalLock
|
protected PeerGroup |
group
|
protected InputPipe |
inputPipe
|
protected boolean |
isReliable
If true then we are using the underlying end-to-end ACK reliable
layer to ensure that messages are received by the remote peer. |
protected int |
maxRetryTimeout
|
protected PipeMsgListener |
msgListener
|
protected Messenger |
msgr
|
protected PipeAdvertisement |
myPipeAdv
|
protected OutgoingMsgrAdaptor |
outgoing
|
static int |
PIPE_CLOSED_EVENT
Pipe close Event |
protected PipeAdvertisement |
pipeAdv
|
protected PipeService |
pipeSvc
|
protected int |
retryTimeout
|
protected ReliableInputStream |
ris
|
protected ReliableOutputStream |
ros
|
protected PipeStateListener |
stateListener
|
protected InputStream |
stream
|
protected int |
timeout
|
protected boolean |
waiting
|
protected int |
windowSize
|
Constructor Summary | |
---|---|
|
JxtaBiDiPipe()
Creates a new object with a default timeout of #timeout, and no reliability. |
protected |
JxtaBiDiPipe(PeerGroup group,
Messenger msgr,
PipeAdvertisement pipe,
StructuredDocument credDoc,
boolean isReliable,
boolean direct)
Creates a bidirectional pipe |
|
JxtaBiDiPipe(PeerGroup group,
PipeAdvertisement pipeAd,
int timeout,
PipeMsgListener msgListener)
Creates a bidirectional pipe. |
|
JxtaBiDiPipe(PeerGroup group,
PipeAdvertisement pipeAd,
int timeout,
PipeMsgListener msgListener,
boolean reliable)
attempts to create a bidirectional connection to remote peer |
|
JxtaBiDiPipe(PeerGroup group,
PipeAdvertisement pipeAd,
PipeMsgListener msgListener)
Creates a bidirectional pipe. |
Method Summary | |
---|---|
protected boolean |
checkCred(StructuredDocument cred)
Not implemented yet |
void |
close()
Closes this pipe. |
protected void |
closePipe(boolean fastClose)
|
void |
connect(PeerGroup group,
PeerID peerid,
PipeAdvertisement pipeAd,
int timeout,
PipeMsgListener msgListener)
Connects to a remote JxtaServerPipe |
void |
connect(PeerGroup group,
PeerID peerid,
PipeAdvertisement pipeAd,
int timeout,
PipeMsgListener msgListener,
boolean reliable)
Connects to a remote JxtaServerPipe |
void |
connect(PeerGroup group,
PipeAdvertisement pipeAd)
Connect to a JxtaServerPipe with default timeout |
void |
connect(PeerGroup group,
PipeAdvertisement pipeAd,
int timeout)
Connects to a remote JxtaBiDiPipe |
protected Message |
createOpenMessage(PeerGroup group,
PipeAdvertisement pipeAd)
Creates a connection request message |
protected void |
finalize()
Closes the JxtaBiDiPipe. |
protected static StructuredDocument |
getCredDoc(PeerGroup group)
Obtain the cred doc from the group object. |
StructuredDocument |
getCredentialDoc()
get the remote credential doc |
protected static Messenger |
getDirectMessenger(PeerGroup group,
PipeAdvertisement pipeAdv,
PeerAdvertisement peer)
A lightweight direct messenger output pipe constructor, note the return type Since all the info needed is available, there's no need for to use the pipe service to resolve the pipe we have all we need to construct a messenger. |
InputPipe |
getInputPipe()
Returns an input stream for this socket. |
PipeMsgListener |
getListener()
Deprecated. use getMessageListener instead |
int |
getMaxRetryTimeout()
Gets the Maximum Retry Timeout of the reliability layer |
Message |
getMessage(int timeout)
Gets a message from the queue. |
PipeMsgListener |
getMessageListener()
Returns the message listener for this pipe |
PipeAdvertisement |
getPipeAdvertisement()
Returns the Assigned PipeAdvertisement |
PipeEventListener |
getPipeEventListener()
Returns the Pipe event listener for this pipe |
PipeStateListener |
getPipeStateListener()
Returns the Pipe state listener for this pipe |
PeerAdvertisement |
getRemotePeerAdvertisement()
Returns remote PeerAdvertisement |
PipeAdvertisement |
getRemotePipeAdvertisement()
Returns remote PipeAdvertisement |
int |
getRetryTimeout()
Gets the Retry Timeout of the reliability layer |
int |
getWindowSize()
When in reliable mode, gets the Reliable library window size |
boolean |
isBound()
Returns the binding state of the JxtaServerPipe. |
protected static Messenger |
lightweightOutputPipe(PeerGroup group,
PipeAdvertisement pipeAdv,
PeerAdvertisement peer)
A lightweight output pipe constructor, note the return type Since all the info needed is available, there's no need for to use the pipe service to resolve the pipe we have all we need to construct a messenger. |
void |
outputPipeEvent(OutputPipeEvent event)
Called when a input pipe has been located for a previously registered pipe. |
void |
pipeMsgEvent(PipeMsgEvent event)
Called for each pipe message event that occurs. |
void |
processIncomingMessage(Message message)
This method is invoked by the Reliablity library for each incoming data message |
boolean |
sendMessage(Message msg)
Send a message Messenger |
void |
setCredentialDoc(StructuredDocument doc)
Sets the connection credential doc. |
protected void |
setInputPipe(InputPipe inputPipe)
Sets the inputPipe attribute of the JxtaBiDiPipe object |
void |
setListener(PipeEventListener eventListener)
Deprecated. use setPipeEventListener instead |
void |
setListener(PipeMsgListener msgListener)
Deprecated. use setMessageListener instead |
void |
setMaxRetryTimeout(int maxRetryTimeout)
Gets the Maximum Retry Timeout of the reliability layer |
void |
setMessageListener(PipeMsgListener msgListener)
Sets message listener for a pipe spawned by the JxtaServerPipe. |
void |
setPipeEventListener(PipeEventListener eventListener)
Sets a Pipe event listener, set listener to null to unset the listener |
void |
setPipeStateListener(PipeStateListener stateListener)
Sets a Pipe state listener, set listener to null to unset the listener |
void |
setReliable(boolean reliable)
Toggles reliability |
protected void |
setRemotePeerAdvertisement(PeerAdvertisement peer)
Sets the remote PeerAdvertisement |
protected void |
setRemotePipeAdvertisement(PipeAdvertisement pipe)
Sets the remote PipeAdvertisement |
void |
setRetryTimeout(int retryTimeout)
Sets the Retry Timeout of the underlying reliability layer . |
void |
setWindowSize(int windowSize)
When in reliable mode, sets the Reliable library window size |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int timeout
protected int retryTimeout
protected int maxRetryTimeout
protected int windowSize
protected PeerGroup group
protected PipeAdvertisement pipeAdv
protected PipeAdvertisement myPipeAdv
protected PipeService pipeSvc
protected InputPipe inputPipe
protected OutputPipe connectOutpipe
protected Messenger msgr
protected InputStream stream
protected final Object closeLock
protected final Object acceptLock
protected final Object finalLock
protected boolean closed
protected boolean bound
protected boolean dequeued
protected PipeMsgListener msgListener
protected PipeEventListener eventListener
protected PipeStateListener stateListener
protected Credential credential
protected boolean waiting
protected boolean isReliable
true
then we are using the underlying end-to-end ACK reliable
layer to ensure that messages are received by the remote peer.
protected ReliableInputStream ris
protected ReliableOutputStream ros
protected volatile boolean direct
true
then we are using a reliable direct messenger to the
remote peer. We will assume that messages which are sent successfully
will be received successfully.
protected OutgoingMsgrAdaptor outgoing
protected StructuredDocument credentialDoc
public static final int PIPE_CLOSED_EVENT
Constructor Detail |
---|
protected JxtaBiDiPipe(PeerGroup group, Messenger msgr, PipeAdvertisement pipe, StructuredDocument credDoc, boolean isReliable, boolean direct) throws IOException
group
- group contextmsgr
- lightweight output pipepipe
- PipeAdvertisementisReliable
- Whether the connection is reliable or notcredDoc
- Credential StructuredDocumentdirect
- indicates a direct messenger pipe
IOException
- if an io error occurspublic JxtaBiDiPipe()
public JxtaBiDiPipe(PeerGroup group, PipeAdvertisement pipeAd, PipeMsgListener msgListener) throws IOException
group
- group contextpipeAd
- PipeAdvertisementmsgListener
- application PipeMsgListener
IOException
- if an io error occurspublic JxtaBiDiPipe(PeerGroup group, PipeAdvertisement pipeAd, int timeout, PipeMsgListener msgListener) throws IOException
group
- group contexttimeout
- The number of milliseconds within which the JxtaBiDiPipe must
be successfully created. An exception will be thrown if the pipe
cannot be created in the alotted time. A timeout value of 0
(zero) specifies an infinite timeout.pipeAd
- PipeAdvertisementmsgListener
- application PipeMsgListener
IOException
- if an io error occurspublic JxtaBiDiPipe(PeerGroup group, PipeAdvertisement pipeAd, int timeout, PipeMsgListener msgListener, boolean reliable) throws IOException
group
- group contextpipeAd
- PipeAdvertisementtimeout
- The number of milliseconds within which the JxtaBiDiPipe must
be successfully created. An exception will be thrown if the pipe
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.msgListener
- application PipeMsgListenerreliable
- if true, the reliability is assumed
IOException
- if an io error occursMethod Detail |
---|
public void connect(PeerGroup group, PipeAdvertisement pipeAd) throws IOException
group
- group contextpipeAd
- PipeAdvertisement
IOException
- if an io error occurspublic void connect(PeerGroup group, PipeAdvertisement pipeAd, int timeout) throws IOException
group
- group contextpipeAd
- PipeAdvertisementtimeout
- timeout in ms, also reset object default timeout
to that of timeout
IOException
- if an io error occurspublic void connect(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAd, int timeout, PipeMsgListener msgListener) throws IOException
group
- group contextpeerid
- peer to connect topipeAd
- PipeAdvertisementtimeout
- timeout in ms, also reset object default timeout to that of timeoutmsgListener
- application PipeMsgListener
IOException
- if an io error occurspublic void connect(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAd, int timeout, PipeMsgListener msgListener, boolean reliable) throws IOException
group
- group contextpeerid
- peer to connect topipeAd
- PipeAdvertisementtimeout
- timeout in ms, also reset object default timeout to that of timeoutmsgListener
- application PipeMsgListenerreliable
- Reliable connection
IOException
- if an io error occurspublic void setReliable(boolean reliable) throws IOException
reliable
- Toggles reliability to reliable
IOException
- if pipe is boundprotected static StructuredDocument getCredDoc(PeerGroup group)
group
- group context
public StructuredDocument getCredentialDoc()
public void setCredentialDoc(StructuredDocument doc)
doc
- Credential StructuredDocumentprotected Message createOpenMessage(PeerGroup group, PipeAdvertisement pipeAd) throws IOException
group
- group contextpipeAd
- pipe advertisement
IOException
- if an io error occurspublic boolean isBound()
public InputPipe getInputPipe() throws IOException
IOException
- if an I/O error occurs when creating the
input stream.public PeerAdvertisement getRemotePeerAdvertisement()
public PipeAdvertisement getRemotePipeAdvertisement()
protected void setRemotePeerAdvertisement(PeerAdvertisement peer)
peer
- Remote PeerAdvertisementprotected void setRemotePipeAdvertisement(PipeAdvertisement pipe)
pipe
- PipeAdvertisementpublic void close() throws IOException
IOException
- if an I/O error occurs when closing this
socket.protected void closePipe(boolean fastClose) throws IOException
IOException
protected void setInputPipe(InputPipe inputPipe)
inputPipe
- The new inputPipe valuepublic void pipeMsgEvent(PipeMsgEvent event)
pipeMsgEvent
in interface PipeMsgListener
event
- The event being received.public int getMaxRetryTimeout()
public void setMaxRetryTimeout(int maxRetryTimeout)
maxRetryTimeout
- The new maximum retry timeout value
IllegalArgumentException
- if maxRetryTimeout exceeds jxta platform maximum retry timeoutpublic int getRetryTimeout()
public void setRetryTimeout(int retryTimeout) throws IOException
retryTimeout
- The new retry timeout value
IOException
- if an I/O error occurspublic int getWindowSize()
public void setWindowSize(int windowSize) throws IOException
windowSize
- The new window size value
IOException
- if an I/O error occurspublic void processIncomingMessage(Message message)
message
- Incoming messagepublic boolean sendMessage(Message msg) throws IOException
Messenger
msg
- Message to send to the remote side
IOException
- if the underlying messenger breaks, either due to
a physical address change, reliability issue.Message
public void outputPipeEvent(OutputPipeEvent event)
OutputPipe
which can
be used to communicate with the remote peer.
outputPipeEvent
in interface OutputPipeListener
event
- the eventprotected static Messenger getDirectMessenger(PeerGroup group, PipeAdvertisement pipeAdv, PeerAdvertisement peer)
group
- group contextpipeAdv
- Remote Pipe Advertisementpeer
- Remote Peer advertisement
protected static Messenger lightweightOutputPipe(PeerGroup group, PipeAdvertisement pipeAdv, PeerAdvertisement peer)
group
- group contextpipeAdv
- Remote Pipe Advertisementpeer
- Remote Peer advertisement
protected boolean checkCred(StructuredDocument cred)
cred
- the credential document
@Deprecated public PipeMsgListener getListener()
public PipeMsgListener getMessageListener()
@Deprecated public void setListener(PipeMsgListener msgListener)
msgListener
- New value of property listener.public void setMessageListener(PipeMsgListener msgListener)
sendMessage(Message)
from within a
PipeMsgListener
may result in a deadlock due to contention
between the sending and receiving portions of BiDi pipes.
msgListener
- New value of property listener.@Deprecated public void setListener(PipeEventListener eventListener)
eventListener
- New value of property listener.public void setPipeEventListener(PipeEventListener eventListener)
eventListener
- New value of property listener.public PipeEventListener getPipeEventListener()
public void setPipeStateListener(PipeStateListener stateListener)
stateListener
- New value of property listener.public PipeStateListener getPipeStateListener()
public Message getMessage(int timeout) throws InterruptedException
timeout
- Amount of time to wait in milliseconds for an object to
be available. Per Java convention, a timeout of zero (0) means wait an
infinite amount of time. Negative values mean do not wait at all.
InterruptedException
- if the operation is interrupted before
the timeout interval is completed.public PipeAdvertisement getPipeAdvertisement()
protected void finalize() throws Throwable
finalize
in class Object
Throwable
|
JXSE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |