Coverage Report - org.mule.context.notification.OptimisedNotificationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
OptimisedNotificationHandler
0%
0/17
0%
0/8
1.8
 
 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.api.context.notification.ServerNotificationHandler;
 11  
 import org.mule.api.context.notification.ServerNotificationListener;
 12  
 
 13  
 /**
 14  
  * Optimized to make a quick decision on a particular class of messages.
 15  
  */
 16  
 public class OptimisedNotificationHandler implements ServerNotificationHandler
 17  
 {
 18  
 
 19  
     private ServerNotificationHandler delegate;
 20  
     private Class type;
 21  0
     private boolean dynamic = false;
 22  0
     private volatile Boolean enabled = null;
 23  
 
 24  
     public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class type)
 25  0
     {
 26  0
         this.delegate = delegate;
 27  0
         this.type = type;
 28  0
         dynamic = delegate.isNotificationDynamic();
 29  0
     }
 30  
 
 31  
     public boolean isNotificationDynamic()
 32  
     {
 33  0
         return dynamic;
 34  
     }
 35  
 
 36  
     public boolean isListenerRegistered(ServerNotificationListener listener)
 37  
     {
 38  0
         return delegate.isListenerRegistered(listener);
 39  
     }
 40  
 
 41  
     /**
 42  
      * This returns a very "conservative" value - it is true if the notification or any subclass would be
 43  
      * accepted.  So if it returns false then you can be sure that there is no need to send the
 44  
      * notification.  On the other hand, if it returns true there is no guarantee that the notification
 45  
      * "really" will be dispatched to any listener.
 46  
      *
 47  
      * @param notfnClass Either the notification class being generated or some superclass
 48  
      * @return false if there is no need to dispatch the notification
 49  
      */
 50  
     public boolean isNotificationEnabled(Class notfnClass)
 51  
     {
 52  0
         if ((!dynamic) && type.isAssignableFrom(notfnClass))
 53  
         {
 54  0
             if (enabled == null)
 55  
             {
 56  0
                 enabled = delegate.isNotificationEnabled(notfnClass);
 57  
             }
 58  
 
 59  0
             return enabled;
 60  
         }
 61  
         else
 62  
         {
 63  0
             return delegate.isNotificationEnabled(notfnClass);
 64  
         }
 65  
     }
 66  
 
 67  
     public void fireNotification(ServerNotification notification)
 68  
     {
 69  0
         if (isNotificationEnabled(notification.getClass()))
 70  
         {
 71  0
             delegate.fireNotification(notification);
 72  
         }
 73  0
     }
 74  
 
 75  
 }