JXTA

net.jxta.impl.pipe
Class PipeServiceImpl

java.lang.Object
  extended by net.jxta.impl.pipe.PipeServiceImpl
All Implemented Interfaces:
EventListener, PipeResolver.Listener, PipeService, Module, Service

public class PipeServiceImpl
extends Object
implements PipeService, PipeResolver.Listener

A JXTA PipeService implementation which implements the standard JXTA Pipe Resolver Protocol (PRP).

This class provides implementation for Unicast, unicast secure and (indirectly) propagate pipes.

See Also:
PipeService, InputPipe, OutputPipe, Message, PipeAdvertisement, PipeResolverMessage, JXTA Protocols Specification : Pipe Binding Protocol

Field Summary
(package private) static long VERIFYINTERVAL
          the interval at which we verify that a pipe is still resolved at a remote peer.
 
Fields inherited from interface net.jxta.pipe.PipeService
PropagateType, UnicastSecureType, UnicastType
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
PipeServiceImpl()
          Default Constructor (don't delete)
 
Method Summary
 InputPipe createInputPipe(PipeAdvertisement adv)
          Create an InputPipe from a pipe Advertisement
 InputPipe createInputPipe(PipeAdvertisement adv, PipeMsgListener listener)
          Create an InputPipe from a pipe Advertisement
 OutputPipe createOutputPipe(PipeAdvertisement pipeAdv, long timeout)
          Attempt to create an OutputPipe using the specified Pipe Advertisement.
 void createOutputPipe(PipeAdvertisement pipeAdv, OutputPipeListener listener)
          Attempt to create an OutputPipe using the specified Pipe Advertisement.
 OutputPipe createOutputPipe(PipeAdvertisement adv, Set<? extends ID> resolvablePeers, long timeout)
          Attempt to create an OutputPipe using the specified Pipe Advertisement.
 void createOutputPipe(PipeAdvertisement pipeAdv, Set<? extends ID> resolvablePeers, OutputPipeListener listener)
          Attempt to create an OutputPipe using the specified Pipe Advertisement.
 ModuleImplAdvertisement getImplAdvertisement()
          Returns the advertisement for this service.
 PipeService getInterface()
          Service objects are not manipulated directly to protect usage of the service.
 void init(PeerGroup group, ID assignedID, Advertisement impl)
          Initialize the module, passing it its peer group and advertisement.
 boolean pipeNAKEvent(PipeResolver.Event event)
          A NAK Event was received for this pipe
 boolean pipeResolveEvent(PipeResolver.Event event)
          Pipe Resolve event
 OutputPipeListener removeOutputPipeListener(ID pipeID, OutputPipeListener listener)
          Remove an OutputPipeListener previously registered with createOuputputPipe.
 OutputPipeListener removeOutputPipeListener(String pipeID, OutputPipeListener listener)
          Remove an OutputPipeListener previously registered with createOuputputPipe.
 int startApp(String[] args)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERIFYINTERVAL

static final long VERIFYINTERVAL
the interval at which we verify that a pipe is still resolved at a remote peer.

See Also:
Constant Field Values
Constructor Detail

PipeServiceImpl

public PipeServiceImpl()
Default Constructor (don't delete)

Method Detail

getInterface

public PipeService getInterface()
Service objects are not manipulated directly to protect usage of the service. A Service interface is returned to access the service methods.

We create only a single interface object and return it over and over again.

Specified by:
getInterface in interface Service
Returns:
Service public interface of the service

getImplAdvertisement

public ModuleImplAdvertisement getImplAdvertisement()
Returns the advertisement for this service.

Specified by:
getImplAdvertisement in interface Service
Returns:
Advertisement the advertisement. This is always a ModuleImplAdvertisement.

init

public void init(PeerGroup group,
                 ID assignedID,
                 Advertisement impl)
Initialize the module, passing it its peer group and advertisement.

Note: when subclassing one of the existing PeerGroup implementations (which implement Module), it may not be recommended to overload the init method. See the documentation of the PeerGroup class being subclassed.

Specified by:
init in interface Module
Parameters:
group - The PeerGroup from which this Module can obtain services. If this module is a Service, this is also the PeerGroup of which this module is a service.
assignedID - Identity of Module within group. modules can use it as a the root of their namespace to create names that are unique within the group but predictable by the same module on another peer. This is normally the ModuleClassID which is also the name under which the module is known by other modules. For a group it is the PeerGroupID itself. The parameters of a service, in the Peer configuration, are indexed by the assignedID of that service, and a Service must publish its run-time parameters in the Peer Advertisement under its assigned ID.
impl - The implementation advertisement for this Module. It is permissible to pass null if no implementation advertisement is available. This may happen if the implementation was selected by explicit class name rather than by following an implementation advertisement. Modules are not required to support that style of loading, but if they do, then their documentation should mention it.

startApp

public int startApp(String[] args)
Complete any remaining initialization of the module. The module should be fully functional after startApp() is completed. That is also the opportunity to supply arbitrary arguments (mostly to applications).

If this module is a PeerGroup service, it may be invoked several times depending on its return value.

Currently this service does not expect arguments.

Specified by:
startApp in interface Module
Parameters:
args - An array of Strings forming the parameters for this Module.
Returns:
int A status indication which may be one of Module.START_OK, Module.START_AGAIN_PROGRESS, Module.START_AGAIN_STALLED, which indicates partial or complete success, or any other value (negative values are recommended for future compatibility), which indicates failure.

stopApp

public void stopApp()
Stop a module. This may be called any time after init() completes and should not assume that startApp() has been called or completed.

The Module cannot be forced to comply, but in the future we might be able to deny it access to anything after some timeout.

Specified by:
stopApp in interface Module

createInputPipe

public InputPipe createInputPipe(PipeAdvertisement adv)
                          throws IOException
Create an InputPipe from a pipe Advertisement

Specified by:
createInputPipe in interface PipeService
Parameters:
adv - The advertisement of the Pipe.
Returns:
The InputPipe created.
Throws:
IOException - error creating input pipe

createInputPipe

public InputPipe createInputPipe(PipeAdvertisement adv,
                                 PipeMsgListener listener)
                          throws IOException
Create an InputPipe from a pipe Advertisement

Specified by:
createInputPipe in interface PipeService
Parameters:
adv - is the advertisement of the Pipe.
listener - PipeMsgListener to receive msgs.
Returns:
InputPipe The InputPipe created.
Throws:
IOException - Error creating input pipe

createOutputPipe

public OutputPipe createOutputPipe(PipeAdvertisement pipeAdv,
                                   long timeout)
                            throws IOException
Attempt to create an OutputPipe using the specified Pipe Advertisement. The pipe will be be resolved within the provided timeout.

Specified by:
createOutputPipe in interface PipeService
Parameters:
pipeAdv - The advertisement of the pipe being resolved.
timeout - Time duration in milliseconds to wait for a successful pipe resolution. 0 will wait indefinitely.
Returns:
OutputPipe the successfully resolved OutputPipe.
Throws:
IOException - If the pipe cannot be created or failed to resolve within the specified time.

createOutputPipe

public OutputPipe createOutputPipe(PipeAdvertisement adv,
                                   Set<? extends ID> resolvablePeers,
                                   long timeout)
                            throws IOException
Attempt to create an OutputPipe using the specified Pipe Advertisement. The pipe will be be resolved to one of the peers in the set of peer ids provided within the provided timeout.

Specified by:
createOutputPipe in interface PipeService
Parameters:
adv - The advertisement of the pipe being resolved.
resolvablePeers - The peers on which the pipe may be resolved. If the Set is empty then the pipe may be resolved to any destination peer.
timeout - Time duration in milliseconds to wait for a successful pipe resolution. 0 will wait indefinitely.
Returns:
The successfully resolved OutputPipe.
Throws:
IOException - If the pipe cannot be created or failed to resolve within the specified time.

createOutputPipe

public void createOutputPipe(PipeAdvertisement pipeAdv,
                             OutputPipeListener listener)
                      throws IOException
Attempt to create an OutputPipe using the specified Pipe Advertisement. The pipe may be resolved to any destination peer. When the pipe is resolved the listener will be called.

Specified by:
createOutputPipe in interface PipeService
Parameters:
pipeAdv - The advertisement of the pipe being resolved.
listener - The listener to be called when the pipe is resolved.
Throws:
IOException - If the pipe cannot be created.

createOutputPipe

public void createOutputPipe(PipeAdvertisement pipeAdv,
                             Set<? extends ID> resolvablePeers,
                             OutputPipeListener listener)
                      throws IOException
Attempt to create an OutputPipe using the specified Pipe Advertisement. When the pipe is resolved to one of the peers in the set of peer ids provided the listener will be called.

Specified by:
createOutputPipe in interface PipeService
Parameters:
pipeAdv - The advertisement of the pipe being resolved.
resolvablePeers - The set of peers on which the pipe may be resolved. If the Set is empty then the pipe may be resolved to any destination peer.
listener - the listener to be called when the pipe is resolved.
Throws:
IOException - If the pipe cannot be created.

removeOutputPipeListener

public OutputPipeListener removeOutputPipeListener(String pipeID,
                                                   OutputPipeListener listener)
Remove an OutputPipeListener previously registered with createOuputputPipe.

Specified by:
removeOutputPipeListener in interface PipeService
Parameters:
pipeID - The pipe who's listener is to be removed.
listener - The listener to remove.
Returns:
The listener which was removed or null if the key did not have a mapping.

removeOutputPipeListener

public OutputPipeListener removeOutputPipeListener(ID pipeID,
                                                   OutputPipeListener listener)
Remove an OutputPipeListener previously registered with createOuputputPipe.

Specified by:
removeOutputPipeListener in interface PipeService
Parameters:
pipeID - The pipe who's listener is to be removed.
listener - The listener to remove.
Returns:
The listener which was removed or null if the key did not have a mapping.

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

pipeNAKEvent

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

We don't do anything with NAKs (yet)

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

JXSE