src/org/sonews/util/Stats.java
changeset 48 b78e77619152
parent 37 74139325d305
child 49 8df94bfd3e2f
     1.1 --- a/src/org/sonews/util/Stats.java	Sun Sep 11 14:19:19 2011 +0200
     1.2 +++ b/src/org/sonews/util/Stats.java	Sun Sep 11 15:05:04 2011 +0200
     1.3 @@ -15,12 +15,11 @@
     1.4   *   You should have received a copy of the GNU General Public License
     1.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     1.6   */
     1.7 -
     1.8  package org.sonews.util;
     1.9  
    1.10  import java.util.Calendar;
    1.11  import org.sonews.config.Config;
    1.12 -import org.sonews.storage.Channel;
    1.13 +import org.sonews.storage.Group;
    1.14  import org.sonews.storage.StorageBackendException;
    1.15  import org.sonews.storage.StorageManager;
    1.16  
    1.17 @@ -29,8 +28,7 @@
    1.18   * @author Christian Lins
    1.19   * @since sonews/0.5.0
    1.20   */
    1.21 -public final class Stats
    1.22 -{
    1.23 +public final class Stats {
    1.24  
    1.25  	public static final byte CONNECTIONS = 1;
    1.26  	public static final byte POSTED_NEWS = 2;
    1.27 @@ -40,15 +38,14 @@
    1.28  	public static final byte MLGW_RUNEND = 6;
    1.29  	private static Stats instance = new Stats();
    1.30  
    1.31 -	public static Stats getInstance()
    1.32 -	{
    1.33 +	public static Stats getInstance() {
    1.34  		return Stats.instance;
    1.35  	}
    1.36  
    1.37 -	private Stats()
    1.38 -	{
    1.39 +	private volatile int connectedClients = 0;
    1.40 +
    1.41 +	private Stats() {
    1.42  	}
    1.43 -	private volatile int connectedClients = 0;
    1.44  
    1.45  	/**
    1.46  	 * A generic method that writes event data to the storage backend.
    1.47 @@ -57,15 +54,13 @@
    1.48  	 * @param type
    1.49  	 * @param groupname
    1.50  	 */
    1.51 -	private void addEvent(byte type, String groupname)
    1.52 -	{
    1.53 +	private void addEvent(byte type, String groupname) {
    1.54  		try {
    1.55  			if (Config.inst().get(Config.EVENTLOG, true)) {
    1.56 -
    1.57 -				Channel group = Channel.getByName(groupname);
    1.58 +				Group group = StorageManager.current().getGroup(groupname);
    1.59  				if (group != null) {
    1.60  					StorageManager.current().addEvent(
    1.61 -						System.currentTimeMillis(), type, group.getInternalID());
    1.62 +							System.currentTimeMillis(), type, group.getInternalID());
    1.63  				}
    1.64  			} else {
    1.65  				Log.get().info("Group " + groupname + " does not exist.");
    1.66 @@ -75,23 +70,19 @@
    1.67  		}
    1.68  	}
    1.69  
    1.70 -	public void clientConnect()
    1.71 -	{
    1.72 +	public void clientConnect() {
    1.73  		this.connectedClients++;
    1.74  	}
    1.75  
    1.76 -	public void clientDisconnect()
    1.77 -	{
    1.78 +	public void clientDisconnect() {
    1.79  		this.connectedClients--;
    1.80  	}
    1.81  
    1.82 -	public int connectedClients()
    1.83 -	{
    1.84 +	public int connectedClients() {
    1.85  		return this.connectedClients;
    1.86  	}
    1.87  
    1.88 -	public int getNumberOfGroups()
    1.89 -	{
    1.90 +	public int getNumberOfGroups() {
    1.91  		try {
    1.92  			return StorageManager.current().countGroups();
    1.93  		} catch (StorageBackendException ex) {
    1.94 @@ -100,8 +91,7 @@
    1.95  		}
    1.96  	}
    1.97  
    1.98 -	public int getNumberOfNews()
    1.99 -	{
   1.100 +	public int getNumberOfNews() {
   1.101  		try {
   1.102  			return StorageManager.current().countArticles();
   1.103  		} catch (StorageBackendException ex) {
   1.104 @@ -111,8 +101,7 @@
   1.105  	}
   1.106  
   1.107  	public int getYesterdaysEvents(final byte eventType, final int hour,
   1.108 -		final Channel group)
   1.109 -	{
   1.110 +			final Group group) {
   1.111  		// Determine the timestamp values for yesterday and the given hour
   1.112  		Calendar cal = Calendar.getInstance();
   1.113  		int year = cal.get(Calendar.YEAR);
   1.114 @@ -133,33 +122,27 @@
   1.115  		}
   1.116  	}
   1.117  
   1.118 -	public void mailPosted(String groupname)
   1.119 -	{
   1.120 +	public void mailPosted(String groupname) {
   1.121  		addEvent(POSTED_NEWS, groupname);
   1.122  	}
   1.123  
   1.124 -	public void mailGatewayed(String groupname)
   1.125 -	{
   1.126 +	public void mailGatewayed(String groupname) {
   1.127  		addEvent(GATEWAYED_NEWS, groupname);
   1.128  	}
   1.129  
   1.130 -	public void mailFeeded(String groupname)
   1.131 -	{
   1.132 +	public void mailFeeded(String groupname) {
   1.133  		addEvent(FEEDED_NEWS, groupname);
   1.134  	}
   1.135  
   1.136 -	public void mlgwRunStart()
   1.137 -	{
   1.138 +	public void mlgwRunStart() {
   1.139  		addEvent(MLGW_RUNSTART, "control");
   1.140  	}
   1.141  
   1.142 -	public void mlgwRunEnd()
   1.143 -	{
   1.144 +	public void mlgwRunEnd() {
   1.145  		addEvent(MLGW_RUNEND, "control");
   1.146  	}
   1.147  
   1.148 -	private double perHour(int key, long gid)
   1.149 -	{
   1.150 +	private double perHour(int key, long gid) {
   1.151  		try {
   1.152  			return StorageManager.current().getEventsPerHour(key, gid);
   1.153  		} catch (StorageBackendException ex) {
   1.154 @@ -168,18 +151,15 @@
   1.155  		}
   1.156  	}
   1.157  
   1.158 -	public double postedPerHour(long gid)
   1.159 -	{
   1.160 +	public double postedPerHour(long gid) {
   1.161  		return perHour(POSTED_NEWS, gid);
   1.162  	}
   1.163  
   1.164 -	public double gatewayedPerHour(long gid)
   1.165 -	{
   1.166 +	public double gatewayedPerHour(long gid) {
   1.167  		return perHour(GATEWAYED_NEWS, gid);
   1.168  	}
   1.169  
   1.170 -	public double feededPerHour(long gid)
   1.171 -	{
   1.172 +	public double feededPerHour(long gid) {
   1.173  		return perHour(FEEDED_NEWS, gid);
   1.174  	}
   1.175  }