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;
}
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());
}
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);
}
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());
}
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;
}
Aggregations