Search in sources :

Example 16 with ServiceException

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;
}
Also used : AsyncDelegate(org.osgi.service.async.delegate.AsyncDelegate) ServiceException(org.osgi.framework.ServiceException) PromiseImpl(org.apache.aries.async.promise.PromiseImpl) ServiceException(org.osgi.framework.ServiceException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Failure(org.osgi.util.promise.Failure) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

ServiceException (org.osgi.framework.ServiceException)16 Organization (org.opencastproject.security.api.Organization)6 IOException (java.io.IOException)5 NotFoundException (org.opencastproject.util.NotFoundException)5 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 SeriesException (org.opencastproject.series.api.SeriesException)3 Effect0 (org.opencastproject.util.data.Effect0)3 File (java.io.File)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Properties (java.util.Properties)2 Context (javax.naming.Context)2 InitialContext (javax.naming.InitialContext)2 BundleMock (org.apache.aries.mocks.BundleMock)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 Test (org.junit.Test)2 AccessControlList (org.opencastproject.security.api.AccessControlList)2