use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class TxInterceptorImpl method preCall.
@Override
public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable {
final Optional<TransactionalAnnotationAttributes> type = txData.getEffectiveType(m);
if (!type.isPresent()) {
// No transaction
return null;
}
TransactionAttribute txAttribute = TransactionAttribute.fromValue(type.get().getTxType());
LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.", getCmId(cm), m.getName(), txAttribute);
TransactionToken token = txAttribute.begin(tm);
if (token.requiresNewCoordination()) {
String coordName = "txInterceptor." + m.getDeclaringClass().getName() + "." + m.getName();
Coordination coord = coordinator.begin(coordName, 0);
// @javax.transaction.Transactional is only part of 1.2 and even if it's about time that all previous
// JTA versions should be forgotten, we can't rely on it...
coord.getVariables().put(Transaction.class, txAttribute.name());
token.setCoordination(coord);
}
return token;
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class InterceptorTest method postCallWithTransaction.
private void postCallWithTransaction(Throwable th, boolean expectRollback, boolean failCoordination) throws Throwable {
IMocksControl c = EasyMock.createControl();
TransactionManager tm = c.createMock(TransactionManager.class);
Coordinator coordinator = c.createMock(Coordinator.class);
ComponentTxData txData = new ComponentTxData(AnnotatedPojo.class);
TxInterceptorImpl sut = new TxInterceptorImpl(tm, coordinator, txData);
Transaction tran = c.createMock(Transaction.class);
if (expectRollback) {
tran.setRollbackOnly();
EasyMock.expectLastCall();
}
Coordination coordination = c.createMock(Coordination.class);
coordination.end();
if (failCoordination) {
EasyMock.expectLastCall().andThrow(coordinationException(th));
} else {
EasyMock.expectLastCall();
}
c.replay();
TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);
tt.setCoordination(coordination);
sut.postCallWithException(null, this.getClass().getMethods()[0], th, tt);
c.verify();
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class InterceptorTest method coordinationException.
private CoordinationException coordinationException(Throwable th) {
Coordination coordination = EasyMock.createMock(Coordination.class);
expect(coordination.getId()).andReturn(1l);
expect(coordination.getName()).andReturn("Test");
replay(coordination);
CoordinationException cex = new CoordinationException("Simulating exception", coordination, CoordinationException.FAILED, th);
return cex;
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class StartAction method startSubsystemResource.
private void startSubsystemResource(Resource resource, final Coordination coordination) throws IOException {
final BasicSubsystem subsystem = (BasicSubsystem) resource;
if (!isTargetStartable(instigator, target, subsystem)) {
return;
}
// their autostart setting set to started.
if (Utils.isContent(this.target, subsystem))
subsystem.setAutostart(true);
new StartAction(instigator, target, subsystem, coordination).run();
if (coordination == null)
return;
coordination.addParticipant(new Participant() {
public void ended(Coordination coordination) throws Exception {
// noop
}
public void failed(Coordination coordination) throws Exception {
new StopAction(target, subsystem, !subsystem.isRoot()).run();
}
});
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class SubsystemResource method getRegion.
public synchronized Region getRegion() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
if (region == null) {
region = createRegion(getId());
Coordination coordination = Activator.getInstance().getCoordinator().peek();
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination arg0) throws Exception {
// Nothing.
}
@Override
public void failed(Coordination arg0) throws Exception {
if (isScoped())
region.getRegionDigraph().removeRegion(region);
}
});
if (!isApplication()) {
setImportIsolationPolicy();
}
}
return region;
}
Aggregations