JXTA

net.jxta.impl.resolver
Class ResolverServiceInterface

java.lang.Object
  extended by net.jxta.impl.resolver.ResolverServiceInterface
All Implemented Interfaces:
Module, GenericResolver, ResolverService, Service

public class ResolverServiceInterface
extends Object
implements ResolverService

Provides a controlled interface to the Resolver Service.


Field Summary
 
Fields inherited from interface net.jxta.resolver.ResolverService
OK, Repropagate
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
ResolverServiceInterface(ResolverServiceImpl theRealThing)
          Only authorized constructor
 
Method Summary
 ModuleImplAdvertisement getImplAdvertisement()
          Returns the advertisement for this service.
 ResolverService getInterface()
          Service objects are not manipulated directly to protect usage of the service.
 void init(PeerGroup g, ID assignedID, Advertisement impl)
          Initialize the module, passing it its peer group and advertisement.
 QueryHandler registerHandler(String name, QueryHandler handler)
          Registers a given QueryHandler, returns the previous handler registered under this name.
 SrdiHandler registerSrdiHandler(String name, SrdiHandler handler)
          Registers a given SrdiHandler, returns the previous handler registered under this name.
 void sendQuery(String rdvPeer, ResolverQueryMsg query)
          Sends a resolver query.
 void sendResponse(String destPeer, ResolverResponseMsg response)
          Send a resolver response.
 void sendSrdi(String destPeer, ResolverSrdiMsg srdi)
          Send an SRDI message.
 int startApp(String[] arg)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
 QueryHandler unregisterHandler(String name)
          Unregisters a given QueryHandler, returns the previous handler registered under this name.
 SrdiHandler unregisterSrdiHandler(String name)
          Unregisters a given SrdiHandler, returns the previous handler registered under this name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResolverServiceInterface

ResolverServiceInterface(ResolverServiceImpl theRealThing)
Only authorized constructor

Parameters:
theRealThing - reference to the impl
Method Detail

getInterface

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

Since THIS is already such an object, it returns itself. FIXME: it is kind of absurd to have this method part of the interface but we do not want to define two levels of Service interface just for that.

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

init

public void init(PeerGroup g,
                 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.

FIXME: This is meaningless for the interface object; it is there only to satisfy the requirements of the interface that we implement. Ultimately, the API should define two levels of interfaces: one for the real service implementation and one for the interface object. Right now it feels a bit heavy to so that since the only different between the two would be init() and may-be getName().

Specified by:
init in interface Module
Parameters:
g - 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[] arg)
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.

Does nothing in the interface object.

Specified by:
startApp in interface Module
Parameters:
arg - 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.

Does nothing in the interface object.

Specified by:
stopApp in interface Module

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.

registerHandler

public QueryHandler registerHandler(String name,
                                    QueryHandler handler)
Registers a given QueryHandler, returns the previous handler registered under this name.

Specified by:
registerHandler in interface ResolverService
Parameters:
name - The name under which this handler is to be registered.
handler - The handler.
Returns:
The previous handler registered under this name.

unregisterHandler

public QueryHandler unregisterHandler(String name)
Unregisters a given QueryHandler, returns the previous handler registered under this name.

Specified by:
unregisterHandler in interface ResolverService
Parameters:
name - The name of the handler to unregister.
Returns:
The previous handler registered under this name.

registerSrdiHandler

public SrdiHandler registerSrdiHandler(String name,
                                       SrdiHandler handler)
Registers a given SrdiHandler, returns the previous handler registered under this name.

Specified by:
registerSrdiHandler in interface ResolverService
Parameters:
name - The name under which this handler is to be registered.
handler - The handler.
Returns:
The previous handler registered under this name.

unregisterSrdiHandler

public SrdiHandler unregisterSrdiHandler(String name)
Unregisters a given SrdiHandler, returns the previous handler registered under this name.

Specified by:
unregisterSrdiHandler in interface ResolverService
Parameters:
name - The name of the handler to unregister.
Returns:
The previous handler registered under this name

sendQuery

public void sendQuery(String rdvPeer,
                      ResolverQueryMsg query)
Sends a resolver query. If destPeer is null the message is propagated.

Specified by:
sendQuery in interface ResolverService
Parameters:
rdvPeer - The destination peer of the query or null if the query is to be propagated.
query - The query to match.

sendResponse

public void sendResponse(String destPeer,
                         ResolverResponseMsg response)
Send a resolver response. If destPeer is null then the response is propagated. Propagated responses are generally announcements and not responses to active queries.

Specified by:
sendResponse in interface ResolverService
Parameters:
destPeer - The destination peer of the response or null if the response is to be propagated.
response - The response to be sent.

sendSrdi

public void sendSrdi(String destPeer,
                     ResolverSrdiMsg srdi)
Send an SRDI message.

If destPeer is null the message is walked.

Specified by:
sendSrdi in interface ResolverService
Parameters:
destPeer - is the destination of the SRDI message.
srdi - is the SRDI message to be sent.

JXSE