Here we will have a look at the Locking System. We will learn how to lock and unlock objects using locks. Locks are used to make sure objects are only used by one owner.
There are three phases to locking: locking, checking and unlocking.
We will now create a lock:
Name |
Type |
Section |
Use |
|
String |
IN |
Any string |
|
String |
IN |
Any string |
LockingSystem.lockAndWait(object ,owner);
Test
and as owner or any other string such as Goofy
.We will now check if an object is locked:
Name |
Type |
Section |
Use |
|
String |
IN |
Any string |
|
String |
IN |
Any string |
|
Boolean |
OUT |
True if a new lock should be acquired |
newLock=LockingSystem.lock(object ,owner);
We will now unlock a locked object:
Name |
Type |
Section |
Use |
|
String |
IN |
Any string |
|
String |
IN |
Any string |
LockingSystem.unlock(object ,owner);
Orchestrator has an internal locking mechanism. It enables you to lock a virtual object, basically, a string. You set a lock with LockingSystem.lock(object, owner)
. Using the LockingSystem.lockAndWait(object, owner)
method with the same object
string will pause the workflow until the object
is unlocked with LockingSystem.unlock(object, owner)
.
Please note that the object isn't really locked; only a lock entry is set. The lock is just a flag and nothing else. If you want to use the Locking System, you will need to check for the locking entry. You can check all locking entries with LockingSystem.retrieveAll()
, which returns an array of strings where each string represents object,owner
. You can release all locks with LockingSystem.unlockAll()
. In the example packages, there are three examples of how to use the Locking System.
Have a look at the example workflows 08.02.4 Locktest (RUN ME)
and 08.02.5 secondary locker
, which show how the locking works.
A very important point to note here is that you have to make sure your workflow handles errors (in the workflow) well. You could end up in a situation where you lock a resource and the workflow locking it terminates on error and does not release the log. Have a look at Try-catch-finally in the recipe JavaScript special statements in Chapter 6, Advanced Programming.
For locking elements in the Orchestrator Client, see the recipe Locking elements in Chapter 4, Programming Skills.
The following are some example workflows:
08.02.1 Lock
08.02.2 Check for Lock
08.02.3 unlock
08.02.4 Locktest (RUN ME)
08.02.5 secondary locker