org/sonews/util/Stats.java
changeset 3 2fdc9cc89502
parent 1 6fceb66e1ad7
child 16 5a4a41cfc0a3
     1.1 --- a/org/sonews/util/Stats.java	Fri Jun 26 16:48:50 2009 +0200
     1.2 +++ b/org/sonews/util/Stats.java	Wed Jul 22 14:04:05 2009 +0200
     1.3 @@ -18,10 +18,11 @@
     1.4  
     1.5  package org.sonews.util;
     1.6  
     1.7 -import java.sql.SQLException;
     1.8  import java.util.Calendar;
     1.9 -import org.sonews.daemon.storage.Database;
    1.10 -import org.sonews.daemon.storage.Group;
    1.11 +import org.sonews.config.Config;
    1.12 +import org.sonews.storage.Channel;
    1.13 +import org.sonews.storage.StorageBackendException;
    1.14 +import org.sonews.storage.StorageManager;
    1.15  
    1.16  /**
    1.17   * Class that capsulates statistical data gathering.
    1.18 @@ -48,26 +49,36 @@
    1.19    private Stats() {}
    1.20    
    1.21    private volatile int connectedClients = 0;
    1.22 -  
    1.23 +
    1.24 +  /**
    1.25 +   * A generic method that writes event data to the storage backend.
    1.26 +   * If event logging is disabled with sonews.eventlog=false this method
    1.27 +   * simply does nothing.
    1.28 +   * @param type
    1.29 +   * @param groupname
    1.30 +   */
    1.31    private void addEvent(byte type, String groupname)
    1.32    {
    1.33 -    Group group = Group.getByName(groupname);
    1.34 -    if(group != null)
    1.35 +    if(Config.inst().get(Config.EVENTLOG, true))
    1.36      {
    1.37 -      try
    1.38 +      Channel group = Channel.getByName(groupname);
    1.39 +      if(group != null)
    1.40        {
    1.41 -        Database.getInstance().addEvent(
    1.42 -          System.currentTimeMillis(), type, group.getID());
    1.43 +        try
    1.44 +        {
    1.45 +          StorageManager.current().addEvent(
    1.46 +            System.currentTimeMillis(), type, group.getInternalID());
    1.47 +        }
    1.48 +        catch(StorageBackendException ex)
    1.49 +        {
    1.50 +          ex.printStackTrace();
    1.51 +        }
    1.52        }
    1.53 -      catch(SQLException ex)
    1.54 +      else
    1.55        {
    1.56 -        ex.printStackTrace();
    1.57 +        Log.msg("Group " + groupname + " does not exist.", true);
    1.58        }
    1.59      }
    1.60 -    else
    1.61 -    {
    1.62 -      Log.msg("Group " + groupname + " does not exist.", true);
    1.63 -    }
    1.64    }
    1.65    
    1.66    public void clientConnect()
    1.67 @@ -89,9 +100,9 @@
    1.68    {
    1.69      try
    1.70      {
    1.71 -      return Database.getInstance().countGroups();
    1.72 +      return StorageManager.current().countGroups();
    1.73      }
    1.74 -    catch(SQLException ex)
    1.75 +    catch(StorageBackendException ex)
    1.76      {
    1.77        ex.printStackTrace();
    1.78        return -1;
    1.79 @@ -102,9 +113,9 @@
    1.80    {
    1.81      try
    1.82      {
    1.83 -      return Database.getInstance().countArticles();
    1.84 +      return StorageManager.current().countArticles();
    1.85      }
    1.86 -    catch(SQLException ex)
    1.87 +    catch(StorageBackendException ex)
    1.88      {
    1.89        ex.printStackTrace();
    1.90        return -1;
    1.91 @@ -112,7 +123,7 @@
    1.92    }
    1.93    
    1.94    public int getYesterdaysEvents(final byte eventType, final int hour,
    1.95 -    final Group group)
    1.96 +    final Channel group)
    1.97    {
    1.98      // Determine the timestamp values for yesterday and the given hour
    1.99      Calendar cal = Calendar.getInstance();
   1.100 @@ -128,10 +139,10 @@
   1.101      
   1.102      try
   1.103      {
   1.104 -      return Database.getInstance()
   1.105 +      return StorageManager.current()
   1.106          .getEventsCount(eventType, startTimestamp, endTimestamp, group);
   1.107      }
   1.108 -    catch(SQLException ex)
   1.109 +    catch(StorageBackendException ex)
   1.110      {
   1.111        ex.printStackTrace();
   1.112        return -1;
   1.113 @@ -167,9 +178,9 @@
   1.114    {
   1.115      try
   1.116      {
   1.117 -      return Database.getInstance().getNumberOfEventsPerHour(key, gid);
   1.118 +      return StorageManager.current().getEventsPerHour(key, gid);
   1.119      }
   1.120 -    catch(SQLException ex)
   1.121 +    catch(StorageBackendException ex)
   1.122      {
   1.123        ex.printStackTrace();
   1.124        return -1;