00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.benchmarks.timit.util.observing;
00032
00033 import java.util.Vector;
00034
00042 public class RealEventObservable implements EventObservable {
00043 private boolean changed = false;
00044
00045 private Vector<EventObserver> eventDataObservers;
00046
00049 public RealEventObservable() {
00050 this.eventDataObservers = new Vector<EventObserver>();
00051 }
00052
00064 public synchronized void addObserver(EventObserver o) {
00065 if (o == null) {
00066 throw new NullPointerException();
00067 }
00068 if (!this.eventDataObservers.contains(o)) {
00069 this.eventDataObservers.addElement(o);
00070 }
00071 }
00072
00080 public synchronized void deleteObserver(EventObserver o) {
00081 this.eventDataObservers.removeElement(o);
00082 }
00083
00099 public void notifyObservers() {
00100 this.notifyObservers(null);
00101 }
00102
00118 public void notifyObservers(Object arg) {
00119
00120
00121
00122
00123 Object[] arrLocal;
00124 this.setChanged();
00125 synchronized (this) {
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 if (!this.changed) {
00137 return;
00138 }
00139 arrLocal = this.eventDataObservers.toArray();
00140 this.clearChanged();
00141 }
00142
00143 for (int i = arrLocal.length - 1; i >= 0; i--) {
00144 ((EventObserver) arrLocal[i]).update(this, arg);
00145 }
00146 }
00147
00151 public synchronized void deleteObservers() {
00152 this.eventDataObservers.removeAllElements();
00153 }
00154
00159 public synchronized void setChanged() {
00160 this.changed = true;
00161 }
00162
00173 public synchronized void clearChanged() {
00174 this.changed = false;
00175 }
00176
00187 public synchronized boolean hasChanged() {
00188 return this.changed;
00189 }
00190
00196 public synchronized int countObservers() {
00197 return this.eventDataObservers.size();
00198 }
00199
00206 public synchronized EventDataBag getEventDataBag(int subjectRank) {
00207 EventDataBag result = new EventDataBag(subjectRank);
00208 Vector<EventData> v = new Vector<EventData>();
00209 EventObserver eventDataObserver = null;
00210 EventData eventData = null;
00211 for (int i = 0; i < this.eventDataObservers.size(); i++) {
00212 eventDataObserver = this.eventDataObservers.get(i);
00213 if (eventDataObserver == null) {
00214 throw new NullPointerException();
00215 } else {
00216 eventData = eventDataObserver.getEventData();
00217 if (eventData == null) {
00218 throw new NullPointerException();
00219 } else {
00220 v.add(eventData);
00221 }
00222 }
00223 }
00224 result.setBag(v);
00225 return result;
00226 }
00227 }