Search in sources :

Example 1 with Coordination

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

the class CoordinatorImpl method getCoordinations.

/**
 * @see org.osgi.service.coordinator.Coordinator#getCoordinations()
 */
public Collection<Coordination> getCoordinations() {
    final Collection<Coordination> result = mgr.getCoordinations();
    final Iterator<Coordination> i = result.iterator();
    while (i.hasNext()) {
        final Coordination c = i.next();
        try {
            this.checkPermission(c.getName(), CoordinationPermission.ADMIN);
        } catch (final SecurityException se) {
            i.remove();
        }
    }
    return result;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 2 with Coordination

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

the class CoordinatorImplTest method test_beginCoordination_stack2.

public void test_beginCoordination_stack2() {
    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());
    c1.end();
    assertNull(coordinator.peek());
    try {
        c2.end();
        fail("c2 is already terminated");
    } catch (CoordinationException ce) {
        assertEquals(CoordinationException.ALREADY_ENDED, ce.getType());
    }
    assertNull(coordinator.peek());
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 3 with Coordination

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

the class CoordinatorImplTest method test_addParticipant_with_ended.

public void test_addParticipant_with_ended() {
    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.end();
    assertTrue(p1.ended);
    assertFalse(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.end();
    assertTrue(p21.ended);
    assertEquals(c2, p21.c);
    assertTrue(p22.ended);
    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.end();
    assertTrue(p31.ended);
    assertEquals(c3, p31.c);
    assertTrue(p32.ended);
    assertEquals(c3, p32.c);
    assertTrue("p32 must be called before p31", p32.time < p31.time);
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 4 with Coordination

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

the class CoordinatorImplTest method test_beginCoordination.

public void test_beginCoordination() {
    final String name = "test";
    final Coordination c1 = coordinator.begin(name, 0);
    assertNotNull(c1);
    assertEquals(name, c1.getName());
    assertEquals(c1, coordinator.peek());
    assertEquals(c1, coordinator.pop());
    assertNull(coordinator.peek());
    c1.push();
    assertEquals(c1, coordinator.peek());
    c1.end();
    assertNull(coordinator.peek());
    final Coordination c2 = coordinator.begin(name, 0);
    assertNotNull(c2);
    assertEquals(name, c2.getName());
    assertEquals(c2, coordinator.peek());
    c2.fail(new Exception());
    assertNotNull(coordinator.peek());
    try {
        c2.end();
        fail("Exception should be thrown");
    } catch (CoordinationException ce) {
    // ignore
    }
    assertNull(coordinator.peek());
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 5 with Coordination

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

the class CoordinatorUtil method getCoordination.

public static Object getCoordination(final Object object) {
    final Coordinator coordinator = (Coordinator) object;
    final Coordination threadCoordination = coordinator.peek();
    if (threadCoordination == null) {
        try {
            return coordinator.create("org.apache.felix.configurator", 0L);
        } catch (final Exception e) {
            SystemLogger.error("Unable to create new coordination with coordinator " + coordinator, e);
        }
    }
    return null;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) Coordinator(org.osgi.service.coordinator.Coordinator)

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