use of org.osgi.framework.ServiceException in project aries by apache.
the class MethodCall method fireAndForget.
public Promise<Void> fireAndForget(Bundle clientBundle, ExecutorService executor, ScheduledExecutorService ses) {
PromiseImpl<Void> started = new PromiseImpl<Void>(executor, ses);
Object svc;
try {
svc = getService();
} catch (Exception e) {
logError("Unable to obtain the service object", e);
started.fail(e);
return started;
}
if (svc instanceof AsyncDelegate) {
try {
if (((AsyncDelegate) svc).execute(method, arguments)) {
releaseService();
started.resolve(null);
return started;
}
} catch (Exception e) {
releaseService();
logError("The AsyncDelegate rejected the fire-and-forget invocation with an exception", e);
started.fail(e);
return started;
}
}
// If we get here then svc is either not an async delegate, or it rejected the call
PromiseImpl<Void> cleanup = new PromiseImpl<Void>();
try {
executor.execute(new FireAndForgetWork(this, cleanup, started));
cleanup.onResolve(new Runnable() {
public void run() {
releaseService();
}
}).then(null, new Failure() {
public void fail(Promise<?> resolved) throws Exception {
logError("The fire-and-forget invocation failed", resolved.getFailure());
}
});
} catch (RejectedExecutionException ree) {
logError("The Async Service threadpool rejected the fire-and-forget invocation", ree);
started.fail(new ServiceException("Unable to enqueue the fire-and forget task", 7, ree));
}
return started;
}
Aggregations