Search in sources :

Example 16 with Coordination

use of org.osgi.service.coordinator.Coordination in project felix by apache.

the class CoordinatorImplTest method test_createCoordination.

public void test_createCoordination() {
    final String name = "test";
    final Coordination c1 = coordinator.create(name, 0);
    assertNotNull(c1);
    assertEquals(name, c1.getName());
    assertNull(coordinator.peek());
    assertNull(c1.getFailure());
    assertFalse(c1.isTerminated());
    assertTrue(c1.getParticipants().isEmpty());
    Exception cause = new Exception();
    assertTrue(c1.fail(cause));
    assertSame(cause, c1.getFailure());
    assertTrue(c1.isTerminated());
    assertNull(coordinator.peek());
    assertFalse(c1.fail(new Exception()));
    try {
        c1.end();
        fail("Expected CoordinationException.FAILED on end() after fail()");
    } catch (CoordinationException ce) {
        // expected failed
        assertEquals(CoordinationException.FAILED, ce.getType());
    }
    final Coordination c2 = coordinator.create(name, 0);
    assertNotNull(c2);
    assertEquals(name, c2.getName());
    assertNull(coordinator.peek());
    assertNull(c2.getFailure());
    assertFalse(c2.isTerminated());
    assertTrue(c2.getParticipants().isEmpty());
    c2.end();
    assertNull(c2.getFailure());
    assertTrue(c2.isTerminated());
    assertNull(coordinator.peek());
    assertFalse(c2.fail(new Exception()));
    try {
        c2.end();
        fail("Expected CoordinationException.ALREADY_ENDED on second end()");
    } catch (CoordinationException ce) {
        // expected already terminated
        assertEquals(CoordinationException.ALREADY_ENDED, ce.getType());
    }
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 17 with Coordination

use of org.osgi.service.coordinator.Coordination in project felix by apache.

the class CoordinatorImplTest method test_Coordination_timeout.

public void test_Coordination_timeout() throws InterruptedException {
    final String name = "test";
    final Coordination c1 = coordinator.create(name, 200);
    final MockParticipant p1 = new MockParticipant();
    c1.addParticipant(p1);
    assertTrue(c1.getParticipants().contains(p1));
    assertEquals(1, c1.getParticipants().size());
    // wait for the coordination to time out
    Thread.sleep(250);
    // expect coordination to have terminated
    assertTrue(c1.isTerminated());
    assertSame(Coordination.TIMEOUT, c1.getFailure());
    // expect Participant.failed() being called
    assertTrue(p1.failed);
    assertEquals(c1, p1.c);
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 18 with Coordination

use of org.osgi.service.coordinator.Coordination in project felix by apache.

the class CoordinatorUtil method addToCoordination.

public static boolean addToCoordination(final Object srv, final UpdateThread thread, final Runnable task) {
    final Coordinator coordinator = (Coordinator) srv;
    Coordination c = coordinator.peek();
    if (c != null) {
        Notifier n = null;
        for (final Participant p : c.getParticipants()) {
            if (p instanceof Notifier) {
                n = (Notifier) p;
                break;
            }
        }
        if (n == null) {
            n = new Notifier(thread);
            c.addParticipant(n);
        }
        n.add(task);
        return true;
    }
    return false;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) Participant(org.osgi.service.coordinator.Participant) Coordinator(org.osgi.service.coordinator.Coordinator)

Example 19 with Coordination

use of org.osgi.service.coordinator.Coordination in project tesb-rt-se by Talend.

the class CoordinationInterceptor method handleMessage.

@Override
public void handleMessage(org.apache.cxf.message.Message message) throws Fault {
    Coordination coordination = coordinator.begin("cxf", 10000);
    message.getExchange().put(Coordination.class, coordination);
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 20 with Coordination

use of org.osgi.service.coordinator.Coordination in project bndtools by bndtools.

the class ResolveOperation method run.

@Override
public void run(IProgressMonitor monitor) {
    MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);
    // Start a coordination
    BundleContext bc = Plugin.getDefault().getBundleContext();
    ServiceReference<Coordinator> coordSvcRef = bc.getServiceReference(Coordinator.class);
    Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
    Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;
    // Begin resolve
    try (ResolverLogger logger = new ResolverLogger()) {
        try {
            ResolveProcess resolve = new ResolveProcess();
            BndResolver bndResolver = new BndResolver(logger);
            ReporterLogService log = new ReporterLogService(model.getWorkspace());
            Map<Resource, List<Wire>> wirings = resolve.resolveRequired(model, model.getWorkspace(), bndResolver, callbacks, log);
            Map<Resource, List<Wire>> optionalResources = new HashMap<Resource, List<Wire>>(resolve.getOptionalResources().size());
            for (Resource optional : resolve.getOptionalResources()) {
                optionalResources.put(optional, new ArrayList<Wire>(resolve.getOptionalReasons(optional)));
            }
            result = new ResolutionResult(Outcome.Resolved, wirings, optionalResources, null, status, logger.getLog());
            if (coordination != null)
                coordination.end();
        } catch (ResolveCancelledException e) {
            result = new ResolutionResult(Outcome.Cancelled, null, null, null, status, logger.getLog());
            if (coordination != null)
                coordination.fail(e);
        } catch (ResolutionException e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
            result = new ResolutionResult(Outcome.Unresolved, null, null, e, status, logger.getLog());
            if (coordination != null)
                coordination.fail(e);
        } catch (Exception e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
            result = new ResolutionResult(Outcome.Error, null, null, null, status, logger.getLog());
            if (coordination != null)
                coordination.fail(e);
        } finally {
            if (coordinator != null)
                bc.ungetService(coordSvcRef);
        }
    }
}
Also used : ReporterLogService(aQute.bnd.deployer.repository.ReporterLogService) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Coordination(org.osgi.service.coordinator.Coordination) ResolverLogger(biz.aQute.resolve.ResolverLogger) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) MultiStatus(org.eclipse.core.runtime.MultiStatus) Coordinator(org.osgi.service.coordinator.Coordinator) Wire(org.osgi.resource.Wire) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Coordination (org.osgi.service.coordinator.Coordination)30 CoordinationException (org.osgi.service.coordinator.CoordinationException)11 Participant (org.osgi.service.coordinator.Participant)7 SubsystemException (org.osgi.service.subsystem.SubsystemException)7 IOException (java.io.IOException)5 BundleException (org.osgi.framework.BundleException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 Coordinator (org.osgi.service.coordinator.Coordinator)4 ArrayList (java.util.ArrayList)3 Resource (org.osgi.resource.Resource)3 ResolutionException (org.osgi.service.resolver.ResolutionException)2 ReporterLogService (aQute.bnd.deployer.repository.ReporterLogService)1 BndResolver (biz.aQute.resolve.BndResolver)1 ResolveProcess (biz.aQute.resolve.ResolveProcess)1 ResolverLogger (biz.aQute.resolve.ResolverLogger)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1