conf.put(BasicLockProvider.KEY_DIRECTORY, folder.getRoot().getAbsolutePath());
conf.put(ExecutionLockProvider.KEY_SCOPE, ExecutionLock.Scope.EXECUTION.getSymbol());
ServiceProfile<ExecutionLockProvider> profile = new ServiceProfile<ExecutionLockProvider>(
"testing", BasicLockProvider.class, conf, ProfileContext.system(getClass().getClassLoader()));
ExecutionLockProvider instance1 = profile.newInstance();
ExecutionLockProvider instance2 = profile.newInstance();
ExecutionLock lock = instance1.newInstance("batch1");
try {
lock.beginFlow("flow1", "exec1");
ExecutionLock other = instance2.newInstance("batch1");
try {
// can acquire other flow lock
other.beginFlow("flow2", "exec1");
other.endFlow("flow2", "exec1");
other.beginFlow("flow2", "exec2");
other.endFlow("flow2", "exec2");
// can acquire other execution lock
other.beginFlow("flow1", "exec2");
other.endFlow("flow1", "exec2");
try {
other.beginFlow("flow1", "exec1");
fail("cannot run same execution");
} catch (IOException e) {
// ok.
}
} finally {
other.close();
}
other = instance2.newInstance("batch2");
try {
// can acquire any flow lock if batch is different
other.beginFlow("flow1", "exec1");
} finally {
other.close();