@Override public void handleMessage(org.apache.cxf.message.Message message) throws Fault { Coordination coordination = coordinator.begin("cxf", 10000); message.getExchange().put(Coordination.class, coordination); }
@Override public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable { if (coordinator == null || em == null) { initServices(); } try { LOG.debug("PreCall for bean {}, method {}", cm.getId(), m.getName()); Coordination coordination = coordinator.begin("jpa", 0); boolean weControlTx = isResourceLocal(em) && !em.getTransaction().isActive(); if (weControlTx) { coordination.addParticipant(new ResourceLocalTransactionParticipant(em)); } return coordination; } catch (Exception e) { LOG.warn("Exception from EmSupplier.preCall", e); throw new RuntimeException(e); // NOSONAR } }
@Override public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable { final TransactionalAnnotationAttributes type = txData.getEffectiveType(m); if (type == null) { // No transaction return null; } TransactionAttribute txAttribute = TransactionAttribute.fromValue(type.getTxType()); LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.", getCmId(cm), m.getName(), txAttribute); TransactionToken token = txAttribute.begin(tm); String coordName = "txInterceptor." + m.getDeclaringClass().getName() + "." + m.getName(); Coordination coord = coordinator.begin(coordName , 0); token.setCoordination(coord); return token; }
@Override public <R> R txExpr(TransactionType type, EmFunction<R> code) { EntityManager em = null; boolean weControlTx = false; if (type != TransactionType.Required) { throw new IllegalStateException("Only transation propagation type REQUIRED is supported"); } Coordination coord = coordinator.begin(this.getClass().getName(), 0); try { em = emSupplier.get(); weControlTx = !em.getTransaction().isActive(); if (weControlTx) { em.getTransaction().begin(); } R result = (R)code.apply(em); if (weControlTx) { em.getTransaction().commit(); } return result; } catch (Exception e) { if (weControlTx) { safeRollback(em); } throw wrapThrowable(e, "Exception occured in transactional code"); } finally { coord.end(); } }
? coordinator.begin("enRoute.configurer", TimeUnit.SECONDS.toMillis(20)) : null; try {
@Override public <R> R txExpr(TransactionType type, EmFunction<R> code) { EntityManager em = null; TransactionToken tranToken = null; TransactionAttribute ta = TransactionAttribute.fromType(type); Coordination coord = null; try { tranToken = ta.begin(tm); coord = coordinator.begin(this.getClass().getName(), 0); em = emSupplier.get(); if (tm.getStatus() != Status.STATUS_NO_TRANSACTION) { em.joinTransaction(); } R result = (R)code.apply(em); safeFinish(tranToken, ta, coord); return result; } catch (RollbackException ex) { safeRollback(tranToken, ta, coord, ex); throw wrapThrowable(ex, "RollbackException is propagating"); } catch (Exception ex) { safeRollback(tranToken, ta, coord, ex); throw wrapThrowable(ex, "Exception occured in transactional code"); } catch (Error ex) { // NOSONAR safeRollback(tranToken, ta, coord, ex); throw ex; } }
@Tooltip("Reads a number of configuration from a resource 'example.configs' and installs them. The actions are enclosed by a Coordination") public void coordinator() throws Exception { try (InputStream in = Examples.class .getResourceAsStream("example.configs")) { Coordination coordination = coordinator.begin("example.1", 100000); try { List<Config> list = dtos.decoder( new TypeReference<List<Config>>() { }).get(in); for (Config config : list) { Configuration c; if (config.factoryPid != null) c = cm.createFactoryConfiguration(config.factoryPid, "?"); else c = cm.getConfiguration(config.pid); c.update(config.properties); } coordination.end(); } catch (Throwable t) { coordination.fail(t); } } }