View Javadoc

1   /*
2    * $Id: ListenerSubscriptionPair.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.context.notification;
12  
13  import org.mule.api.context.notification.ServerNotificationListener;
14  import org.mule.util.ClassUtils;
15  
16  /**
17   * A simple tuple that stores a listener with an optional subscription (used to match a resource ID).
18   */
19  public class ListenerSubscriptionPair
20  {
21  
22      private ServerNotificationListener listener;
23      private String subscription = ServerNotificationManager.NULL_SUBSCRIPTION;
24      private boolean nullSubscription = true;
25  
26      /**
27       * For config - must be constructed using the setters
28       */
29      public ListenerSubscriptionPair()
30      {
31          super();
32      }
33  
34      public ListenerSubscriptionPair(ServerNotificationListener listener)
35      {
36          setListener(listener);
37      }
38  
39      public ListenerSubscriptionPair(ServerNotificationListener listener, String subscription)
40      {
41          setListener(listener);
42          setSubscription(subscription);
43      }
44  
45      public void setListener(ServerNotificationListener listener)
46      {
47          this.listener = listener;
48      }
49  
50      public void setSubscription(String subscription)
51      {
52          if (null != subscription)
53          {
54              this.subscription = subscription;
55              nullSubscription = false;
56          }
57      }
58  
59      public ServerNotificationListener getListener()
60      {
61          return listener;
62      }
63  
64      public String getSubscription()
65      {
66          return subscription;
67      }
68  
69      public boolean isNullSubscription()
70      {
71          return nullSubscription;
72      }
73  
74      @Override
75      public int hashCode()
76      {
77          return ClassUtils.hash(new Object[]{listener, subscription, nullSubscription});
78      }
79  
80      @Override
81      public boolean equals(Object obj)
82      {
83          if (this == obj)
84          {
85              return true;
86          }
87          if (obj == null || getClass() != obj.getClass())
88          {
89              return false;
90          }
91  
92          ListenerSubscriptionPair other = (ListenerSubscriptionPair) obj;
93          return ClassUtils.equal(listener, other.listener) 
94              && ClassUtils.equal(subscription, other.subscription)
95              && (nullSubscription == other.nullSubscription);
96      }
97  
98      @Override
99      public String toString()
100     {
101         return "ListenerSubscriptionPair [listener=" + listener + ", subscription=" + subscription + "]";
102     } 
103 
104 }