wsadmin スクリプトを使用したアクティブ・トランザクションおよび準備済みトランザクションの管理
wsadmin スクリプトを使用して、管理者による処置が必要になる場合があるアクティブ・トランザクションと準備済みトランザクションを管理します。
始める前に
このタスクについて
通常の環境では、トランザクションは自動的に実行され、自動的に完了 (コミットまたはロールバック) するので、特に介入する必要はありません。
ただし、環境によっては、トランザクションを手動で解決する必要があります。
例えば、必要な時間フレーム内に再び使用可能にならないことが明らかなリソース・マネージャーをポーリングしてトランザクションが動作を停止した場合は、トランザクションをロールバックします。
通常の環境では、トランザクションはあらゆる手段によって終了されます。
ただし、リソース・リカバリー・サービス (RRS) およびネイティブ・コンテキスト・フィニッシングにより、トランザクションを終了できない場合があります。 この場合、次の使用可能なウィンドウでロールバックされるように、トランザクションには rollback_only のマークが付加されます。
このほかの場合、トランザクションを手動で終了する必要がある場合があります。
例えば、必要な時間フレーム内に再び使用可能にならないことが明らかなリソース・マネージャーをポーリングしてトランザクションが動作を停止した場合は、トランザクションを終了します。
TransactionService MBean および Transaction MBean について詳しくは、アプリケーション・プログラミング・インターフェース (API) の文書を参照してください。
手順
例
以下のスクリプトは、TransactionService MBean と Transaction MBean の使用方法を示して、手動のトランザクションで処理する例です。このスクリプトは、アプリケーション・サーバーに対してのみ実行し、デプロイメント・マネージャーまたはノード・エージェントに対しては実行しないでください。
# get the TransactionService MBean
set servicembean [$AdminControl queryNames type=TransactionService,*]
# get the Transaction MBean
set mbean [$AdminControl queryNames type=Transaction,*]
set input 0
while {$input >= 0} {
# invoke the listManualTransactions method
set tranManualList [$AdminControl invoke $servicembean listManualTransactions]
if {[llength $tranManualList] > 0} {
puts "----Manual Transaction details---------------"
set index 0
foreach tran $tranManualList {
puts " Index= $index tran= $tran"
incr index
}
puts "----End of Manual Transactions ---------------"
puts "Select index of transaction to commit/rollback:"
set input [gets stdin]
if {$input < 0} {
puts "No index selected, exiting."
} else {
set tran [lindex $tranManualList $input]
set commaPos [expr [string first "," $tran ]-1]
set localTID [string range $tran 0 $commaPos]
puts "Enter c to commit or r to rollback Transaction $localTID"
set input [gets stdin]
if {$input=="c"} {
puts "Committing transaction=$localTID"
$AdminControl invoke $mbean commit $localTID
}
if {$input=="r"} {
puts "Rolling back transaction=$localTID"
$AdminControl invoke $mbean rollback $localTID
}
}
} else {
puts "No Manual transactions found, exiting"
set input -1
}
puts " "
}
import sys
def wsadminToList(inStr):
outList=[]
if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
tmpList = inStr[1:-1].split(" ")
else:
tmpList = inStr.split("¥n") #splits for Windows or Linux
for item in tmpList:
item = item.rstrip(); #removes any Windows "¥r"
if (len(item)>0):
outList.append(item)
return outList
#endDef
servicembean = AdminControl.queryNames("type=TransactionService,*" )
mbean = AdminControl.queryNames("type=Transaction,*" )
input = 0
while (input >= 0):
tranList = wsadminToList(AdminControl.invoke(servicembean, "listManualTransactions" ))
tranLength = len(tranList)
if (tranLength > 0):
print "----Manual Transaction details---------------"
index = 0
for tran in tranList:
print " Index=" , index , " tran=" , tran
index = index+1
#endFor
print "----End of Manual Transactions ---------------"
print "Select index of transaction to commit/rollback:"
input = sys.stdin.readline().strip()
if (input == ""):
print "No index selected, exiting."
input = -1
else:
tran = tranList[int(input)]
commaPos = (tran.find(",") -1)
localTID = tran[0:commaPos+1]
print "Enter c to commit or r to rollback transaction ", localTID
input = sys.stdin.readline().strip()
if (input == "c"):
print "Committing transaction=", localTID
AdminControl.invoke(mbean, "commit", localTID )
#endIf
elif (input == "r"):
print "Rolling back transaction=", localTID
AdminControl.invoke(mbean, "rollback", localTID )
#endIf
else:
input = -1
#endelse
#endElse
else:
print "No transactions found, exiting"
input = -1
#endElse
print " "
#endWhile