@@ -0,0 +1,2172 @@
+%0Apackage eu.mosaic_cloud.tools.callbacks.tools;%0A%0A%0Aimport java.util.ArrayDeque;%0Aimport java.util.concurrent.Callable;%0A%0Aimport eu.mosaic_cloud.tools.callbacks.core.CallbackCompletion;%0Aimport eu.mosaic_cloud.tools.callbacks.core.CallbackCompletionObserver;%0A%0Aimport com.google.common.base.Preconditions;%0A%0A%0Apublic class CallbackCompletionWorkflows%0A%7B%0A%09public static final CallbackCompletion%3CVoid%3E executeSequence (final Callable%3CCallbackCompletion%3CVoid%3E%3E ... operations_)%0A%09%7B%0A%09%09Preconditions.checkNotNull (operations_);%0A%09%09final ArrayDeque%3CCallable%3CCallbackCompletion%3CVoid%3E%3E%3E operations = new ArrayDeque%3CCallable%3CCallbackCompletion%3CVoid%3E%3E%3E (operations_.length);%0A%09%09for (final Callable%3CCallbackCompletion%3CVoid%3E%3E operation : operations_) %7B%0A%09%09%09Preconditions.checkNotNull (operation);%0A%09%09%09operations.add (operation);%0A%09%09%7D%0A%09%09final CallbackCompletionDeferredFuture%3CVoid%3E future = CallbackCompletionDeferredFuture.create (Void.class);%0A%09%09final Runnable chainer = new Runnable () %7B%0A%09%09%09@Override%0A%09%09%09public void run ()%0A%09%09%09%7B%0A%09%09%09%09final Runnable chainer = this;%0A%09%09%09%09if (operations.isEmpty ()) %7B%0A%09%09%09%09%09future.trigger.triggerSucceeded (null);%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%09%09%09%09final CallbackCompletion%3CVoid%3E completion;%0A%09%09%09%09try %7B%0A%09%09%09%09%09final Callable%3CCallbackCompletion%3CVoid%3E%3E operation = operations.removeFirst ();%0A%09%09%09%09%09completion = operation.call ();%0A%09%09%09%09%7D catch (final Throwable exception) %7B%0A%09%09%09%09%09// FIXME: log...%0A%09%09%09%09%09future.trigger.triggerFailed (exception);%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%09%09%09%09if (completion.isCompleted ()) %7B%0A%09%09%09%09%09final Throwable exception = completion.getException ();%0A%09%09%09%09%09if (exception != null) %7B%0A%09%09%09%09%09%09future.trigger.triggerFailed (exception);%0A%09%09%09%09%09%09return;%0A%09%09%09%09%09%7D else%0A%09%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%09%09%09%09completion.observe (new CallbackCompletionObserver () %7B%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public CallbackCompletion%3CVoid%3E completed (final CallbackCompletion%3C?%3E completion_)%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09Preconditions.checkArgument (completion_ == completion);%0A%09%09%09%09%09%09final Throwable exception = completion.getException ();%0A%09%09%09%09%09%09if (exception != null)%0A%09%09%09%09%09%09%09future.trigger.triggerFailed (exception);%0A%09%09%09%09%09%09else%0A%09%09%09%09%09%09%09chainer.run ();%0A%09%09%09%09%09%09return (null);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D);%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09chainer.run ();%0A%09%09return (future.completion);%0A%09%7D%0A%7D%0A

Implement simple callback completion based workflows (currently only "sequence")