本文整理汇总了Java中bitronix.tm.TransactionManagerServices.isTransactionManagerRunning方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionManagerServices.isTransactionManagerRunning方法的具体用法?Java TransactionManagerServices.isTransactionManagerRunning怎么用?Java TransactionManagerServices.isTransactionManagerRunning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitronix.tm.TransactionManagerServices
的用法示例。
在下文中一共展示了TransactionManagerServices.isTransactionManagerRunning方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
/**
* Register a {@link XAResourceProducer}. If registration happens after the transaction manager started, incremental
* recovery is run on that resource.
* @param producer the {@link XAResourceProducer}.
* @throws RecoveryException When an error happens during recovery.
*/
public static void register(XAResourceProducer producer) throws RecoveryException {
try {
final boolean alreadyRunning = TransactionManagerServices.isTransactionManagerRunning();
final ProducerHolder holder = alreadyRunning ? new InitializableProducerHolder(producer) : new ProducerHolder(producer);
if (resources.add(holder)) {
if (holder instanceof InitializableProducerHolder) {
boolean recovered = false;
try {
if (log.isDebugEnabled()) { log.debug("Transaction manager is running, recovering resource '" + holder.getUniqueName() + "'."); }
IncrementalRecoverer.recover(producer);
((InitializableProducerHolder) holder).initialize();
recovered = true;
} finally {
if (!recovered) { resources.remove(holder); }
}
}
} else {
throw new IllegalStateException("A resource with uniqueName '" + holder.getUniqueName() + "' has already been registered. " +
"Cannot register XAResourceProducer '" + producer + "'.");
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Cannot register the XAResourceProducer '" + producer + "' caused by invalid input.", e);
}
}
示例2: withStartupTimeLogging
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
private <T> T withStartupTimeLogging(Supplier<T> sup) {
if (TransactionManagerServices.isTransactionManagerRunning())
return sup.get();
Stopwatch watch = Stopwatch.createStarted();
T result = sup.get();
StartupTimeLogger.stopAndLog("Bitronix startup", watch);
return result;
}
示例3: tearDownBtm
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@After
public void tearDownBtm() throws Exception {
if(cacheManager != null) {
cacheManager.close();
}
if (TransactionManagerServices.isTransactionManagerRunning()) {
TransactionManagerServices.getTransactionManager().shutdown();
}
}
示例4: lookupTransactionManagerWrapper
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Override
public TransactionManagerWrapper lookupTransactionManagerWrapper() { // <2>
if (!TransactionManagerServices.isTransactionManagerRunning()) { // <3>
throw new IllegalStateException("BTM must be started beforehand");
}
TransactionManagerWrapper tmWrapper = new TransactionManagerWrapper(TransactionManagerServices.getTransactionManager(),
new BitronixXAResourceRegistry()); // <4>
LOGGER.info("Using looked up transaction manager : {}", tmWrapper);
return tmWrapper;
}
示例5: getInPool
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
/**
* Get an IN_POOL connection. This method blocks for up to remainingTimeMs milliseconds
* for someone to return or create a connection in the available pool. If remainingTimeMs
* expires, an exception is thrown. It does not use stateTransitionLock.readLock() because
* the availablePool [a LinkedBlockingQueue] is already thread safe.
*
* @param remainingTimeMs the maximum time to wait for a connection
* @return a connection from the available (IN_POOL) pool
* @throws Exception thrown in no connection is available before the remainingTimeMs time expires
*/
private T getInPool(long remainingTimeMs) throws Exception {
if (inPoolSize() == 0) {
if (log.isDebugEnabled()) { log.debug("no more free connections in " + this + ", trying to grow it"); }
grow();
}
if (log.isDebugEnabled()) { log.debug("getting IN_POOL connection from " + this + ", waiting if necessary"); }
try {
T xaStatefulHolder = availablePool.pollFirst(remainingTimeMs, TimeUnit.MILLISECONDS);
if (xaStatefulHolder == null) {
if (TransactionManagerServices.isTransactionManagerRunning())
TransactionManagerServices.getTransactionManager().dumpTransactionContexts();
throw new BitronixRuntimeException("XA pool of resource " + bean.getUniqueName() + " still empty after " + bean.getAcquisitionTimeout() + "s wait time");
}
if (expireStatefulHolder(xaStatefulHolder, false)) {
return getInPool(remainingTimeMs);
}
return xaStatefulHolder;
} catch (InterruptedException e) {
throw new BitronixRuntimeException("Interrupted while waiting for IN_POOL connection.");
}
}
示例6: isEnlistedInSomeTransaction
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
private static boolean isEnlistedInSomeTransaction(XAResourceHolder<? extends XAResourceHolder> xaResourceHolder) throws BitronixSystemException {
if (log.isDebugEnabled()) { log.debug("looking in in-flight transactions for XAResourceHolderState of " + xaResourceHolder); }
if (!TransactionManagerServices.isTransactionManagerRunning()) {
if (log.isDebugEnabled()) { log.debug("transaction manager not running, there is no in-flight transaction"); }
return false;
}
return xaResourceHolder.hasStateForXAResource(xaResourceHolder);
}
示例7: tearDown
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
if (TransactionManagerServices.isTransactionManagerRunning())
TransactionManagerServices.getTransactionManager().shutdown();
journal.close();
pds.close();
TransactionManagerServices.getJournal().close();
new File(TransactionManagerServices.getConfiguration().getLogPart1Filename()).delete();
new File(TransactionManagerServices.getConfiguration().getLogPart2Filename()).delete();
EventRecorder.clear();
}
示例8: tearDown
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
if (TransactionManagerServices.isTransactionManagerRunning()) {
TransactionManagerServices.getTransactionManager().shutdown();
}
}
示例9: currentTransaction
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
/**
* Get the transaction running on the current thead context.
* @return null if there is no transaction on the current context or if the transaction manager is not running.
*/
public static BitronixTransaction currentTransaction() {
if (!TransactionManagerServices.isTransactionManagerRunning())
return null;
return TransactionManagerServices.getTransactionManager().getCurrentTransaction();
}
示例10: run
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
/**
* Run the recovery process. This method is automatically called by the transaction manager, you should never
* call it manually.
*/
@Override
public void run() {
if (!isRunning.compareAndSet(false, true)) {
log.info("recoverer is already running, abandoning this recovery request");
return;
}
try {
committedCount = 0;
rolledbackCount = 0;
long oldestTransactionTimestamp = Long.MAX_VALUE;
// Collect dangling records from journal, must run before oldestTransactionTimestamp is calculated
Map<Uid, JournalRecord> danglingRecords = TransactionManagerServices.getJournal().collectDanglingRecords();
// Query resources from ResourceRegistrar
synchronized (ResourceRegistrar.class) {
for (String name : ResourceRegistrar.getResourcesUniqueNames()) {
registeredResources.put(name, ResourceRegistrar.get(name));
}
if (TransactionManagerServices.isTransactionManagerRunning()) {
oldestTransactionTimestamp = TransactionManagerServices.getTransactionManager().getOldestInFlightTransactionTimestamp();
}
}
// 1. call recover on all known resources
recoverAllResources();
// 2. commit dangling COMMITTING transactions
Set<Uid> committedGtrids = commitDanglingTransactions(oldestTransactionTimestamp, danglingRecords);
committedCount = committedGtrids.size();
// 3. rollback any remaining recovered transaction
rolledbackCount = rollbackAbortedTransactions(oldestTransactionTimestamp, committedGtrids);
if (executionsCount == 0 || committedCount > 0 || rolledbackCount > 0) {
log.info("recovery committed " + committedCount + " dangling transaction(s) and rolled back " + rolledbackCount +
" aborted transaction(s) on " + registeredResources.size() + " resource(s) [" + getRegisteredResourcesUniqueNames() + "]" +
((TransactionManagerServices.getConfiguration().isCurrentNodeOnlyRecovery()) ? " (restricted to serverId '" + TransactionManagerServices.getConfiguration().getServerId() + "')" : ""));
}
else if (log.isDebugEnabled()) {
log.debug("recovery committed " + committedCount + " dangling transaction(s) and rolled back " + rolledbackCount +
" aborted transaction(s) on " + registeredResources.size() + " resource(s) [" + getRegisteredResourcesUniqueNames() + "]" +
((TransactionManagerServices.getConfiguration().isCurrentNodeOnlyRecovery()) ? " (restricted to serverId '" + TransactionManagerServices.getConfiguration().getServerId() + "')" : ""));
}
this.completionException = null;
} catch (Exception ex) {
this.completionException = ex;
log.warn("recovery failed, registered resource(s): " + getRegisteredResourcesUniqueNames(), ex);
}
finally {
recoveredXidSets.clear();
registeredResources.clear();
executionsCount++;
isRunning.set(false);
}
}