/** * Create a new Coordination Exception with a cause. * * @param message The detail message for this exception. * @param coordination The Coordination associated with this exception. * @param cause The cause associated with this exception. * @param type The type of this exception. * @throws IllegalArgumentException If the specified type is {@link #FAILED} * and the specified cause is {@code null}. */ public CoordinationException(String message, Coordination coordination, int type, Throwable cause) { super(message, cause); this.type = type; if (coordination == null) { this.id = -1L; this.name = "<>"; } else { this.id = coordination.getId(); this.name = coordination.getName(); } if ((type == FAILED) && (cause == null)) { throw new IllegalArgumentException("A cause must be specified for type FAILED"); } }
@Override public void ended(Coordination coordination) throws Exception { LOG.debug("Closing EntityManager for persistence unit " + unitName + " as coordination " + coordination.getName() + " ended."); EntityManager em = removeEm(coordination); emSet.remove(em); em.close(); if (shutdown.get()) { emsToShutDown.countDown(); } } }
LOG.debug("Creating EntityManager for persistence unit " + unitName + ", coordination " + coordination.getName()); em = createEm(emf); emSet.add(em); setEm(coordination, em); coordination.addParticipant(new EmShutDownParticipant());
@Override public void failed(Coordination coordination) throws Exception { LOG.debug("Coordination failed " + coordination.getName(), coordination.getFailure()); ended(coordination); }
private static void close(Coordination coord) { if (coord != null) { coord.end(); } }
/** * @see org.osgi.service.coordinator.Coordinator#addParticipant(org.osgi.service.coordinator.Participant) */ public boolean addParticipant(final Participant participant) { Coordination current = peek(); if (current != null) { current.addParticipant(participant); return true; } return false; }
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; } }
@Override public void postCallWithException(ComponentMetadata cm, Method m, Throwable ex, Object preCallToken) { LOG.debug("PostCallWithException for bean {}, method {}", cm.getId(), m.getName(), ex); if (preCallToken != null) { ((Coordination)preCallToken).fail(ex); } }
/** * @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; }
@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); } } }
public static void endCoordination(final Object object) { final Coordination coordination = (Coordination) object; try { coordination.end(); } catch (final Exception e) { SystemLogger.error("Error ending coordination " + coordination, e); } } }
public boolean addParticipant(Participant participant) throws CoordinationException { CoordinationWeakReference.processOrphanedCoordinations(); Coordination coordination = peek(); if (coordination == null) return false; coordination.addParticipant(participant); return true; }
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; } }
public boolean fail(Throwable reason) { CoordinationWeakReference.processOrphanedCoordinations(); Coordination coordination = peek(); if (coordination == null) return false; return coordination.fail(reason); }
/** * Create a new Coordination Exception. * * @param message The detail message for this exception. * @param coordination The Coordination associated with this exception. * @param type The type of this exception. * @throws IllegalArgumentException If the specified type is {@link #FAILED} * . */ public CoordinationException(String message, Coordination coordination, int type) { super(message); this.type = type; if (coordination == null) { this.id = -1L; this.name = "<>"; } else { this.id = coordination.getId(); this.name = coordination.getName(); } if (type == FAILED) { throw new IllegalArgumentException("A cause must be specified for type FAILED"); } }
/** * @see org.osgi.service.coordinator.Coordinator#pop() */ public Coordination pop() { Coordination c = mgr.pop(); if ( c != null ) { checkPermission(c.getName(), CoordinationPermission.INITIATE); c = ((CoordinationImpl)c).getHolder(); } return c; }
@Override public void postCallWithReturn(ComponentMetadata cm, Method m, Object returnType, Object preCallToken) throws Exception { LOG.debug("PostCallWithReturn for bean {}, method {}", cm.getId(), m.getName()); if (preCallToken != null) { ((Coordination)preCallToken).end(); } }
@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 } }