com.ibm.wsspi.runtime.service
Class WsServiceRegistry

java.lang.Object
  extended by com.ibm.wsspi.runtime.service.WsServiceRegistry

public final class WsServiceRegistry
extends java.lang.Object

A meta-service that provides methods for WebSphere components to register services and locate services.

In order to use this registry, clients must be exeucting in a bundle and that bundle must register with the registry (see registerBundleContext).

Examples

Registering as a Service
Suppose you have a service interface and an implementation of that interface which you wish to register:

public interface MyServiceIF {...}

public class MyServiceImpl implements MyServiceIF {...}

The service can be registered via the following pattern:

MyServiceImpl impl = ...;
WsServiceRegistry.addService(impl, MyServiceIF.class);

Locating a Registered Service

Given the service registered in the previous example, code elsewhere in the server can access that service via the following pattern:

MyServiceImpl service = (MyServiceImpl)WsServiceRegistry.getService(this,MyServiceImpl.class);
service.foo();


Constructor Summary
WsServiceRegistry()
           
 
Method Summary
static java.lang.Object addService(java.lang.Object serviceImplementation, java.lang.Class serviceInterface)
          Registers a service (implementation) via the given service interface.
static java.lang.Object getService(java.lang.Object requestor, java.lang.Class serviceInterface)
          Returns the service that registered with the specified service class.
static void registerBundleContext(org.osgi.framework.BundleActivator activator, org.osgi.framework.BundleContext context)
          Registers BundleContext object with this meta-service.
static void unregisterBundleContext(org.osgi.framework.BundleActivator activator, org.osgi.framework.BundleContext context)
          Unregisters BundleContext object with this meta-service.
static void unregisterService(java.lang.Object token)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WsServiceRegistry

public WsServiceRegistry()
Method Detail

addService

public static java.lang.Object addService(java.lang.Object serviceImplementation,
                                          java.lang.Class serviceInterface)
                                   throws java.lang.Exception
Registers a service (implementation) via the given service interface. name.

Parameters:
serviceImplementation - The implementation of the service that is being registered.
serviceInterface - The interface of the service that is being registered. The serviceImplementation must implement this interface.
Returns:
Object A token that may be used to unregister the service.
Throws:
java.lang.Exception - When registration fails.

unregisterService

public static void unregisterService(java.lang.Object token)

getService

public static java.lang.Object getService(java.lang.Object requestor,
                                          java.lang.Class serviceInterface)
                                   throws java.lang.Exception
Returns the service that registered with the specified service class.

Parameters:
requestor - Component requesting access to service (typically this).
serviceInterface - Interface class for the service registered.
Returns:
Reference to the service implementation.
Throws:
java.lang.Exception - thrown if service could not be obtained.

registerBundleContext

public static void registerBundleContext(org.osgi.framework.BundleActivator activator,
                                         org.osgi.framework.BundleContext context)
                                  throws java.lang.Exception
Registers BundleContext object with this meta-service. This method must be invoked from each bundle which wants to use the registry.

Parameters:
context - BundleContext to register
Throws:
java.lang.IllegalArgumentException - if parameters are illegal
java.lang.Exception - if the bundle context had already been registered

unregisterBundleContext

public static void unregisterBundleContext(org.osgi.framework.BundleActivator activator,
                                           org.osgi.framework.BundleContext context)
                                    throws java.lang.Exception
Unregisters BundleContext object with this meta-service.

Parameters:
context -
Throws:
java.lang.Exception