List of usage examples for org.springframework.transaction.support TransactionSynchronization TransactionSynchronization
TransactionSynchronization
From source file:org.hyperic.hq.common.server.session.AuditManagerImpl.java
/** * Push a global audit container onto the stack. Any subsequent audits * created (via saveAudit) will be added to this container. * // ww w . j a v a 2s .c o m * */ public void pushContainer(Audit newContainer) { Audit currentContainer = getCurrentAudit(); newContainer.setStartTime(System.currentTimeMillis()); if (currentContainer == null) { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { popAll(); } public void afterCompletion(int status) { } public void afterCommit() { } }); } else { currentContainer.addChild(newContainer); } CONTAINERS.set(newContainer); }
From source file:org.hyperic.hq.escalation.server.session.EscalationRuntimeImpl.java
/** * Unschedule the execution of an escalation state. The unschedule will only * occur if the transaction successfully commits. *//* www .j a v a 2 s. com*/ public void unscheduleEscalation(EscalationState state) { final Integer stateId = state.getId(); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { unscheduleEscalation_(stateId); } }); }
From source file:org.hyperic.hq.escalation.server.session.EscalationRuntimeImpl.java
/** * Remove the uncommitted escalation state for this entity performing * escalations from the uncommitted escalation state cache. * /*from ww w. ja v a2 s . c o m*/ * @param def * The entity that performs escalations. * @param postTxnCommit * <code>true</code> to remove post txn commit; * <code>false</code> to remove immediately. */ public void removeFromUncommittedEscalationStateCache(final PerformsEscalations def, boolean postTxnCommit) { if (postTxnCommit) { boolean addedTxnListener = false; try { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { removeFromUncommittedEscalationStateCache(def, false); } }); addedTxnListener = true; } finally { if (!addedTxnListener) { removeFromUncommittedEscalationStateCache(def, false); } } } else { _uncomittedEscalatingEntities.remove(new EscalatingEntityIdentifier(def)); } }
From source file:org.hyperic.hq.escalation.server.session.EscalationRuntimeImpl.java
/** * This method introduces an escalation state to the runtime. The escalation * will be invoked according to the next action time of the state. * /*w ww .j a v a2s .c o m*/ * If the state had been previously scheduled, it will be rescheduled with * the new time. */ public void scheduleEscalation(final EscalationState state) { final long schedTime = state.getNextActionTime(); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { scheduleEscalation_(state, schedTime); } }); }
From source file:org.hyperic.hq.events.server.session.ClassicEscalatableCreator.java
private void registerAlertFiredEvent(final Integer alertId, final AlertConditionsSatisfiedZEventPayload payload) { try {//www. j a v a 2 s . c om TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { // TODO HE-565 Possibly have MessagePublisher always // wait until successful tx commit before publishing // messages messagePublisher.publishMessage(EventConstants.EVENTS_TOPIC, new AlertFiredEvent(alertId, _def.getId(), AppdefUtil.newAppdefEntityId(_def.getResource()), _def.getName(), payload.getTimestamp(), payload.getMessage())); } }); } catch (OptimisticLockingFailureException e) { throw e; } catch (Throwable t) { _log.error( "Error registering to send an AlertFiredEvent on transaction commit. The alert will be fired, but the event will not be sent. This could cause a future recovery alert not to fire.", t); } }
From source file:org.hyperic.hq.events.server.session.RegisteredTriggerManagerImpl.java
private void addPostCommitSetEnabledListener(final Map<Integer, List<Integer>> alertDefTriggerMap, final boolean enabled) { try {//from w ww . j a v a 2 s . co m TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { try { setTriggersEnabled(alertDefTriggerMap, enabled); } catch (Exception e) { log.error("Error setting triggers enabled to " + enabled, e); } } }); } catch (Throwable t) { log.error("Error registering to set triggers enabled to " + enabled, t); } }
From source file:org.hyperic.hq.events.server.session.RegisteredTriggerManagerImpl.java
public void addTriggersCreatedTxListener(final List list) { try {/*from www .j a v a2 s. com*/ TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { final boolean debug = log.isDebugEnabled(); StopWatch watch = new StopWatch(); try { // We need to process this in a new transaction, // AlertDef ID should be set now that original tx is // committed if (!list.isEmpty()) { Object object = list.get(0); if (object instanceof Zevent) { if (debug) watch.markTimeBegin("enqueueEvents[" + list.size() + "]"); zeventEnqueuer.enqueueEvents(list); if (debug) watch.markTimeEnd("enqueueEvents[" + list.size() + "]"); } else if (object instanceof RegisteredTrigger) { RegisteredTrigger trigger = (RegisteredTrigger) object; AlertDefinition alertDefinition = getDefinitionFromTrigger(trigger); if (alertDefinition != null) { if (debug) watch.markTimeBegin("enqueueEvent"); zeventEnqueuer.enqueueEvent(new TriggersCreatedZevent(alertDefinition.getId())); if (debug) watch.markTimeEnd("enqueueEvent"); } } } } catch (Exception e) { log.error("Error creating triggers for alert definition.", e); } finally { if (debug) { log.debug("TransactionListener.afterCommit: time=" + watch); } } } }); } catch (Throwable t) { log.error("Error registering to create triggers for alert definition.", t); } }
From source file:org.hyperic.hq.galerts.processor.GalertProcessorImpl.java
/** * Called when primitive information has been updated which doens't * require a reload of the entire definition. */// w ww . ja v a 2s. co m public void alertDefUpdated(GalertDef def, final String newName) { final Integer defId = def.getId(); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { synchronized (cfgLock) { MemGalertDef memDef = (MemGalertDef) _alertDefs.get(defId); if (memDef != null) memDef.setName(newName); } } }); }
From source file:org.hyperic.hq.galerts.processor.GalertProcessorImpl.java
/** * Call this if an alert-def is created or updated. The internal state * of the processor will be updated after the current transaction * successfully commits. // w w w .j a v a2 s. c om * * This method should be called for major changes to the definition, such * as conditions, enablement, etc., since it fully unloads the existing * definition and reloads it (meaning that internal state of the * triggers, such as previously processed metrics, etc. will be reset) */ public void loadReloadOrUnload(GalertDef def) { final boolean isUnload = !def.isEnabled(); final Integer defId = def.getId(); final MemGalertDef memDef; if (isUnload) { memDef = null; } else { memDef = new MemGalertDef(def); } TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { if (isUnload) { handleUnload(defId); } else { handleUpdate(memDef); } } }); }
From source file:org.hyperic.hq.galerts.processor.GalertProcessorImpl.java
/** * Call this if an alert-def is deleted. After the transaction is * successfully committed, it will be removed from the processor. *//*from w w w . j a v a2 s . co m*/ public void alertDefDeleted(final Integer defId) { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { public void suspend() { } public void resume() { } public void flush() { } public void beforeCompletion() { } public void beforeCommit(boolean readOnly) { } public void afterCompletion(int status) { } public void afterCommit() { handleUnload(defId); } }); }