Entering content frame

Function documentation Lookup of SAP J2EE Engine Services Locate the document in its SAP Library structure

Use

At JNDI Registry Service startup, the names of all services are obtained from the SystemMonitor.

These names are bound in the root context of the naming system with the corresponding objects that keep information about the service/interface, and provide a way of getting an interface instance of the service/interface.

Each service in the J2EE Engine can make its interface available for lookup from the naming system, as long as it registers a new instance of the service interface implementation in the ObjectRegistry.

Example

// Creating an instance of the implementation of the service interface

AnyServiceImpl serviceImpl = new AnyServiceImpl();

 

// Registering this object in the registry

serviceContext.getContainerContext().getObjectRegistry().
registerInterface(serviceImpl);

 

Once the service registers its interface in the ObjectRegistry, it becomes available for lookup. Services are looked up from the root context of the naming system.

When a client gets the root context and tries to lookup any service name in the ClientContext, the object returned from the server is checked to see if it is an instance of a RemoteServiceReference. If it is an instance, the getServiceInterface() method is called. It returns an object representing a service interface (if this has been put in the registry), or null (if the service has not registered its interface yet, or if the interface is not remote and the client is not running on the server). If the provided service interface implementation is a remote one (extends PortableRemoteObject, UnicastRemoteObject, or implements Remote), it will return a stub connected to this implementation during a lookup from any client.

Example

// Get root context

Context ctx = new InitialContext();

 

// Lookup the service name

AnyService anyService = (AnyService) (ctx.lookup("serviceName"));

 

Note

AnyServiceImpl implements the AnyServiceinterface.

If the client is an application running on a server from which it wants to look up a service, the InitialContext must be created with property “domain” with the value “ true”, because by default it gets an offset context (not the root context of the JNDI Registry Service namespace).

 

 

Leaving content frame