本文整理汇总了C#中Transaction.getRequests方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.getRequests方法的具体用法?C# Transaction.getRequests怎么用?C# Transaction.getRequests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.getRequests方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: prepare
//Participant prepare function invoked by a coordinator.
public void prepare(Transaction t, string coordinatorURL)
{
TransactionInfo tInfo = new TransactionInfo(t);
_transactions.Add(t.getTicket(), tInfo);
checkStatus();
_prevStatus = _status;
tInfo._coordinatorURL = coordinatorURL;
bool selfinvolved = false;
foreach (Request r in t.getRequests())
{
PadIntValue value;
if (_padInts.TryGetValue(r.involved(), out value))
{
selfinvolved = true;
if (r.isWrite())
{
value.setValue(r.getVal());
tInfo._valuesToBeChanged.Add(value);
Console.WriteLine("Preparing write to padint " + value.getId() + " the value " + value.getValue());
}
else
{
Console.WriteLine("Preparing Read of padint " + value.getId() + "it has the value " + value.getValue());
}
}
}
if (selfinvolved)
{
Console.WriteLine("###############");
Console.WriteLine("adding uncomm trans Prepare");
Console.WriteLine("t Request Count: " + t.getRequests().Count());
Console.WriteLine("t Ticket: " + t.getTicket());
Console.WriteLine("t TimeStamp: " + t.getTimeStamp());
Console.WriteLine("###############");
Console.WriteLine("");
//add transaction t to the list of uncommited transactions and the ticket to the tickets seen list
if(!_transactionsUncommited.Contains(t))
_transactionsUncommited.Add(t);
}
addTicketToList(t.getTicket());
removeTicketSequence();
try
{
RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
typeof(RemoteServerInterface), coordinatorURL);
serv.prepared(t.getTicket(), _ownURL, true);
}
catch(TxException e)
{
Console.WriteLine("Failed at remote prepare");
throw e;
}
_transactions[t.getTicket()] = tInfo;
}
示例2: validateLocal
public void validateLocal(Transaction t)
{
TransactionInfo tInfo = _transactions[t.getTicket()];
RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
typeof(RemoteServerInterface), tInfo._coordinatorURL);
tInfo._transactionsUncommited.Clear();
tInfo._transactionsUncommited.AddRange(_transactionsUncommited);
//Start the validating proccess
if (!(t.getTicket() <= _lastTicketTrans))
{
tInfo._lastTicketSeen = _lastTicketTrans;
tInfo._unComTransHandles = new AutoResetEvent[t.getTicket() - tInfo._lastTicketSeen];
for (int i = 0; i < tInfo._handlerID; i++)
{
tInfo._unComTransHandles[i] = new AutoResetEvent(false);
}
if (!WaitHandle.WaitAll(tInfo._unComTransHandles, 2000))
serv.validated(t.getTicket(), _ownURL, false);
}
// check if the transaction is in conflict with any uncommited transaction before me
foreach (Transaction tran_last in tInfo._transactionsUncommited)
{
if (tran_last.getTicket() < t.getTicket())
{
foreach (Request req_last in tran_last.getRequests())
foreach (Request req_act in t.getRequests())
if (req_last.involved() == req_act.involved() && req_last.isWrite() == req_act.isWrite())
serv.validated(t.getTicket(), _ownURL, false);
}
}
serv.validated(t.getTicket(), _ownURL, true);
_transactions[t.getTicket()] = tInfo;
}
示例3: commit
//.........这里部分代码省略.........
Console.WriteLine("###############");
Console.WriteLine("");
if(validate(ticket))
{
foreach (String p in tInfo._participants)
{
try
{
Console.WriteLine("###############");
Console.WriteLine("InsideForeachParticipant");
Console.WriteLine("###############");
Console.WriteLine("");
RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
typeof(RemoteServerInterface), p);
RemoteAsyncCommitLocalChanges prep = new RemoteAsyncCommitLocalChanges(serv.commitLocalChanges);
prep.BeginInvoke(t.getTicket(), null, null);
}
catch(TxException e)
{
Console.WriteLine(e.Message);
throw e;
}
}
Console.WriteLine("###############");
Console.WriteLine("Before HandleReception");
Console.WriteLine("###############");
Console.WriteLine("");
if (tInfo._participants.Count() > 0)
{
if (!WaitHandle.WaitAll(tInfo._handles, 2000))
throw new TxException("Receiving Commit failed");
resetHandles(t.getTicket());
}
tInfo = _transactions[ticket];
//Commiting local changes
foreach (PadIntValue item in tInfo._valuesToBeChanged)
{
_padInts[(item.getId())].setValue(item.getValue());
}
Console.WriteLine("###############");
Console.WriteLine("After Handle Reception");
Console.WriteLine("###############");
Console.WriteLine("");
Console.WriteLine("###############");
Console.WriteLine("Before Removing from uncom trans");
Console.WriteLine("t Request Count: " + t.getRequests().Count());
Console.WriteLine("t Ticket: " + t.getTicket());
Console.WriteLine("t TimeStamp: " + t.getTimeStamp());
Console.WriteLine("###############");
Console.WriteLine("");
if (_transactionsUncommited.Contains(t))
{
Console.WriteLine("###############");
Console.WriteLine("Removing from uncom trans");
Console.WriteLine("###############");
Console.WriteLine("");
_transactionsUncommited.Remove(t);
}
tInfo._transactionsUncommited.Clear();
_transactions[ticket] = tInfo;
Console.WriteLine("###############");
Console.WriteLine("After Removing from uncom trans");
Console.WriteLine("###############");
Console.WriteLine("");
_prevStatus = STATE.ALIVE;
_status = STATE.ALIVE;
_transactions.Remove(tInfo._transaction.getTicket());
//tInfo._participants.Clear();
//tInfo._valuesToBeChanged.Clear();
//tInfo._handles = null;
//tInfo._validatehandles = null;
//tInfo._unComTransHandles = null;
//tInfo._partHandlers.Clear();
//tInfo._Transaction = null;
//tInfo._coordinatorURL = null;
checkReplica();
RemoteServerInterface serverR = (RemoteServerInterface)Activator.GetObject(
typeof(RemoteServerInterface), _replicaURL);
RemoteAsyncReplicated repli = new RemoteAsyncReplicated(serverR.replicatedInfo);
repli.BeginInvoke(_padInts, null, null);
Console.WriteLine("Transaction Successfull.");
return true;
}
else
{
Console.WriteLine("last ticket seen: " + _lastTicketTrans);
Console.WriteLine("trans ticket " + t.getTicket());
return abort(ticket);
}
}