/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 com.taobao.datasource.tm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkCompletedException;
import javax.resource.spi.work.WorkException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.jboss.logging.Logger;
import org.jboss.util.timeout.Timeout;
import org.jboss.util.timeout.TimeoutFactory;
import org.jboss.util.timeout.TimeoutTarget;
import com.taobao.datasource.tm.integrity.TransactionIntegrity;
/**
* Our <code>Transaction</code> implementation.
*
* @see TxManager
*
* @author <a href="mailto:rickard.oberg@telkel.com">Rickard Ãberg</a>
* @author <a href="mailto:marc.fleury@telkel.com">Marc Fleury</a>
* @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
* @author <a href="mailto:toby.allsopp@peace.com">Toby Allsopp</a>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
* @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
* @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
* @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
* @version $Revision: 57208 $
*/
public class TransactionImpl
implements Transaction, TimeoutTarget
{
// Constants -----------------------------------------------------
/**
* Code meaning "no heuristics seen",
* must not be XAException.XA_HEURxxx
*/
private static final int HEUR_NONE = XAException.XA_RETRY;
// Resource states
private final static int RS_NEW = 0; // not yet enlisted
private final static int RS_ENLISTED = 1; // enlisted
private final static int RS_SUSPENDED = 2; // suspended
private final static int RS_ENDED = 3; // not associated
private final static int RS_VOTE_READONLY = 4; // voted read-only
private final static int RS_VOTE_OK = 5; // voted ok
private final static int RS_FORGOT = 6; // RM has forgotten
// Attributes ----------------------------------------------------
/** Class logger, we don't want a new logger with every transaction. */
private static Logger log = Logger.getLogger(TransactionImpl.class);
/** True if trace messages should be logged. */
private boolean trace = log.isTraceEnabled();
/** The ID of this transaction. */
private XidImpl xid;
/** The global id */
private GlobalId gid;
private HashSet threads = new HashSet(1);
private Map transactionLocalMap = Collections.synchronizedMap(new HashMap());
private Throwable cause;
/**
* The synchronizations to call back.
*/
private Synchronization[] sync = new Synchronization[3];
/**
* Size of allocated synchronization array.
*/
private int syncAllocSize = 3;
/**
* Count of synchronizations for this transaction.
*/
private int syncCount = 0;
/**
* A list of the XAResources that have participated in this transaction.
*/
private ArrayList resources = new ArrayList(3);
/**
* The XAResource used in the last resource gambit
*/
private Resource lastResource;
/**
* Flags that it is too late to enlist new resources.
*/
private boolean resourcesEnded = false;
/**
* Last branch id used.
*/
private long lastBranchId = 0;
/**
* Status of this transaction.
*/
private int status;
/**
* The heuristics status of this transaction.
*/
private int heuristicCode = HEUR_NONE;
/**
* The time when this transaction was started.
*/
private long start;
/**
* The timeout handle for this transaction.
*/
private Timeout timeout;
/**
* Timeout in millisecs
*/
private long timeoutPeriod;
/**
* Mutex for thread-safety. This should only be changed in the
* <code>lock()</code> and <code>unlock()</code> methods.
*/
private Thread locked = null;
/**
* The lock depth
*/
private int lockDepth = 0;
/** Any current work associated with the transaction */
private Work work;
/**
* Flags that we are done with this transaction and that it can be reused.
*/
private boolean done = false;
// Static --------------------------------------------------------
/**
* Factory for Xid instances of specified class.
* This is set from the <code>TransactionManagerService</code>
* MBean.
*/
static XidFactoryMBean xidFactory;
// static TransactionManagerService txManagerService;
/** The timeout factory */
static TimeoutFactory timeoutFactory = TimeoutFactory.getSingleton();
/**
* This static code is only present for testing purposes so a
* tm can be usable without a lot of setup.
*/
static void defaultXidFactory()
{
if (xidFactory == null)
xidFactory = new XidFactory();
}
// Constructors --------------------------------------------------
TransactionImpl(long timeout)
{
xid = xidFactory.newXid();
gid = xid.getTrulyGlobalId();
status = Status.STATUS_ACTIVE;
start = System.currentTimeMillis();
this.timeout = timeoutFactory.createTimeout(start+timeout, this);
this.timeoutPeriod = timeout;
if (trace)
log.trace("Created new instance for tx=" + toString());
}
TransactionImpl(GlobalId gid, long timeout)
{
this.gid = gid;
xid = xidFactory.newXid();
status = Status.STATUS_ACTIVE;
start = System.currentTimeMillis();
this.timeout = timeoutFactory.createTimeout(start+timeout, this);
this.timeoutPeriod = timeout;
if (trace)
log.trace("Created new instance for tx=" + toString());
}
// Implements TimeoutTarget --------------------------------------
/**
* Called when our timeout expires.
*/
public void timedOut(Timeout timeout)
{
lock();
try
{
log.warn("Transaction " + toString() + " timed out." +
" status=" + getStringStatus(status));
if (this.timeout == null)
return; // Don't race with timeout cancellation.
this.timeout = null;
switch (status)
{
case Status.STATUS_ROLLEDBACK:
case Status.STATUS_COMMITTED:
case Status.STATUS_NO_TRANSACTION:
return; // Transaction done.
case Status.STATUS_ROLLING_BACK:
re
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
tddl.rar_Different_TDDL (1250个子文件)
console.bat 42B
wc.db 951KB
generators.dtd 797B
entries 3B
format 3B
TransactionImpl.java 66KB
SynchronizationTimer.java 64KB
WrappedResultSet.java 40KB
ConcurrentReaderHashMap.java 38KB
ConcurrentHashMap.java 38KB
CopyOnWriteArrayList.java 37KB
RowBasedReplicationExecutor.java 36KB
FuncRegister.java 36KB
JBossManagedConnectionPool.java 34KB
TxConnectionManager.java 34KB
PooledExecutor.java 32KB
TAtomDsConfHandle.java 30KB
MockResultSet.java 29KB
FJTaskRunner.java 28KB
VirtualTableRuleMatcher.java 26KB
DatabaseMetaDataWrapper.java 26KB
TResultSetWrapper.java 26KB
TStringUtil.java 25KB
TxManager.java 25KB
WrappedCallableStatement.java 25KB
InternalManagedConnectionPool.java 23KB
BaseConnectionManager2.java 22KB
TGroupConnection.java 22KB
MockPreparedStatement.java 21KB
ConfigManager.java 21KB
TGroupPreparedStatement.java 20KB
FJTaskRunnerGroup.java 20KB
TGroupCallableStatement.java 19KB
NavigableMap.java 19KB
CallableStatementWrapper.java 19KB
CachedConnectionManager.java 19KB
BaseWrapperManagedConnection.java 19KB
VetoableChangeMulticaster.java 19KB
FJTask.java 18KB
TGroupConnectionUnitTest.java 18KB
LocalTxDataSourceDO.java 18KB
TGroupDatabaseMetaData.java 17KB
MockDataBaseMetaData.java 17KB
TGroupStatement.java 17KB
Monitor.java 16KB
WrappedConnection.java 16KB
VirtualTable.java 16KB
StatMonitor.java 15KB
CachedCallableStatement.java 15KB
TStatementWrapper.java 15KB
DailyMaxRollingFileAppender.java 15KB
BaseWrapperManagedConnectionFactory.java 15KB
CachedPreparedStatement.java 15KB
EnumeratorImp.java 15KB
PropertyChangeMulticaster.java 14KB
LocalTxDataSource.java 14KB
NavigableSet.java 14KB
TAtomDataSourceUnitTest.java 14KB
WrappedPreparedStatement.java 14KB
SyncCollection.java 13KB
Rendezvous.java 13KB
BufferedStatLogWriter.java 13KB
AtomBufferedStatLogWriter.java 12KB
TDataSourceWrapper.java 12KB
TPreparedStatementWrapper.java 12KB
ClockDaemon.java 12KB
WrappedStatement.java 12KB
MatrixBufferedStatLogWriter.java 11KB
RowBasedReplicater.java 11KB
ConcurrentLRUHashMap.java 11KB
MockDataSource.java 11KB
AdvancedParameter.java 11KB
StatMonitorSingleHash.java 11KB
ConfigServerHelper.java 11KB
AbstractDBSelector.java 11KB
Sync.java 11KB
Channel.java 11KB
TConnectionWrapper.java 11KB
SlaveInfo.java 11KB
TGroupDataSource.java 10KB
SynchronousChannel.java 10KB
LocalManagedConnectionFactory.java 10KB
MockConnection.java 10KB
LRUHashMap.java 10KB
BoundedLinkedQueue.java 10KB
Config.java 10KB
GroovyStaticMethod.java 10KB
XidImpl.java 10KB
CyclicBarrier.java 9KB
MockStatement.java 9KB
SwingWorker.java 9KB
TMonitor.java 9KB
TransactionLocal.java 9KB
WriterPreferenceReadWriteLock.java 9KB
StringUtils.java 9KB
TAtomConfParser.java 9KB
Samples.java 9KB
EquityDbManager.java 9KB
TransactionSynchronizer.java 8KB
CRUDTest.java 8KB
共 1250 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功