Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other
* contributors as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.infinispan.transaction;
import net.jcip.annotations.GuardedBy;
import org.infinispan.Cache;
import org.infinispan.CacheException;
import org.infinispan.commands.CommandsFactory;
import org.infinispan.commands.tx.RollbackCommand;
import org.infinispan.commands.write.WriteCommand;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.Configurations;
import org.infinispan.context.InvocationContextContainer;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
import org.infinispan.factories.annotations.Stop;
import org.infinispan.interceptors.InterceptorChain;
import org.infinispan.interceptors.locking.ClusteringDependentLogic;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.CacheNotifier;
import org.infinispan.notifications.cachelistener.annotation.TopologyChanged;
import org.infinispan.notifications.cachelistener.event.TopologyChangedEvent;
import org.infinispan.remoting.rpc.RpcManager;
import org.infinispan.remoting.transport.Address;
import org.infinispan.topology.CacheTopology;
import org.infinispan.transaction.synchronization.SyncLocalTransaction;
import org.infinispan.transaction.synchronization.SynchronizationAdapter;
import org.infinispan.transaction.xa.CacheTransaction;
import org.infinispan.transaction.xa.GlobalTransaction;
import org.infinispan.transaction.xa.TransactionFactory;
import org.infinispan.util.InfinispanCollections;
import org.infinispan.util.Util;
import org.infinispan.util.concurrent.ConcurrentMapFactory;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import javax.transaction.Transaction;
import javax.transaction.TransactionSynchronizationRegistry;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static org.infinispan.util.Util.currentMillisFromNanotime;
/**
* Repository for {@link RemoteTransaction} and {@link org.infinispan.transaction.xa.TransactionXaAdapter}s (locally
* originated transactions).
*
* @author [email protected]
* @author Galder Zamarreño
* @since 4.0
*/
@Listener
public class TransactionTable {
public static final int CACHE_STOPPED_TOPOLOGY_ID = -1;
private static final Log log = LogFactory.getLog(TransactionTable.class);
private ConcurrentMap localTransactions;
private ConcurrentMap globalToLocalTransactions;
private ConcurrentMap remoteTransactions;
protected Configuration configuration;
protected InvocationContextContainer icc;
protected TransactionCoordinator txCoordinator;
protected TransactionFactory txFactory;
protected RpcManager rpcManager;
protected CommandsFactory commandsFactory;
private InterceptorChain invoker;
private CacheNotifier notifier;
private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
protected ClusteringDependentLogic clusteringLogic;
protected boolean clustered = false;
private Lock minTopologyRecalculationLock;
private final ConcurrentMap completedTransactions = ConcurrentMapFactory.makeConcurrentMap();
private ScheduledExecutorService executorService;
/**
* minTxTopologyId is the minimum topology ID across all ongoing local and remote transactions.
*/
private volatile int minTxTopologyId = CACHE_STOPPED_TOPOLOGY_ID;
private volatile int currentTopologyId = CACHE_STOPPED_TOPOLOGY_ID;
private String cacheName;
@Inject
public void initialize(RpcManager rpcManager, Configuration configuration,
InvocationContextContainer icc, InterceptorChain invoker, CacheNotifier notifier,
TransactionFactory gtf, TransactionCoordinator txCoordinator,
TransactionSynchronizationRegistry transactionSynchronizationRegistry,
CommandsFactory commandsFactory, ClusteringDependentLogic clusteringDependentLogic, Cache cache) {
this.rpcManager = rpcManager;
this.configuration = configuration;
this.icc = icc;
this.invoker = invoker;
this.notifier = notifier;
this.txFactory = gtf;
this.txCoordinator = txCoordinator;
this.transactionSynchronizationRegistry = transactionSynchronizationRegistry;
this.commandsFactory = commandsFactory;
this.clusteringLogic = clusteringDependentLogic;
this.cacheName = cache.getName();
}
@Start(priority = 9) // Start before cache loader manager
@SuppressWarnings("unused")
private void start() {
final int concurrencyLevel = configuration.locking().concurrencyLevel();
localTransactions = ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
globalToLocalTransactions = ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
if (configuration.clustering().cacheMode().isClustered()) {
minTopologyRecalculationLock = new ReentrantLock();
// Only initialize this if we are clustered.
remoteTransactions = ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
notifier.addListener(this);
clustered = true;
}
// Periodically run a task to cleanup the transaction table from completed transactions.
ThreadFactory tf = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
String address = rpcManager != null ? rpcManager.getTransport().getAddress().toString() : "local";
Thread th = new Thread(r, "TxCleanupService," + cacheName + "," + address);
th.setDaemon(true);
return th;
}
};
executorService = Executors.newSingleThreadScheduledExecutor(tf);
long interval = configuration.transaction().reaperWakeUpInterval();
executorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
cleanupCompletedTransactions();
}
}, interval, interval, TimeUnit.MILLISECONDS);
}
@Stop
@SuppressWarnings("unused")
private void stop() {
if (executorService != null)
executorService.shutdownNow();
if (clustered) {
notifier.removeListener(this);
currentTopologyId = CACHE_STOPPED_TOPOLOGY_ID; // indicate that the cache has stopped
}
shutDownGracefully();
}
public Set