Coverage Report - org.mule.management.stats.RouterStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
RouterStatistics
14%
7/51
0%
0/14
1.471
 
 1  
 /*
 2  
  * $Id: RouterStatistics.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.management.stats;
 12  
 
 13  
 import org.mule.management.stats.printers.SimplePrinter;
 14  
 import org.mule.umo.endpoint.UMOEndpoint;
 15  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 16  
 
 17  
 import java.io.PrintWriter;
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.HashMap;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 /**
 25  
  * <code>RouterStatistics</code> TODO
 26  
  */
 27  
 public class RouterStatistics implements Statistics
 28  
 {
 29  
 
 30  
     /**
 31  
      * Serial version
 32  
      */
 33  
     private static final long serialVersionUID = 4540482357430845065L;
 34  
 
 35  
     public static final int TYPE_INBOUND = 1;
 36  
     public static final int TYPE_OUTBOUND = 2;
 37  
     public static final int TYPE_RESPONSE = 3;
 38  
     public static final int TYPE_NESTED = 4;
 39  
 
 40  
     private boolean enabled;
 41  
     private long notRouted;
 42  
     private long caughtInCatchAll;
 43  
     private long totalRouted;
 44  
     private long totalReceived;
 45  
     private Map routed;
 46  
     private int type;
 47  
 
 48  
     /**
 49  
      * @see org.mule.management.stats.Statistics#clear()
 50  
      */
 51  
     public synchronized void clear()
 52  
     {
 53  0
         notRouted = 0;
 54  0
         totalRouted = 0;
 55  0
         totalReceived = 0;
 56  0
         caughtInCatchAll = 0;
 57  0
         routed.clear();
 58  0
     }
 59  
 
 60  
     /**
 61  
      * @see org.mule.management.stats.Statistics#isEnabled()
 62  
      */
 63  
     public boolean isEnabled()
 64  
     {
 65  36
         return enabled;
 66  
     }
 67  
 
 68  
     public void logSummary()
 69  
     {
 70  0
         logSummary(new SimplePrinter(System.out));
 71  0
     }
 72  
 
 73  
     public void logSummary(PrintWriter printer)
 74  
     {
 75  0
         printer.print(this);
 76  0
     }
 77  
 
 78  
     /**
 79  
      * @see org.mule.management.stats.Statistics#setEnabled(boolean)
 80  
      */
 81  
     public synchronized void setEnabled(boolean b)
 82  
     {
 83  88
         enabled = b;
 84  88
     }
 85  
 
 86  
     /**
 87  
      * The constructor
 88  
      */
 89  
     public RouterStatistics(int type)
 90  
     {
 91  888
         super();
 92  888
         this.type = type;
 93  888
         routed = new HashMap();
 94  888
     }
 95  
 
 96  
     /**
 97  
      * Increment routed message for multiple endpoints
 98  
      * 
 99  
      * @param endpoints The endpoint collection
 100  
      */
 101  
     public void incrementRoutedMessage(Collection endpoints)
 102  
     {
 103  0
         if (endpoints == null || endpoints.isEmpty())
 104  
         {
 105  0
             return;
 106  
         }
 107  0
         List list = new ArrayList(endpoints);
 108  0
         synchronized (list)
 109  
         {
 110  0
             for (int i = 0; i < list.size(); i++)
 111  
             {
 112  0
                 incrementRoutedMessage((UMOEndpoint) list.get(i));
 113  
             }
 114  0
         }
 115  0
     }
 116  
 
 117  
     /**
 118  
      * Increment routed message for an endpoint
 119  
      * 
 120  
      * @param endpoint The endpoint
 121  
      */
 122  
     public synchronized void incrementRoutedMessage(UMOImmutableEndpoint endpoint)
 123  
     {
 124  0
         if (endpoint == null)
 125  
         {
 126  0
             return;
 127  
         }
 128  
 
 129  0
         String name = endpoint.getName();
 130  
 
 131  0
         Long cpt = (Long) routed.get(name);
 132  0
         long count = 0;
 133  
 
 134  0
         if (cpt != null)
 135  
         {
 136  0
             count = cpt.longValue();
 137  
         }
 138  
 
 139  
         // TODO we should probably use a MutableLong here,
 140  
         // but that might be problematic for remote MBean access (serialization)
 141  0
         routed.put(name, new Long(++count));
 142  
 
 143  0
         totalRouted++;
 144  0
         totalReceived++;
 145  0
     }
 146  
 
 147  
     /**
 148  
      * Increment no routed message
 149  
      */
 150  
     public synchronized void incrementNoRoutedMessage()
 151  
     {
 152  0
         notRouted++;
 153  0
         totalReceived++;
 154  0
     }
 155  
 
 156  
     /**
 157  
      * Increment no routed message
 158  
      */
 159  
     public synchronized void incrementCaughtMessage()
 160  
     {
 161  0
         caughtInCatchAll++;
 162  0
     }
 163  
 
 164  
     /**
 165  
      * @return Returns the notRouted.
 166  
      */
 167  
     public final long getCaughtMessages()
 168  
     {
 169  0
         return caughtInCatchAll;
 170  
     }
 171  
 
 172  
     /**
 173  
      * @return Returns the notRouted.
 174  
      */
 175  
     public final long getNotRouted()
 176  
     {
 177  0
         return notRouted;
 178  
     }
 179  
 
 180  
     /**
 181  
      * @return Returns the totalReceived.
 182  
      */
 183  
     public final long getTotalReceived()
 184  
     {
 185  0
         return totalReceived;
 186  
     }
 187  
 
 188  
     /**
 189  
      * @return Returns the totalRouted.
 190  
      */
 191  
     public final long getTotalRouted()
 192  
     {
 193  0
         return totalRouted;
 194  
     }
 195  
 
 196  
     /**
 197  
      * @return Returns the totalRouted.
 198  
      */
 199  
     public final long getRouted(String endpointName)
 200  
     {
 201  0
         Long l = (Long) routed.get(endpointName);
 202  
 
 203  0
         if (l == null)
 204  
         {
 205  0
             return 0;
 206  
         }
 207  
         else
 208  
         {
 209  0
             return l.longValue();
 210  
         }
 211  
     }
 212  
 
 213  
     public boolean isInbound()
 214  
     {
 215  0
         return type == TYPE_INBOUND;
 216  
     }
 217  
 
 218  
     public Map getRouted()
 219  
     {
 220  0
         return routed;
 221  
     }
 222  
 }