1 22 package test.implementation.notification.support; 23 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 27 import javax.management.Notification ; 28 import javax.management.NotificationListener ; 29 30 35 public class Listener 36 implements NotificationListener 37 { 38 40 43 public HashMap notifications = new HashMap (); 44 45 public boolean waiting = false; 46 47 49 52 public Listener() 53 { 54 } 55 56 58 61 public void handleNotification(Notification notification, Object handback) 62 { 63 doWait(true); 64 65 synchronized(notifications) 66 { 67 ArrayList received = (ArrayList ) notifications.get(handback); 68 if (received == null) 69 { 70 received = new ArrayList (); 71 notifications.put(handback, received); 72 } 73 received.add(notification); 74 } 75 76 doNotify(false); 77 } 78 79 public synchronized void doWait(boolean value) 80 { 81 try 82 { 83 waiting = value; 84 this.wait(); 85 } 86 catch (InterruptedException e) 87 { 88 throw new RuntimeException (e.toString()); 89 } 90 } 91 92 public synchronized void doNotify(boolean expected) 93 { 94 try 95 { 96 while (waiting != expected) 97 this.wait(10); 98 this.notifyAll(); 99 } 100 catch (InterruptedException e) 101 { 102 throw new RuntimeException (e.toString()); 103 } 104 } 105 } 106 | Popular Tags |