Search in sources :

Example 11 with Coordination

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

the class CoordinatorImpl method getCoordination.

/**
 * @see org.osgi.service.coordinator.Coordinator#getCoordination(long)
 */
public Coordination getCoordination(final long id) {
    Coordination c = mgr.getCoordinationById(id);
    if (c != null) {
        try {
            checkPermission(c.getName(), CoordinationPermission.ADMIN);
            c = ((CoordinationImpl) c).getHolder();
        } catch (final SecurityException e) {
            c = null;
        }
    }
    return c;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 12 with Coordination

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

the class CoordinatorImpl method pop.

/**
 * @see org.osgi.service.coordinator.Coordinator#pop()
 */
public Coordination pop() {
    Coordination c = mgr.pop();
    if (c != null) {
        checkPermission(c.getName(), CoordinationPermission.INITIATE);
        c = ((CoordinationImpl) c).getHolder();
    }
    return c;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 13 with Coordination

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

the class CoordinatorImplTest method test_addParticipant_with_failed.

public void test_addParticipant_with_failed() {
    final String name = "test";
    final Coordination c1 = coordinator.create(name, 0);
    final MockParticipant p1 = new MockParticipant();
    c1.addParticipant(p1);
    assertTrue(c1.getParticipants().contains(p1));
    assertEquals(1, c1.getParticipants().size());
    c1.fail(new Exception());
    assertFalse(p1.ended);
    assertTrue(p1.failed);
    assertEquals(c1, p1.c);
    // assert order of call
    final Coordination c2 = coordinator.create(name, 0);
    final MockParticipant p21 = new MockParticipant();
    final MockParticipant p22 = new MockParticipant();
    c2.addParticipant(p21);
    c2.addParticipant(p22);
    assertTrue(c2.getParticipants().contains(p21));
    assertTrue(c2.getParticipants().contains(p22));
    assertEquals(2, c2.getParticipants().size());
    c2.fail(new Exception());
    assertTrue(p21.failed);
    assertEquals(c2, p21.c);
    assertTrue(p22.failed);
    assertEquals(c2, p22.c);
    assertTrue("p22 must be called before p21", p22.time < p21.time);
    // assert order of call with two registrations
    final Coordination c3 = coordinator.create(name, 0);
    final MockParticipant p31 = new MockParticipant();
    final MockParticipant p32 = new MockParticipant();
    c3.addParticipant(p31);
    c3.addParticipant(p32);
    // should be "ignored"
    c3.addParticipant(p31);
    assertTrue(c3.getParticipants().contains(p31));
    assertTrue(c3.getParticipants().contains(p32));
    assertEquals(2, c3.getParticipants().size());
    c3.fail(new Exception());
    assertTrue(p31.failed);
    assertEquals(c3, p31.c);
    assertTrue(p32.failed);
    assertEquals(c3, p32.c);
    assertTrue("p31 must be called before p32", p32.time < p31.time);
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 14 with Coordination

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

the class CoordinatorImplTest method test_Coordination_addParticipant_timeout.

public void test_Coordination_addParticipant_timeout() throws InterruptedException {
    final String name1 = "test1";
    final String name2 = "test2";
    final MockParticipant p1 = new MockParticipant();
    // ensure short timeout for participation
    mgr.configure(200);
    final Coordination c1 = coordinator.create(name1, 0);
    c1.addParticipant(p1);
    assertTrue(c1.getParticipants().contains(p1));
    assertEquals(1, c1.getParticipants().size());
    // preset p1PartFailure to be be sure the participation actually starts
    p1.addParticipantFailure(new Exception("Not Started yet"));
    Thread c2Thread = new Thread() {

        @Override
        public void run() {
            final Coordination c2 = coordinator.create(name2, 0);
            try {
                p1.addParticipantFailure(null);
                c2.addParticipant(p1);
            } catch (Throwable t) {
                p1.addParticipantFailure(t);
            } finally {
                c2.end();
            }
        }
    };
    c2Thread.start();
    // wait at most 2 seconds for the second thread to terminate
    // we expect this if the participation properly times out
    c2Thread.join(2000);
    assertFalse("Thread for second Coordination did not terminate....", c2Thread.isAlive());
    Throwable p1PartFailure = p1.addParticipantFailure;
    if (p1PartFailure == null) {
        fail("Expecting CoordinationException/FAILED for second participation");
    } else if (p1PartFailure instanceof CoordinationException) {
        assertEquals(CoordinationException.FAILED, ((CoordinationException) p1PartFailure).getType());
    } else {
        fail("Unexpected Throwable while trying to addParticipant: " + p1PartFailure);
    }
    c1.end();
    // make sure c2Thread has terminated
    if (c2Thread.isAlive()) {
        c2Thread.interrupt();
        c2Thread.join(1000);
        assertFalse("Thread for second Coordination did still not terminate....", c2Thread.isAlive());
    }
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 15 with Coordination

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

the class CoordinatorImplTest method test_beginCoordination_stack.

public void test_beginCoordination_stack() {
    final String name = "test";
    final Coordination c1 = coordinator.begin(name, 0);
    assertNotNull(c1);
    assertEquals(name, c1.getName());
    assertEquals(c1, coordinator.peek());
    final Coordination c2 = coordinator.begin(name, 0);
    assertNotNull(c2);
    assertEquals(name, c2.getName());
    assertEquals(c2, coordinator.peek());
    c2.end();
    assertEquals(c1, coordinator.peek());
    c1.end();
    assertNull(coordinator.peek());
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

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