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