Search in sources :

Example 21 with Coordination

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;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination)

Example 22 with Coordination

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();
}
Also used : IMocksControl(org.easymock.IMocksControl) Transaction(javax.transaction.Transaction) Coordination(org.osgi.service.coordinator.Coordination) TransactionManager(javax.transaction.TransactionManager) Coordinator(org.osgi.service.coordinator.Coordinator)

Example 23 with Coordination

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;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 24 with Coordination

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();
        }
    });
}
Also used : Participant(org.osgi.service.coordinator.Participant) Coordination(org.osgi.service.coordinator.Coordination) BundleException(org.osgi.framework.BundleException) SubsystemException(org.osgi.service.subsystem.SubsystemException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 25 with Coordination

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;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) Participant(org.osgi.service.coordinator.Participant) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ResolutionException(org.osgi.service.resolver.ResolutionException) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException)

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