JXTA

net.jxta.impl.pipe
Class InputPipeImpl

java.lang.Object
  extended by net.jxta.impl.pipe.InputPipeImpl
All Implemented Interfaces:
EndpointListener, InputPipe
Direct Known Subclasses:
SecureInputPipeImpl

 class InputPipeImpl
extends Object
implements EndpointListener, InputPipe

Implements the InputPipe interface by listening on the endpoint for messages to service "PipeService" and a param of the Pipe ID.


Field Summary
protected  boolean closed
           
protected  PipeMsgListener listener
           
protected  PipeAdvertisement pipeAdv
           
protected  ID pipeID
           
protected  UnbiasedQueue queue
           
protected static int QUEUESIZE
           
protected  PipeRegistrar registrar
           
 
Constructor Summary
InputPipeImpl(PipeRegistrar r, PipeAdvertisement adv, PipeMsgListener listener)
          Constructor for the InputPipeImpl object
 
Method Summary
 void close()
          Close the pipe.
protected  void finalize()
          

Closes the pipe.

 PipeAdvertisement getAdvertisement()
          Gets the pipe advertisement
 String getName()
          Gets the pipe name
 ID getPipeID()
          Gets the pipe id
 String getType()
          Gets the pipe type
 Message poll(int timeout)
          Poll for a message from the pipe.
 void processIncomingMessage(Message msg, EndpointAddress srcAddr, EndpointAddress dstAddr)
          This method is invoked by the EndpointService for each incoming message which is addressed to this listener.
 Message waitForMessage()
          Wait (block) for a message to be received.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUEUESIZE

protected static final int QUEUESIZE
See Also:
Constant Field Values

registrar

protected PipeRegistrar registrar

pipeAdv

protected final PipeAdvertisement pipeAdv

pipeID

protected final ID pipeID

closed

protected volatile boolean closed

listener

protected PipeMsgListener listener

queue

protected final UnbiasedQueue queue
Constructor Detail

InputPipeImpl

InputPipeImpl(PipeRegistrar r,
              PipeAdvertisement adv,
              PipeMsgListener listener)
        throws IOException
Constructor for the InputPipeImpl object

Parameters:
r - pipe resolver
adv - pipe advertisement
listener - listener to receive messages
Throws:
IOException - if an io error occurs
Method Detail

finalize

protected void finalize()
                 throws Throwable

Closes the pipe.

Overrides:
finalize in class Object
Throws:
Throwable

waitForMessage

public Message waitForMessage()
                       throws InterruptedException
Wait (block) for a message to be received.

Specified by:
waitForMessage in interface InputPipe
Returns:
a message or null if the pipe has been closed.
Throws:
InterruptedException - If another thread interrupted while we were waiting for a message.

poll

public Message poll(int timeout)
             throws InterruptedException
Poll for a message from the pipe. If there is no message immediately available then wait the specified amount of time for a message to arrive.

Specified by:
poll in interface InputPipe
Parameters:
timeout - Maximum number of milliseconds to wait (block) for a message to be received. If zero then wait indefinitely for a message.
Returns:
Message received or null if the pipe has closed or the timeout expired without a message being received.
Throws:
InterruptedException - If another thread interrupted while we were waiting for a message.

close

public void close()
Close the pipe. No additional messages will be received on this pipe.

Specified by:
close in interface InputPipe

processIncomingMessage

public void processIncomingMessage(Message msg,
                                   EndpointAddress srcAddr,
                                   EndpointAddress dstAddr)
This method is invoked by the EndpointService for each incoming message which is addressed to this listener.

Specified by:
processIncomingMessage in interface EndpointListener
Parameters:
msg - Incoming message
srcAddr - Endpoint Address of the source of the message.
dstAddr - Endpoint Address of the destination of the message.

getType

public String getType()
Gets the pipe type

Specified by:
getType in interface InputPipe
Returns:
The type

getPipeID

public ID getPipeID()
Gets the pipe id

Specified by:
getPipeID in interface InputPipe
Returns:
The type

getName

public String getName()
Gets the pipe name

Specified by:
getName in interface InputPipe
Returns:
The name

getAdvertisement

public PipeAdvertisement getAdvertisement()
Gets the pipe advertisement

Specified by:
getAdvertisement in interface InputPipe
Returns:
The advertisement

JXSE