JXTA

net.jxta.impl.pipe
Class NonBlockingOutputPipe

java.lang.Object
  extended by net.jxta.impl.pipe.NonBlockingOutputPipe
All Implemented Interfaces:
Runnable, EventListener, PipeResolver.Listener, OutputPipe
Direct Known Subclasses:
SecureOutputPipe

 class NonBlockingOutputPipe
extends Object
implements PipeResolver.Listener, OutputPipe, Runnable

An implementation of Ouput Pipe which sends messages on the pipe asynchronously. The send() method for this implementation will never block.


Nested Class Summary
(package private) static class NonBlockingOutputPipe.WorkerState
          Tracks the state of our worker thread.
 
Constructor Summary
NonBlockingOutputPipe(PeerGroup peerGroup, PipeResolver pipeResolver, PipeAdvertisement pAdv, ID destPeer, Set<? extends ID> peers)
          Create a new output pipe
 
Method Summary
 void close()
          close the pipe
protected  void finalize()
          
 PipeAdvertisement getAdvertisement()
          Gets the pipe advertisement
 String getName()
          Gets the pipe name
 ID getPipeID()
          Gets the pipe id
 String getType()
          Gets the pipe type
 boolean isClosed()
          Returns true if this pipe is closed and no longer accepting messages to be sent.
protected  EndpointAddress mkAddress(ID destPeer, ID pipeID)
          Convenience method for constructing a peer endpoint address from its peer id
 boolean pipeNAKEvent(PipeResolver.Event event)
          A NAK Event was received for this pipe
 boolean pipeResolveEvent(PipeResolver.Event event)
          Pipe Resolve event
 void run()
          

Sends the messages.

 boolean send(Message msg)
          Send a message through the pipe

WARNING: The message object used when sending a pipe message should not be reused or modified after the OutputPipe.send(Message) call is made.

 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonBlockingOutputPipe

public NonBlockingOutputPipe(PeerGroup peerGroup,
                             PipeResolver pipeResolver,
                             PipeAdvertisement pAdv,
                             ID destPeer,
                             Set<? extends ID> peers)
Create a new output pipe

Parameters:
peerGroup - peergroup we are working in.
pipeResolver - the piperesolver this pipe is bound to.
pAdv - advertisement for the pipe we are supporting.
destPeer - the peer this pipe is currently bound to.
peers - the set of peers we allow this pipe to be bound to.
Method Detail

finalize

protected void finalize()
                 throws Throwable

Overrides:
finalize in class Object
Throws:
Throwable

close

public void close()
close the pipe

Specified by:
close in interface OutputPipe

isClosed

public boolean isClosed()
Returns true if this pipe is closed and no longer accepting messages to be sent. The pipe should be discarded.

Specified by:
isClosed in interface OutputPipe
Returns:
true if this pipe is closed, otherwise false.

getType

public final String getType()
Gets the pipe type

Specified by:
getType in interface OutputPipe
Returns:
The type

getPipeID

public final ID getPipeID()
Gets the pipe id

Specified by:
getPipeID in interface OutputPipe
Returns:
The type

getName

public final String getName()
Gets the pipe name

Specified by:
getName in interface OutputPipe
Returns:
The name

getAdvertisement

public final PipeAdvertisement getAdvertisement()
Gets the pipe advertisement

Specified by:
getAdvertisement in interface OutputPipe
Returns:
The advertisement

send

public boolean send(Message msg)
             throws IOException
Send a message through the pipe

WARNING: The message object used when sending a pipe message should not be reused or modified after the OutputPipe.send(Message) call is made. Concurrent modification of messages will produce unexpected result.

Specified by:
send in interface OutputPipe
Parameters:
msg - is the PipeMessage to be sent.
Returns:
boolean true if the message has been sent otherwise false. false. is commonly returned for non-error related congestion, meaning that you should be able to send the message after waiting some amount of time.
Throws:
IOException - output pipe error

run

public void run()

Sends the messages.

This method does a lot of things. It has several distinct states:

Acquire a messenger to the specified destination peer. If a messenger is acquired, then go to SENDMESSAGES state otherwise go to STARTMIGRATE.

STATE Activity
ACQUIREMESSENGER
SENDMESSAGES Send messages until queue is closed and all messages have been sent. Go to state CLOSED when done. If the messenger becomes closed then go to ACQUIREMESSENGER. If there are no messages to send for IDLEWORKERLINGER milliseconds then the worker thread will exit. It will only be restarted if another message is eventually enqueued.
STARTVERIFY Starts a verification query(s) to the destination peer. This state is activated after PipeServiceImpl.VERIFYINTERVAL milliseconds of sending messages. The query responses will be tracked in the PENDINGVERIFY state.
STARTMIGRATE Starts a query(s) for peers listening on this pipe. The query responses will be tracked in the PENDINGMIGRATE state.
PENDINGVERIFY Issues query messages to verify that the destination peer is still listening on the pipe. Queries are issued every QUERYINTERVAL milliseconds. If a positive response is received, go to state ACQUIREMESSENGER. If no response is received within QUERYTIMEOUT milliseconds or a negative response is received then go to state STARTMIGRATE.
PENDINGMIGRATE Issues query messages to find a new destination peer. Queries are issued every QUERYINTERVAL milliseconds. If a positive response is received, go to state ACQUIREMESSENGER. If no positive response from an eligible peer is received within QUERYTIMEOUT milliseconds go to state CLOSED.
CLOSED Exit the worker thread.

Specified by:
run in interface Runnable

mkAddress

protected EndpointAddress mkAddress(ID destPeer,
                                    ID pipeID)
Convenience method for constructing a peer endpoint address from its peer id

Parameters:
destPeer - the desitnation peer
pipeID - the pipe to put in the param field.
Returns:
the pipe endpoint address.

pipeNAKEvent

public boolean pipeNAKEvent(PipeResolver.Event event)
A NAK Event was received for this pipe

Specified by:
pipeNAKEvent in interface PipeResolver.Listener
Parameters:
event - event the PipeResolver Event
Returns:
true if the event was handled otherwise false

pipeResolveEvent

public boolean pipeResolveEvent(PipeResolver.Event event)
Pipe Resolve event

Specified by:
pipeResolveEvent in interface PipeResolver.Listener
Parameters:
event - event the PipeResolver Event
Returns:
true if the event was handled otherwise false

JXSE