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.ServerNotification;
10  import org.mule.routing.filters.WildcardFilter;
11  
12  /**
13   * This does the work necessary to deliver events to a particular listener.  It is generated for a
14   * particular {@link Configuration} and stored in a
15   * {@link org.mule.context.notification.Policy}.
16   */
17  class Sender
18  {
19  
20      private ListenerSubscriptionPair pair;
21      private WildcardFilter subscriptionFilter;
22  
23      Sender(ListenerSubscriptionPair pair)
24      {
25          this.pair = pair;
26          subscriptionFilter = new WildcardFilter(pair.getSubscription());
27          subscriptionFilter.setCaseSensitive(false);
28      }
29  
30      public void dispatch(ServerNotification notification)
31      {
32          if (pair.isNullSubscription() ||
33                  (null != notification.getResourceIdentifier() &&
34                          subscriptionFilter.accept(notification.getResourceIdentifier())))
35          {
36              try
37              {
38                  pair.getListener().onNotification(notification);
39              }
40              catch (Exception e)
41              {
42                  // Exceptions from listeners do not affect the notification processing
43              }
44          }
45      }
46  
47  }
48