⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactionmanager.java

📁 java pos,你可以直接编译运行,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    List participants = new ArrayList();                    while (st.hasMoreTokens ()) {                        String grp = st.nextToken();                        addGroup (id, grp);                        participants.addAll (getParticipants (grp));                    }                    iter = participants.iterator();                    continue;                }            }        }        return members.size() == 0 ? NO_JOIN : (abort ? ABORTED : PREPARED);    }    protected List getParticipants (String groupName) {        List participants = (List) groups.get (groupName);        if (participants == null)            participants = new ArrayList();        return participants;    }    protected List getParticipants (long id) {        List participants = getParticipants (DEFAULT_GROUP);        String key = getKey(GROUPS, id);        String grp = null;        while ( (grp = (String) psp.inp (key)) != null) {            participants.addAll (getParticipants (grp));        }        return participants;    }    protected void initParticipants (Element config)         throws ConfigurationException    {        groups.put (DEFAULT_GROUP,  initGroup (config));        Iterator iter = config.getChildren ("group").iterator();        while (iter.hasNext()) {            Element e = (Element) iter.next();            String name = e.getAttributeValue ("name");            if (name == null)                 throw new ConfigurationException ("missing group name");            if (groups.get (name) != null) {                throw new ConfigurationException (                    "Group '" + name + "' already defined"                );            }            groups.put (name, initGroup (e));        }    }    protected ArrayList initGroup (Element e)         throws ConfigurationException    {        ArrayList group = new ArrayList ();        Iterator iter = e.getChildren ("participant").iterator();        while (iter.hasNext()) {            group.add (createParticipant ((Element) iter.next()));        }        return group;    }    protected TransactionParticipant createParticipant (Element e)         throws ConfigurationException    {        QFactory factory = getFactory();        TransactionParticipant participant = (TransactionParticipant)             factory.newInstance (e.getAttributeValue ("class")        );        factory.setLogger (participant, e);        factory.setConfiguration (participant, e);        return participant;    }    protected String getKey (String prefix, long id) {        StringBuffer sb = new StringBuffer (prefix);        sb.append (Long.toString (id));        return sb.toString ();    }    protected long initCounter (String name, long defValue) {        Long L = (Long) psp.rdp (name);        if (L == null) {            L = new Long (defValue);            psp.out (name, L);        }        return L.longValue();    }    protected void commitOff (Space sp) {        if (sp instanceof JDBMSpace) {            ((JDBMSpace) sp).setAutoCommit (false);        }    }    protected void commitOn (Space sp) {        if (sp instanceof JDBMSpace) {            JDBMSpace jsp = (JDBMSpace) sp;            jsp.commit ();            jsp.setAutoCommit (true);        }    }    protected void syncTail () {        synchronized (psp) {            commitOff (psp);            psp.inp (TAIL);            psp.out (TAIL, new Long (tail));            commitOn (psp);        }    }    protected void initTailLock () {        SpaceUtil.wipe (sp, tailLock);        sp.out (tailLock, TAILLOCK);    }    protected void checkTail () {        Object lock = sp.in (tailLock);        while (tailDone()) {            tail++;        }        syncTail ();        sp.out (tailLock, lock);    }    protected boolean tailDone () {        String stateKey = getKey (STATE, tail);        Integer state = (Integer) psp.rdp (stateKey);        if (DONE.equals (psp.rdp (stateKey))) {            purge (tail);            return true;        }        return false;    }    protected long nextId () {        long h;        synchronized (psp) {            commitOff (psp);            psp.in  (HEAD);            h = head;            psp.out (HEAD, new Long (++head));            commitOn (psp);        }        return h;    }    protected void snapshot (long id, Serializable context) {        snapshot (id, context, null);    }    protected void snapshot (long id, Serializable context, Integer status) {        String contextKey = getKey (CONTEXT, id);        synchronized (psp) {            commitOff (psp);            while (psp.inp (contextKey) != null)                ;            if (context != null)                psp.out (contextKey, context);            if (status != null) {                String stateKey  = getKey (STATE, id);                while (psp.inp (stateKey) != null)                    ;                psp.out (stateKey, status);            }            commitOn (psp);        }    }    protected void setState (long id, Integer state) {        String stateKey  = getKey (STATE, id);        synchronized (psp) {            commitOff (psp);            while (psp.inp (stateKey) != null)                ;            if (state!= null)                psp.out (stateKey, state);            commitOn (psp);        }    }    protected void addGroup (long id, String groupName) {        if (groupName != null)            psp.out (getKey (GROUPS, id), groupName);    }    protected void purge (long id) {        String stateKey   = getKey (STATE, id);        String contextKey = getKey (CONTEXT, id);        String groupsKey  = getKey (GROUPS, id);        synchronized (psp) {            commitOff (psp);            while (psp.inp (stateKey) != null)                ;            while (psp.inp (contextKey) != null)                ;            while (psp.inp (groupsKey) != null)                ;            commitOn (psp);        }    }    protected void recover () {        if (tail < head) {            getLog().info ("recover - tail=" +tail+", head="+head);        }        while (tail < head) {            recover (tail++);        }        syncTail ();    }    protected void recover (long id) {        LogEvent evt = getLog().createLogEvent ("recover");        evt.addMessage ("<id>" + id + "</id>");        try {            String stateKey   = getKey (STATE, id);            String contextKey = getKey (CONTEXT, id);            Integer state = (Integer) psp.rdp (stateKey);            if (state == null) {                evt.addMessage ("<unknown/>");                SpaceUtil.wipe (psp, contextKey);   // just in case ...                return;            }            Serializable context = (Serializable) psp.rdp (contextKey);            if (context != null)                evt.addMessage (context);            if (DONE.equals (state)) {                evt.addMessage ("<done/>");            } else if (COMMITTING.equals (state)) {                evt.addMessage ("<commit/>");                commit (id, context, getParticipants (id), true);            } else if (PREPARING.equals (state)) {                evt.addMessage ("<abort/>");                abort (id, context, getParticipants (id), true);            }            purge (id);        } finally {            Logger.log (evt);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -