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