KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > rmi > ClientListenerHolder


1 package org.jboss.mx.remoting.rmi;
2
3 import javax.management.ObjectName JavaDoc;
4 import javax.management.NotificationListener JavaDoc;
5 import javax.management.NotificationFilter JavaDoc;
6
7 /**
8  * This is a holder for the listener and related information to
9  * be stored on the client side for when notifications are received
10  * from the server. This will help in making sure the correct information
11  * is supplied back to original listener when calling to handle notifications.
12  *
13  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
14  */

15 public class ClientListenerHolder
16 {
17    private ObjectName JavaDoc targetMBean;
18    private NotificationListener JavaDoc listener;
19    private NotificationFilter JavaDoc filter;
20    private Object JavaDoc handback;
21    private boolean filterOnClient = false;
22
23    public ClientListenerHolder(ObjectName JavaDoc objectName, NotificationListener JavaDoc listener,
24                                NotificationFilter JavaDoc filter, Object JavaDoc handback)
25    {
26       this.targetMBean = objectName;
27       this.listener = listener;
28       this.filter = filter;
29       this.handback = handback;
30    }
31
32    /**
33     * returns the the hashcode based on target mbean, filter, and handback.
34     */

35    public int hashCode()
36    {
37       int hashcode = targetMBean.hashCode() + listener.hashCode() + (filter != null ? filter.hashCode() : 0) + (handback != null ? handback.hashCode() : 0);
38       return hashcode;
39    }
40
41    /**
42     * Will check to see object passed is a ClientListenerHolder and
43     */

44    public boolean equals(Object JavaDoc obj)
45    {
46       if(obj != null)
47       {
48          if(obj instanceof ClientListenerHolder)
49          {
50             ClientListenerHolder holder = (ClientListenerHolder)obj;
51             if(targetMBean.equals(holder.getObjectName()) &&
52                listener.equals(holder.getListener()))
53             {
54                if(filter != null)
55                {
56                   if(filter.equals(holder.getFilter()))
57                   {
58                      if(handback != null)
59                      {
60                         return handback.equals(holder.getHandback());
61                      }
62                      else
63                      {
64                         if(holder.getHandback() == null)
65                         {
66                            return true;
67                         }
68                         else
69                         {
70                            return false;
71                         }
72                      }
73                   }
74                   else
75                   {
76                      return false;
77                   }
78                }
79                else
80                {
81                   if(holder.getFilter() == null)
82                   {
83                      if(handback != null)
84                      {
85                         return handback.equals(holder.getHandback());
86                      }
87                      else
88                      {
89                         if(holder.getHandback() == null)
90                         {
91                            return true;
92                         }
93                         else
94                         {
95                            return false;
96                         }
97                      }
98                   }
99                   else
100                   {
101                      return false;
102                   }
103                }
104             }
105             else
106             {
107                return false;
108             }
109          }
110          else
111          {
112             return false;
113          }
114       }
115       else
116       {
117          return false;
118       }
119    }
120
121    public NotificationListener JavaDoc getListener()
122    {
123       return listener;
124    }
125
126    public NotificationFilter JavaDoc getFilter()
127    {
128       return filter;
129    }
130
131    public Object JavaDoc getHandback()
132    {
133       return handback;
134    }
135
136    public ObjectName JavaDoc getObjectName()
137    {
138       return targetMBean;
139    }
140
141    public void setFilterOnClient(boolean shouldFilterOnClient)
142    {
143       filterOnClient = shouldFilterOnClient;
144    }
145
146    public boolean getFilterOnClient()
147    {
148       return filterOnClient;
149    }
150 }
151
Popular Tags