Example usage for org.springframework.transaction.support TransactionSynchronization TransactionSynchronization

List of usage examples for org.springframework.transaction.support TransactionSynchronization TransactionSynchronization

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionSynchronization TransactionSynchronization.

Prototype

TransactionSynchronization

Source Link

Usage

From source file:org.hyperic.hq.hqu.RenditServerImpl.java

private void deployPlugin(final PluginWrapper plugin, final File path, String pluginName, String pluginVer) {
    try {//  w w w.  j a v a2 s .  c  om
        // 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)//from  w  w w . j a va2 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);
}