Реализация TransactionManager в JINI
Я реализую двухфазную блокировку с использованием JINI. Я сделал это, следуя определению алгоритма. И в моей реализации у меня есть несколько ArrayLists и HashMap, чтобы отслеживать, какие участники совершили или прервали транзакцию.
Каждый раз, когда я выполняю операции присоединения / фиксации / прерывания, мои ArrayLists и HashMap пусты (без предыдущих участников), а HashCode моего TransactionManager всегда отличается. Я провел 2 дня в поисках проблемы и до сих пор не могу понять, почему это происходит.
// here is the implementation of join method of my TransactionManager
private HashMap<Long, ArrayList<TransactionParticipant>> _transactions = new HashMap<Long, ArrayList<TransactionParticipant>>();
private ArrayList<TransactionParticipant> _participantTest = new ArrayList<TransactionParticipant>();
@Override
public synchronized void join(long trxId, TransactionParticipant tp, long crashCount) throws UnknownTransactionException, CannotJoinException, CrashCountException, RemoteException {
// add new participant to list of participants that belong to current trxId
List<TransactionParticipant> participants = _transactions.get(trxId);
_participantTest.add(tp);
participants.add(tp);
System.out.println("Test hash code " + this.hashCode());
System.out.println("Number of participants is " + participants.size() + "for Trxid " + trxId);
System.out.println("Number of participants in other is " + _participantTest.size() + "for Trxid " + trxId);
}
Следующий код используется для "публикации" моего TransactionManager
String[] groups = { "group" };
ServiceInfo serviceInfo = new ServiceInfo(
"twoPhaseTrxManager",
"a",
"b",
"1.0",
"Join Manager",
"c");
Entry[] entries = new Entry[] { serviceInfo };
LookupDiscoveryManager lookupDiscoveryManager = new LookupDiscoveryManager(groups, null, null);
// "this" (first argument) refers to Current instance of transaction manager (object being published)
new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );
Любая помощь действительно ценится.
1 ответ
Решение
Я смог решить проблему, изменив это:
new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );
к этому:
new JoinManager(RemoteObject.toStub(this), entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );