EMMA Coverage Report (generated Sun May 02 20:42:29 CEST 2010)
[all classes][hu.netmind.beankeeper.logging.impl]

COVERAGE SUMMARY FOR SOURCE FILE [SnapshotLoggerImpl.java]

nameclass, %method, %block, %line, %
SnapshotLoggerImpl.java50%  (1/2)83%  (5/6)31%  (34/108)43%  (13/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SnapshotLoggerImpl$ProfileEntry0%   (0/1)0%   (0/1)0%   (0/9)0%   (0/4)
SnapshotLoggerImpl$ProfileEntry (): void 0%   (0/1)0%   (0/9)0%   (0/4)
     
class SnapshotLoggerImpl100% (1/1)100% (5/5)34%  (34/99)50%  (13/26)
log (String, String): void 100% (1/1)6%   (4/64)15%  (2/13)
init (Map): void 100% (1/1)77%  (17/22)71%  (5/7)
<static initializer> 100% (1/1)100% (6/6)100% (2/2)
SnapshotLoggerImpl (): void 100% (1/1)100% (6/6)100% (3/3)
release (): void 100% (1/1)100% (1/1)100% (1/1)

1/**
2 * Copyright (C) 2007 NetMind Consulting Bt.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19package hu.netmind.beankeeper.logging.impl;
20 
21import hu.netmind.beankeeper.logging.SnapshotLogger;
22import org.apache.log4j.Logger;
23import java.util.*;
24 
25/**
26 * This implementation uses configuration to get the output interval of
27 * categories, and uses apache logger for output.
28 * @author Brautigam Robert
29 * @version CVS Revision: $Revision$
30 */
31public class SnapshotLoggerImpl implements SnapshotLogger 
32{
33   private static Logger logger = Logger.getLogger(SnapshotLogger.class);
34   private static int PROFILE_INTERVAL = 5000;
35 
36   private long lastOutputTime = 0;
37   private Map eventEntries;
38 
39   public void init(Map parameters)
40   {
41      eventEntries = Collections.synchronizedMap(new HashMap());
42      try
43      {
44         ResourceBundle config = ResourceBundle.getBundle("beankeeper");
45         PROFILE_INTERVAL = Integer.valueOf(config.getString("beankeeper.profile.interval")).intValue();
46      } catch ( Exception e ) {
47         logger.error("could not read configuration file, using hardcoded defaults.",e);
48      }
49   }
50 
51   public void release()
52   {
53   }
54   
55   /**
56    * Log an event.
57    * @param category The category identifier of the event.
58    * @param message The message of given type.
59    */
60   public void log(String category,String message)
61   {
62      // If not enabled, do nothing
63      if ( ! logger.isDebugEnabled() )
64         return;
65      // Adjust count
66      ProfileEntry entry = (ProfileEntry) eventEntries.get(category);
67      if ( entry == null )
68      {
69         entry = new ProfileEntry();
70         eventEntries.put(category,entry);
71      }
72      entry.count++;
73      // Decide what to do
74      long currentTime = System.currentTimeMillis();
75      if ( currentTime > PROFILE_INTERVAL + entry.lastOutputTime )
76      {
77         // Time's up, output now
78         logger.debug("["+category+":"+entry.count+"] "+message);
79         entry.lastOutputTime = currentTime;
80         // Clear entry
81         entry.count=0;
82      }
83   }
84 
85   private static class ProfileEntry
86   {
87      public long lastOutputTime;
88      public int count;
89 
90      public ProfileEntry()
91      {
92         lastOutputTime = 0;
93         count = 0;
94      }
95   }
96}
97 
98 

[all classes][hu.netmind.beankeeper.logging.impl]
EMMA 2.0.5312debian (C) Vladimir Roubtsov