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