Show TOC Start of Content Area

Background documentation Getting a LogicalLocking Instance  Locate the document in its SAP Library structure

You obtain a LogicalLocking instance from the Application Locking Service within a specific namespace in the following way:

...

       1.      Lookup the LogicalLockingFactory object using JNDI.

As the lookup parameter, use the predefined constant LogicalLockingFactory.JNDI_NAME. It holds the path under which the LogicalLockingFactory object is bound in the JNDI tree.

       2.      Call the createLogicalLocking() method on the LogicalLockingFactory object and supply the namespace and its description as method parameters.

Syntax

public LogicalLocking createLogicalLocking

    (java.lang.String namespace, java.lang.String description)

throws com.sap.engine.frame.core.locking.TechnicalLockException,

java.lang.IllegalArgumentException;

The name and description are arbitrary strings. The following restrictions apply:

      The namespace string cannot start with a letter or a digit

      The description string cannot be null

Example

The following code reserves a namespace for the given description. Applications can then lock objects within this namespace using the returned LogicalLocking instance.

import javax.naming.InitialContext;

import javax.naming.NamingException;

import com.sap.engine.frame.core.locking.TechnicalLockException;

import com.sap.engine.services.applocking.LogicalLocking;

import com.sap.engine.services.applocking.LogicalLockingFactory;

 

InitialContext ctx = new InitialContext();

try {

     LogicalLockingFactory lf =

        (LogicalLockingFactory) ctx.lookup(

           LogicalLockingFactory.JNDI_NAME);

 

     LogicalLocking logicalLocking =

        lf.createLogicalLocking("SAP/FM", "SAP Facility Management");

} catch (NamingException ne) {

  // JNDI lookup error

} catch (TechnicalLockException tle) {

  // the namespace is already reserved for another description

} catch (IllegalArgumentException iae) {

  // the namespace is already reserved for another description

}

 

Note

Application components share a namespace by reserving the namespace multiple times for the same description. An attempt to reserve the same namespace with another description causes an error returning an IlleagalArgumentException exception.

The LogicalLocking instance does not identify a user session or a user transaction. You can use the same LogicalLocking instance in different transactions or use different LogicalLocking instances in one transaction.

For more information about the LogicalLockingFactory interface, refer to the JavaDoc of the package com.sap.engine.services.applocking in the SAP NetWeaver Developer Studio help section.

End of Content Area