Locking feature for assembly line synchronization

As an option, you can synchronize assembly lines at the dispatcher level by using a locking mechanism.

The dispatcher provides a lock to the assembly lines, which must acquire the lock before running code that requires synchronization. The lock must be released after the code is run. Using the lock, assembly lines can achieve synchronization between assembly lines by acquiring and releasing the lock.

For example, an LDAP adapter can use assembly line synchronization after the following changes to schema.dsml and service.def files in the adapter profile:
Note: This example applies to the LDAP adapter. Similar changes must be made to other adapters.
  • schema.dsml
    You must change this file if you want to include the LockName attribute on the service form. For example:
    1. Attribute Definitions section
      <!-- ******************************************************** -->
      <!-- erLdapLockName                                           -->
      <!-- ******************************************************** -->
      <attribute-type single-value = "true" >       
      <name>erLdapLockName</name>       
      <description>Lock name for AL synchronization</description>       
      <object-identifier>1.3.6.1.4.1.6054.3.139.2.31</object-identifier>        
      <syntax>1.3.6.1.4.1.1466.115.121.1.15</syntax>       
      </attribute-type>
    2. RMI Service class section
      <attribute ref = "erLdapLockName" required = "false" />
  • service.def

    For each operation in the service.def file, add a dispatcher parameter. For example:

    <dispatcherParameter name="LockName" source= "erLdapLockName">
        <default>$(SO!erservicename)</default>
    </dispatcherParameter>

    The source attribute in the dispatcherParameter would be required only if the LockName value is taken from the service form. If the field is not on the service form, the default value is taken. The dispatcherParameter name must always be LockName.

    This example sets the default value of the lock name to be same as the service name. However, you can change its value based on your requirements.

    For example, you might provide it with a default name or add a field on the service form, where the lock name can be set and the default value points to that field. The dispatcher uses the value of the LockName dispatcher parameter to create the lock. The lock is created before the assembly line begins to run if a lock with the same name does not already exist.

To acquire and release the lock, you can add code similar to the following code snippet to any hook of your assembly line. However, do not add this in the PROLOG section when assembly line caching is enabled. The PROLOG section is not run again after the assembly line is in the cache.
var myALCfg = task.getConfigClone();     //Get AL config object.
var myALSettings = myALCfg.getSettings(); //Get AL settings object from AL config.
var LockName = myALSettingsgetStringParameter("LockName");
task.logmsg("Lock name is"+LockName);
var lock = java.lang.System.getProperties().get(LockName);
var timeout = 240; //The maximum time that AL should wait to acquire the lock.

if ( lock.tryLock(timeout, java.util.concurrent.TimeUnit.SECONDS) )
{
       /*
                  Critical Section
       */
 }
else
 {
      task.logmsg("Failed to acquire lock");
 }
The critical section is the interval from when the lock is acquired to the point when it is released. The lock can be released using the following:
if (lock!=null)
{
      lock.unlock(); //Releases the lock
}

You can add this specification in the same hook, or in any hook. However, you must release the lock at appropriate places, even in error paths if required. Not doing so can cause an IllegalMonitorStateException event.