Project JXTA

net.jxta.impl.pipe
Class NonBlockingWireOutputPipe

java.lang.Object
  extended by net.jxta.impl.pipe.NonBlockingWireOutputPipe
All Implemented Interfaces:
Runnable, OutputPipe

 class NonBlockingWireOutputPipe
extends Object
implements 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 NonBlockingWireOutputPipe.workerState
          Tracks the state of our worker thread.
 
Constructor Summary
NonBlockingWireOutputPipe(PeerGroup g, WirePipe wire, PipeAdvertisement pAdv, Set peers)
          Create a new output pipe
 
Method Summary
 void close()
          
(package private)  boolean enqueue(Message message)
          Push a message on the send queue.
protected  void finalize()
          
 PipeAdvertisement getAdvertisement()
          
 String getName()
          
 ID getPipeID()
          
 String getType()
          
 boolean isClosed()
          
 void run()
          

Sends the messages.

 boolean send(Message message)
          
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonBlockingWireOutputPipe

public NonBlockingWireOutputPipe(PeerGroup g,
                                 WirePipe wire,
                                 PipeAdvertisement pAdv,
                                 Set peers)
Create a new output pipe

Parameters:
g - peergroup we are working in.
r - 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()

Overrides:
finalize in class Object

close

public void close()

Specified by:
close in interface OutputPipe

isClosed

public boolean isClosed()

Specified by:
isClosed in interface OutputPipe

getType

public final String getType()

Specified by:
getType in interface OutputPipe

getPipeID

public final ID getPipeID()

Specified by:
getPipeID in interface OutputPipe

getName

public final String getName()

Specified by:
getName in interface OutputPipe

getAdvertisement

public final PipeAdvertisement getAdvertisement()

Specified by:
getAdvertisement in interface OutputPipe

send

public boolean send(Message message)
             throws IOException

Specified by:
send in interface OutputPipe
Throws:
IOException

enqueue

boolean enqueue(Message message)
          throws IOException
Push a message on the send queue. The message should already contain the wire header.

Parameters:
message - the message to enqueue.
Throws:
IOException - for failures in queuing.

run

public void run()

Sends the messages.

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

STATE Activity
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 millisecondsthen the worker thread will exit. It will only be restarted if another message is eventually enqueued.
CLOSED Exit the worker thread.

Specified by:
run in interface Runnable

JXTA J2SE