Package org.objectweb.speedo.workingset.lib

Source Code of org.objectweb.speedo.workingset.lib.TxObserverImpl

/**
* Copyright (C) 2001-2005 France Telecom R&D
*/
package org.objectweb.speedo.workingset.lib;

import org.objectweb.perseus.persistence.api.VirtualState;
import org.objectweb.perseus.persistence.api.WorkingSet;
import org.objectweb.speedo.mim.api.LifeCycle;
import org.objectweb.speedo.mim.api.StateItf;

import java.util.Iterator;

public class TxObserverImpl extends WorkingSetStatistic {

    private final static String WORD = "/ pnc: ";
    private final static int WORD_LENGTH = WORD.length();
   
    private StringBuffer sb = new StringBuffer();
   
    public TxObserverImpl() {
        super();
    }

    public void transactionEnded(Object tx, int s, Boolean validate) {
        super.transactionEnded(tx, s, validate);
        WorkingSet ws = (WorkingSet) tx;
        sb.delete(0, sb.length());
        sb.append("\n\t- oids: [");
        String sep = "";
        for (Iterator iter = ws.oids().iterator(); iter.hasNext();) {
            Object oid = iter.next();
            org.objectweb.perseus.persistence.api.State sa = (org.objectweb.perseus.persistence.api.State) ws.lookup(oid);
            sb.append(sep);
            sep = "\n\t\t";
            if (sa != VirtualState.instance) {
                if (LifeCycle.isDirty(((StateItf) sa).speedoGetStatus())) {
                    sb.append("M ");
                }
            }
            sb.append(oid2str(oid));
        }
        sb.append("]");
    }

    private String oid2str(Object oid) {
        if (oid == null) {
            return null;
        }
        final String s = oid.toString();
        final int idx = s.indexOf(WORD);
        if (idx == -1) {
            return s;
        } else {
            return s.substring(idx + WORD_LENGTH);
        }
       
    }
   
    protected StringBuffer getStatistic() {
        return super.getStatistic().append(sb);
    }
}
TOP

Related Classes of org.objectweb.speedo.workingset.lib.TxObserverImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.