1 8 9 package mx4j.remote; 10 11 import javax.management.Notification ; 12 import javax.management.NotificationFilter ; 13 import javax.management.NotificationListener ; 14 import javax.management.ObjectName ; 15 16 19 public class NotificationTuple 20 { 21 private static final NotificationFilter NO_FILTER = new NotificationFilter () 22 { 23 public boolean isNotificationEnabled(Notification notification) 24 { 25 return true; 26 } 27 28 public String toString() 29 { 30 return "no filter"; 31 } 32 }; 33 private static final Object NO_HANDBACK = new Object () 34 { 35 public String toString() 36 { 37 return "no handback"; 38 } 39 }; 40 41 private final ObjectName observed; 42 private final NotificationListener listener; 43 private final NotificationFilter filter; 44 private final Object handback; 45 private boolean invokeFilter; 46 47 public NotificationTuple(ObjectName observed, NotificationListener listener) 48 { 49 this(observed, listener, NO_FILTER, NO_HANDBACK); 50 } 51 52 public NotificationTuple(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) 53 { 54 this.observed = observed; 55 this.listener = listener; 56 this.filter = filter; 57 this.handback = handback; 58 this.invokeFilter = false; 59 } 60 61 public ObjectName getObjectName() 62 { 63 return observed; 64 } 65 66 public NotificationListener getNotificationListener() 67 { 68 return listener; 69 } 70 71 public Object getHandback() 72 { 73 if (handback == NO_HANDBACK) return null; 74 return handback; 75 } 76 77 public NotificationFilter getNotificationFilter() 78 { 79 if (filter == NO_FILTER) return null; 80 return filter; 81 } 82 83 public void setInvokeFilter(boolean invoke) 84 { 85 this.invokeFilter = invoke; 86 } 87 88 public boolean getInvokeFilter() 89 { 90 if (!invokeFilter) return false; 91 NotificationFilter filter = getNotificationFilter(); 92 if (filter == null) return false; 93 return true; 94 } 95 96 public boolean equals(Object obj) 97 { 98 if (this == obj) return true; 99 if (!(obj instanceof NotificationTuple)) return false; 100 101 final NotificationTuple other = (NotificationTuple)obj; 102 103 if (!observed.equals(other.observed)) return false; 104 if (!listener.equals(other.listener)) return false; 105 106 if (filter == NO_FILTER) return true; 108 if (other.filter == NO_FILTER) return true; 109 110 if (filter != null ? !filter.equals(other.filter) : other.filter != null) return false; 111 if (handback != null ? !handback.equals(other.handback) : other.handback != null) return false; 112 113 return true; 114 } 115 116 public int hashCode() 117 { 118 int result; 119 result = observed.hashCode(); 120 result = 29 * result + listener.hashCode(); 121 result = 29 * result + (filter != null ? filter.hashCode() : 0); 122 result = 29 * result + (handback != null ? handback.hashCode() : 0); 123 return result; 124 } 125 126 public String toString() 127 { 128 StringBuffer buffer = new StringBuffer ("NotificationTuple ["); 129 buffer.append(observed).append(", "); 130 buffer.append(listener).append(", "); 131 buffer.append(filter).append(", "); 132 buffer.append(handback).append("]"); 133 return buffer.toString(); 134 } 135 } 136 | Popular Tags |