001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package mx4j.remote;
010:
011: import javax.management.Notification;
012: import javax.management.NotificationFilter;
013: import javax.management.NotificationListener;
014: import javax.management.ObjectName;
015:
016: /**
017: * @version $Revision: 1.5 $
018: */
019: public class NotificationTuple {
020: private static final NotificationFilter NO_FILTER = new NotificationFilter() {
021: public boolean isNotificationEnabled(Notification notification) {
022: return true;
023: }
024:
025: public String toString() {
026: return "no filter";
027: }
028: };
029: private static final Object NO_HANDBACK = new Object() {
030: public String toString() {
031: return "no handback";
032: }
033: };
034:
035: private final ObjectName observed;
036: private final NotificationListener listener;
037: private final NotificationFilter filter;
038: private final Object handback;
039: private boolean invokeFilter;
040:
041: public NotificationTuple(ObjectName observed,
042: NotificationListener listener) {
043: this (observed, listener, NO_FILTER, NO_HANDBACK);
044: }
045:
046: public NotificationTuple(ObjectName observed,
047: NotificationListener listener, NotificationFilter filter,
048: Object handback) {
049: this .observed = observed;
050: this .listener = listener;
051: this .filter = filter;
052: this .handback = handback;
053: this .invokeFilter = false;
054: }
055:
056: public ObjectName getObjectName() {
057: return observed;
058: }
059:
060: public NotificationListener getNotificationListener() {
061: return listener;
062: }
063:
064: public Object getHandback() {
065: if (handback == NO_HANDBACK)
066: return null;
067: return handback;
068: }
069:
070: public NotificationFilter getNotificationFilter() {
071: if (filter == NO_FILTER)
072: return null;
073: return filter;
074: }
075:
076: public void setInvokeFilter(boolean invoke) {
077: this .invokeFilter = invoke;
078: }
079:
080: public boolean getInvokeFilter() {
081: if (!invokeFilter)
082: return false;
083: NotificationFilter filter = getNotificationFilter();
084: if (filter == null)
085: return false;
086: return true;
087: }
088:
089: public boolean equals(Object obj) {
090: if (this == obj)
091: return true;
092: if (!(obj instanceof NotificationTuple))
093: return false;
094:
095: final NotificationTuple other = (NotificationTuple) obj;
096:
097: if (!observed.equals(other.observed))
098: return false;
099: if (!listener.equals(other.listener))
100: return false;
101:
102: // Special treatment for special filter
103: if (filter == NO_FILTER)
104: return true;
105: if (other.filter == NO_FILTER)
106: return true;
107:
108: if (filter != null ? !filter.equals(other.filter)
109: : other.filter != null)
110: return false;
111: if (handback != null ? !handback.equals(other.handback)
112: : other.handback != null)
113: return false;
114:
115: return true;
116: }
117:
118: public int hashCode() {
119: int result;
120: result = observed.hashCode();
121: result = 29 * result + listener.hashCode();
122: result = 29 * result + (filter != null ? filter.hashCode() : 0);
123: result = 29 * result
124: + (handback != null ? handback.hashCode() : 0);
125: return result;
126: }
127:
128: public String toString() {
129: StringBuffer buffer = new StringBuffer("NotificationTuple [");
130: buffer.append(observed).append(", ");
131: buffer.append(listener).append(", ");
132: buffer.append(filter).append(", ");
133: buffer.append(handback).append("]");
134: return buffer.toString();
135: }
136: }
|