1 15 package org.apache.hivemind.lib.impl; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.apache.hivemind.ApplicationRuntimeException; 21 import org.apache.hivemind.lib.RemoteExceptionCoordinator; 22 import org.apache.hivemind.lib.RemoteExceptionEvent; 23 import org.apache.hivemind.lib.RemoteExceptionListener; 24 25 30 31 public class RemoteExceptionCoordinatorImpl implements RemoteExceptionCoordinator 32 { 33 private boolean _locked; 34 private List _listeners; 35 36 private void checkLocked(String methodName) 37 { 38 if (_locked) 39 throw new ApplicationRuntimeException(ImplMessages.coordinatorLocked(methodName)); 40 } 41 42 public synchronized void addRemoteExceptionListener(RemoteExceptionListener listener) 43 { 44 checkLocked("addRemoteExceptionListener"); 45 46 if (_listeners == null) 47 _listeners = new ArrayList (); 48 49 _listeners.add(listener); 50 } 51 52 public synchronized void removeRemoteExceptionListener(RemoteExceptionListener listener) 53 { 54 checkLocked("removeRemoteExceptionListener"); 55 56 if (_listeners == null) 57 return; 58 59 _listeners.remove(listener); 60 } 61 62 public synchronized void fireRemoteExceptionDidOccur(Object source, Throwable exception) 63 { 64 checkLocked("sendNotification"); 65 66 if (_listeners == null || _listeners.size() == 0) 67 return; 68 69 RemoteExceptionEvent event = new RemoteExceptionEvent(source, exception); 70 71 int count = _listeners.size(); 72 73 _locked = true; 74 75 try 76 { 77 78 for (int i = 0; i < count; i++) 79 { 80 RemoteExceptionListener listener = (RemoteExceptionListener) _listeners.get(i); 81 82 listener.remoteExceptionDidOccur(event); 83 } 84 } 85 finally 86 { 87 _locked = false; 88 } 89 90 } 91 92 } 93 | Popular Tags |