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