}
@Override
public final void registeredCallbacks (final Callbacks proxy, final CallbackIsolate isolate)
{
final FsmCallbackCompletionTransaction initializeSucceededCompletedTransaction = Cloudlet.this.fsm.new FsmCallbackCompletionTransaction (FsmTransition.CallbacksInitializeSucceededCompleted) {
@Override
protected final StateAndOutput<FsmState, Void> execute (final CallbackCompletion<Void> initializedCompletion)
{
Preconditions.checkState (Cloudlet.this.initializeFuture != null);
final Throwable exception = initializedCompletion.getException ();
StateAndOutput<FsmState, Void> result;
if (exception == null) {
Cloudlet.this.initializeFuture.trigger.triggerSucceeded (null);
Cloudlet.this.initializeFuture = null;
result = StateAndOutput.create (FsmState.Active, null);
} else {
Cloudlet.this.failures.traceDeferredException (exception);
Cloudlet.this.initializeFuture.trigger.triggerFailed (QueuedExceptions.create (Cloudlet.this.failures));
Cloudlet.this.initializeFuture = null;
Cloudlet.this.reactor.destroyProxy (Cloudlet.this.callbacksProxy);
result = StateAndOutput.create (FsmState.CallbacksUnregisterPending, null);
}
return result;
}
};
final FsmCallbackCompletionTransaction initializeFailedCompletedTransaction = Cloudlet.this.fsm.new FsmCallbackCompletionTransaction (FsmTransition.CallbacksInitializeFailedCompleted) {
@Override
protected final StateAndOutput<FsmState, Void> execute (final CallbackCompletion<Void> initializedCompletion)
{
Preconditions.checkState (Cloudlet.this.initializeFuture != null);
final Throwable exception = initializedCompletion.getException ();
if (exception != null) {
Cloudlet.this.failures.traceDeferredException (exception);
}
Cloudlet.this.initializeFuture.trigger.triggerFailed (QueuedExceptions.create (Cloudlet.this.failures));
Cloudlet.this.initializeFuture = null;
Cloudlet.this.reactor.destroyProxy (Cloudlet.this.callbacksProxy);
return StateAndOutput.create (FsmState.CallbacksUnregisterPending, null);
}
};
final FsmCallbackCompletionTransaction initializeCompletedTransaction = Cloudlet.this.fsm.new FsmCallbackCompletionTransaction (FsmTransition.CallbacksInitializeCompleted) {
@Override
protected final StateAndOutput<FsmState, Void> execute (final CallbackCompletion<Void> initializeCompletion)
{
final Throwable exception = initializeCompletion.getException ();
StateAndOutput<FsmState, Void> result;
if (exception == null) {
final CloudletCallbackCompletionArguments<TContext> arguments = new CloudletCallbackCompletionArguments<TContext> (Cloudlet.this.controllerProxy);
final CallbackCompletion<Void> initializedCompletion = Cloudlet.this.callbacksProxy.initializeSucceeded (Cloudlet.this.controllerContext, arguments);
initializeSucceededCompletedTransaction.observe (initializedCompletion);
result = StateAndOutput.create (FsmState.CallbacksInitializeSucceededPending, null);
} else {
Cloudlet.this.failures.traceDeferredException (exception);
final CloudletCallbackCompletionArguments<TContext> arguments = new CloudletCallbackCompletionArguments<TContext> (Cloudlet.this.controllerProxy, exception);
final CallbackCompletion<Void> initializedCompletion = Cloudlet.this.callbacksProxy.initializeFailed (Cloudlet.this.controllerContext, arguments);
initializeFailedCompletedTransaction.observe (initializedCompletion);
result = StateAndOutput.create (FsmState.CallbacksInitializeFailedPending, null);
}
return result;
}
};
Cloudlet.this.fsm.new FsmVoidTransaction (FsmTransition.CallbacksRegisterCompleted) {
@Override
public final StateAndOutput<FsmState, Void> execute ()
{
final CloudletCallbackArguments<TContext> arguments = new CloudletCallbackArguments<TContext> (Cloudlet.this.controllerProxy);
final CallbackCompletion<Void> completion = Cloudlet.this.callbacksProxy.initialize (Cloudlet.this.controllerContext, arguments);
initializeCompletedTransaction.observe (completion);
return StateAndOutput.create (FsmState.CallbacksInitializePending, null);
}
}.trigger ();
}