简体   繁体   English

在JINI中实现TransactionManager

[英]Implementing TransactionManager in JINI

I'm implementing Two-Phase Lock using JINI. 我正在使用JINI实现两阶段锁定。 I've done it by following algorithm definition. 我通过遵循算法定义来做到这一点。 And in my implementation I have a few ArrayLists and HashMap to track which participants has committed or aborted transaction. 在我的实现中,我有一些ArrayLists和HashMap可以跟踪哪些参与者已提交或中止事务。

Every time I do join/commit/abort operations, my ArrayLists and HashMap are empty (no previous participants) and HashCode of my TransactionManager is always different. 每次执行加入/提交/中止操作时,我的ArrayLists和HashMap都是空的(没有以前的参与者),而TransactionManager的HashCode总是不同的。 I spent 2 days looking for a problem and still can't understand why this is happening. 我花了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);
    }

The following code is used to "publish" my TransactionManager 以下代码用于“发布”我的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() ); 

Any help is truly appreciated. 任何帮助,我们都感激不尽。

I was able to solve the problem by changing this: 我可以通过更改以下方法解决问题:

new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() ); 

to this: 对此:

new JoinManager(RemoteObject.toStub(this), entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM