JXTA

net.jxta.impl.pipe
Class WirePipe

java.lang.Object
  extended by net.jxta.impl.pipe.WirePipe
All Implemented Interfaces:
EndpointListener, PipeRegistrar, InputPipe

public class WirePipe
extends Object
implements EndpointListener, InputPipe, PipeRegistrar

WirePipe (aka Propagated pipe) is very similar to IGMP, where a creation of an input pipe results in a propagated pipe membership registration with the peer's rendezvous peer, and a closure results in a propagated pipe group resignation, these group registration/resignation are simply PipeService SRDI messages.


Field Summary
(package private)  int messagesReceived
           
 
Constructor Summary
WirePipe(PeerGroup group, PipeResolver pipeResolver, WirePipeImpl wireService, PipeAdvertisement adv)
          Constructor
 
Method Summary
 void close()
          Close the pipe.
(package private) static String createMsgId()
          Create a unique (mostly) identifier for this message
protected  void finalize()
          

Closes the pipe.

 boolean forget(InputPipe wireinputpipe)
          This peer is no longer listening on the specified 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 message, EndpointAddress srcAddr, EndpointAddress dstAddr)
          This method is invoked by the EndpointService for each incoming message which is addressed to this listener.
(package private)  void processIncomingMessage(Message message, WireHeader header, EndpointAddress srcAddr, EndpointAddress dstAddr)
          local version with the wire header already parsed.
 boolean register(InputPipe wireinputpipe)
          Register that this peer is an InputPipe for the specified Pipe ID.
(package private)  void repropagate(Message message, WireHeader header)
          Repropagate a message.
(package private)  void sendMessage(Message message, Set<? extends ID> peers, WireHeader header)
          Sends a message on the propagated pipe.
 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

messagesReceived

int messagesReceived
Constructor Detail

WirePipe

public WirePipe(PeerGroup group,
                PipeResolver pipeResolver,
                WirePipeImpl wireService,
                PipeAdvertisement adv)
Constructor

Parameters:
group - The Group associated with this service
pipeResolver - the associated pipe resolver
wireService - The pipe service associated with this pipe
adv - pipe advertisement
Method Detail

finalize

protected void finalize()
                 throws Throwable

Closes the pipe.

Overrides:
finalize in class Object
Throws:
Throwable

register

public boolean register(InputPipe wireinputpipe)
Register that this peer is an InputPipe for the specified Pipe ID.

Specified by:
register in interface PipeRegistrar
Parameters:
wireinputpipe - The InputPipe to be registered.
Returns:
If true then the pipe was registered, otherwise false.

forget

public boolean forget(InputPipe wireinputpipe)
This peer is no longer listening on the specified pipe.

Specified by:
forget in interface PipeRegistrar
Parameters:
wireinputpipe - The InputPipe to be forgotten.
Returns:
true if the pipe was removed otherwise false.

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

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

processIncomingMessage

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

Handler for messages received through the normal pipe endpoint listener.

"PipeService" / <PipeID>

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

processIncomingMessage

void processIncomingMessage(Message message,
                            WireHeader header,
                            EndpointAddress srcAddr,
                            EndpointAddress dstAddr)
local version with the wire header already parsed. There are two paths to this point; via the local endpoint listener or via the general propagation listener in WirePipeImpl.

Parameters:
message - the message
header - the wire header
srcAddr - source
dstAddr - destination

repropagate

void repropagate(Message message,
                 WireHeader header)
Repropagate a message.

Parameters:
message - the message
header - the header

sendMessage

void sendMessage(Message message,
                 Set<? extends ID> peers,
                 WireHeader header)
           throws IOException
Sends a message on the propagated pipe. if set is not empty, then the message is sent to set of peers.

Parameters:
message - The message to send.
peers - The peers to which the message will be sent. If the set is empty then the message is sent to all members of the pipe that are connected to the rendezvous, as well as walk the message through the network
header - message header
Throws:
IOException - if an io error occurs

createMsgId

static String createMsgId()
Create a unique (mostly) identifier for this message

Returns:
a message sequence uuid

JXSE