List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager registerSynchronization
public static void registerSynchronization(TransactionSynchronization synchronization) throws IllegalStateException
From source file:org.hyperic.hq.events.server.session.ClassicEscalatableCreator.java
private void registerAlertFiredEvent(final Integer alertId, final AlertConditionsSatisfiedZEventPayload payload) { try {/*from w ww .j a v a2 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() { // 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 .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() { 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 ww w . ja v a 2 s . c o 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() { 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. *//*from w w w . ja va 2 s . com*/ 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. /*ww w . j a va 2s . 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 ww . j a v a 2s . 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); } }); }
From source file:org.hyperic.hq.hqu.RenditServerImpl.java
private void deployPlugin(final PluginWrapper plugin, final File path, String pluginName, String pluginVer) { try {/*from w ww .jav a 2 s . c o m*/ // TODO Need to change this...this is done for short term to get past circular dependency w/ UIPluginManager uiPluginManager = Bootstrap.getBean(UIPluginManager.class); UIPlugin p = uiPluginManager.createOrUpdate(pluginName, pluginVer); plugin.deploy(p); 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) { plugins.put(path.getName(), plugin); } } }); } catch (Exception e) { throw new PluginLoadException("Error loading HQU plugin [" + pluginName + "]", e); } }
From source file:org.hyperic.hq.zevents.ZeventManager.java
/** * Enqueue events if the current running transaction successfully commits. * @see #enqueueEvents(List)/* w w w .j ava2 s . c o m*/ */ public void enqueueEventsAfterCommit(List<? extends Zevent> inEvents, final long timeout) { final List<Zevent> events = new ArrayList<Zevent>(inEvents); TransactionSynchronization txListener = new TransactionSynchronization() { public void afterCommit() { try { if (_log.isDebugEnabled()) { _log.debug("Listener[" + this.toString() + "] after tx. Enqueueing. "); } enqueueEvents(events, timeout); } catch (InterruptedException e) { _log.warn("Interrupted while enqueueing events: ", e); } catch (Exception e) { _log.error("Errorwhile enqueueing events: ", e); } } public void afterCompletion(int status) { } public void beforeCommit(boolean readOnly) { } public void beforeCompletion() { } public void flush() { } public void resume() { } public void suspend() { } }; if (_log.isDebugEnabled()) { _log.debug("Listener[" + txListener + "] Enqueueing events: " + inEvents); } TransactionSynchronizationManager.registerSynchronization(txListener); }
From source file:org.jspresso.framework.application.backend.AbstractBackendController.java
/** * {@inheritDoc}/*ww w .j a v a 2 s . c o m*/ */ @Override public void joinTransaction(boolean nested) { TransactionSynchronizationManager.registerSynchronization(this); if (!isUnitOfWorkActive()) { beginUnitOfWork(); } else if (nested) { beginNestedUnitOfWork(); } }
From source file:org.kuali.rice.kcb.service.impl.MessagingServiceImpl.java
private void queueJob(MessageProcessingJob.Mode mode, long messageId, String user, String cause) { // queue up the processing job after the transaction has committed LOG.debug("registering synchronization"); if (!TransactionSynchronizationManager.isSynchronizationActive()) { throw new RiceRuntimeException("transaction syncronization is not active " + "(!TransactionSynchronizationManager.isSynchronizationActive())"); } else if (!TransactionSynchronizationManager.isActualTransactionActive()) { throw new RiceRuntimeException("actual transaction is not active " + "(!TransactionSynchronizationManager.isActualTransactionActive())"); }//from ww w.jav a2 s . c o m TransactionSynchronizationManager.registerSynchronization(new QueueProcessingJobSynchronization(jobName, jobGroup, mode, messageId, user, cause, synchronous)); }