01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: */package org.objectweb.speedo.workingset.lib;
04:
05: import org.objectweb.perseus.persistence.api.VirtualState;
06: import org.objectweb.perseus.persistence.api.WorkingSet;
07: import org.objectweb.speedo.mim.api.LifeCycle;
08: import org.objectweb.speedo.mim.api.StateItf;
09:
10: import java.util.Iterator;
11:
12: public class TxObserverImpl extends WorkingSetStatistic {
13:
14: private final static String WORD = "/ pnc: ";
15: private final static int WORD_LENGTH = WORD.length();
16:
17: private StringBuffer sb = new StringBuffer();
18:
19: public TxObserverImpl() {
20: super ();
21: }
22:
23: public void transactionEnded(Object tx, int s, Boolean validate) {
24: super .transactionEnded(tx, s, validate);
25: WorkingSet ws = (WorkingSet) tx;
26: sb.delete(0, sb.length());
27: sb.append("\n\t- oids: [");
28: String sep = "";
29: for (Iterator iter = ws.oids().iterator(); iter.hasNext();) {
30: Object oid = iter.next();
31: org.objectweb.perseus.persistence.api.State sa = (org.objectweb.perseus.persistence.api.State) ws
32: .lookup(oid);
33: sb.append(sep);
34: sep = "\n\t\t";
35: if (sa != VirtualState.instance) {
36: if (LifeCycle
37: .isDirty(((StateItf) sa).speedoGetStatus())) {
38: sb.append("M ");
39: }
40: }
41: sb.append(oid2str(oid));
42: }
43: sb.append("]");
44: }
45:
46: private String oid2str(Object oid) {
47: if (oid == null) {
48: return null;
49: }
50: final String s = oid.toString();
51: final int idx = s.indexOf(WORD);
52: if (idx == -1) {
53: return s;
54: } else {
55: return s.substring(idx + WORD_LENGTH);
56: }
57:
58: }
59:
60: protected StringBuffer getStatistic() {
61: return super.getStatistic().append(sb);
62: }
63: }
|