|
Revision 2738, 3.3 KB
(checked in by chf, 15 months ago)
|
|
Some cleanups and refactorings. More to come
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.interpreter.evaluator.transactions; |
|---|
| 19 | import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunner; |
|---|
| 20 | import java.util.AbstractSet; |
|---|
| 21 | import java.util.concurrent.CopyOnWriteArrayList; |
|---|
| 22 | |
|---|
| 23 | public class ReadSet extends AbstractSet<Transaction> { |
|---|
| 24 | private CopyOnWriteArrayList<Transaction> elements; |
|---|
| 25 | private Boolean sealed; |
|---|
| 26 | |
|---|
| 27 | public ReadSet() { |
|---|
| 28 | sealed = false; |
|---|
| 29 | elements = new CopyOnWriteArrayList<Transaction>(); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | public ReadSet(ReadSet r) { |
|---|
| 34 | sealed = false; |
|---|
| 35 | elements = new CopyOnWriteArrayList<Transaction>(); |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | if (r != null) |
|---|
| 40 | myAdd(r); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | private void myAdd(ReadSet r) { |
|---|
| 44 | for (Transaction t : elements) |
|---|
| 45 | if (t.isActive()) |
|---|
| 46 | elements.add(t); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public String toString() { |
|---|
| 50 | return "sealed = " + sealed + " elements = " + elements; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | public void copyFrom(ReadSet aSet) { |
|---|
| 59 | elements.addAll(aSet.elements); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public void seal() { |
|---|
| 63 | sealed = true; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | public boolean add(Transaction t) { |
|---|
| 72 | cleanup(); |
|---|
| 73 | if (sealed) { |
|---|
| 74 | FortressTaskRunner.debugPrintln("add of " + t + " to readset " + toString() + " failed because readset was sealed"); |
|---|
| 75 | Thread.dumpStack(); |
|---|
| 76 | return false; |
|---|
| 77 | } else { |
|---|
| 78 | elements.addIfAbsent(t); |
|---|
| 79 | return true; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public void cleanup() { |
|---|
| 84 | for (Transaction t : elements) |
|---|
| 85 | if (!t.isActive()) |
|---|
| 86 | remove(t); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | public boolean remove(Transaction t) { |
|---|
| 95 | boolean res = elements.contains(t); |
|---|
| 96 | if (res) elements.remove(t); |
|---|
| 97 | return res; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | public void clear() { |
|---|
| 104 | elements.clear(); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | public int size() { |
|---|
| 112 | return elements.size(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | public java.util.Iterator<Transaction> iterator() { |
|---|
| 120 | return elements.iterator(); |
|---|
| 121 | } |
|---|
| 122 | } |
|---|