# HG changeset patch
# User cli
# Date 1315746304 -7200
# Node ID b78e7761915246923ab36c027531325cc069d4a0
# Parent e118b4d60029c6065d5def39bd7d0eb47cde1e2c
Merge Channel and Group classes.
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/NNTPConnection.java
--- a/src/org/sonews/daemon/NNTPConnection.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/NNTPConnection.java Sun Sep 11 15:05:04 2011 +0200
@@ -32,7 +32,7 @@
import java.util.TimerTask;
import org.sonews.daemon.command.Command;
import org.sonews.storage.Article;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
import org.sonews.util.Log;
import org.sonews.util.Stats;
@@ -54,7 +54,7 @@
private Charset charset = Charset.forName("UTF-8");
private Command command = null;
private Article currentArticle = null;
- private Channel currentGroup = null;
+ private Group currentGroup = null;
private volatile long lastActivity = System.currentTimeMillis();
private ChannelLineBuffers lineBuffers = new ChannelLineBuffers();
private int readLock = 0;
@@ -196,7 +196,7 @@
/**
* @return The currently selected communication channel (not SocketChannel)
*/
- public Channel getCurrentChannel()
+ public Group getCurrentChannel()
{
return this.currentGroup;
}
@@ -206,7 +206,7 @@
this.currentArticle = article;
}
- public void setCurrentGroup(final Channel group)
+ public void setCurrentGroup(final Group group)
{
this.currentGroup = group;
}
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/ArticleCommand.java
--- a/src/org/sonews/daemon/command/ArticleCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/ArticleCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,13 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.daemon.command;
import java.io.IOException;
import org.sonews.storage.Article;
import org.sonews.daemon.NNTPConnection;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
/**
@@ -30,38 +29,32 @@
* @author Dennis Schwerdel
* @since n3tpd/0.1
*/
-public class ArticleCommand implements Command
-{
+public class ArticleCommand implements Command {
@Override
- public String[] getSupportedCommandStrings()
- {
- return new String[] {"ARTICLE", "BODY", "HEAD"};
+ public String[] getSupportedCommandStrings() {
+ return new String[]{"ARTICLE", "BODY", "HEAD"};
}
@Override
- public boolean hasFinished()
- {
+ public boolean hasFinished() {
return true;
}
@Override
- public String impliedCapability()
- {
+ public String impliedCapability() {
return null;
}
@Override
- public boolean isStateful()
- {
+ public boolean isStateful() {
return false;
}
// TODO: Refactor this method to reduce its complexity!
@Override
public void processLine(NNTPConnection conn, final String line, byte[] raw)
- throws IOException
- {
+ throws IOException {
final String[] command = line.split(" ");
Article article = null;
@@ -82,7 +75,7 @@
} else {
// Message Number
try {
- Channel currentGroup = conn.getCurrentChannel();
+ Group currentGroup = conn.getCurrentChannel();
if (currentGroup == null) {
conn.println("400 no group selected");
return;
@@ -105,7 +98,7 @@
if (command[0].equalsIgnoreCase("ARTICLE")) {
conn.println("220 " + artIndex + " " + article.getMessageID()
- + " article retrieved - head and body follow");
+ + " article retrieved - head and body follow");
conn.println(article.getHeaderSource());
conn.println("");
conn.println(article.getBody());
@@ -144,7 +137,7 @@
* message-id Article message-id
*/ else if (command[0].equalsIgnoreCase("HEAD")) {
conn.println("221 " + artIndex + " " + article.getMessageID()
- + " Headers follow (multi-line)");
+ + " Headers follow (multi-line)");
conn.println(article.getHeaderSource());
conn.println(".");
}
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/GroupCommand.java
--- a/src/org/sonews/daemon/command/GroupCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/GroupCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -20,8 +20,9 @@
import java.io.IOException;
import org.sonews.daemon.NNTPConnection;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
+import org.sonews.storage.StorageManager;
/**
* Class handling the GROUP command.
@@ -78,9 +79,9 @@
{
final String[] command = line.split(" ");
- Channel group;
+ Group group;
if (command.length >= 2) {
- group = Channel.getByName(command[1]);
+ group = StorageManager.current().getGroup(command[1]);
if (group == null || group.isDeleted()) {
conn.println("411 no such news group");
} else {
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/ListCommand.java
--- a/src/org/sonews/daemon/command/ListCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/ListCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -24,7 +24,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.sonews.daemon.NNTPConnection;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
import org.sonews.util.Log;
@@ -74,8 +74,8 @@
conn.println(".");
} else if (command[1].equalsIgnoreCase("NEWSGROUPS")) {
conn.println("215 information follows");
- final List list = Channel.getAll();
- for (Channel g : list) {
+ final List list = Group.getAll();
+ for (Group g : list) {
conn.println(g.getName() + "\t" + "-");
}
conn.println(".");
@@ -103,10 +103,10 @@
private void printGroupInfo(NNTPConnection conn, String pattern)
throws IOException, StorageBackendException
{
- final List groups = Channel.getAll();
+ final List groups = Group.getAll();
if (groups != null) {
conn.println("215 list of newsgroups follows");
- for (Channel g : groups) {
+ for (Group g : groups) {
try {
Matcher matcher = pattern == null
? null : Pattern.compile(pattern).matcher(g.getName());
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/ListGroupCommand.java
--- a/src/org/sonews/daemon/command/ListGroupCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/ListGroupCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,14 +15,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.daemon.command;
import java.io.IOException;
import java.util.List;
import org.sonews.daemon.NNTPConnection;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
+import org.sonews.storage.StorageManager;
/**
* Class handling the LISTGROUP command.
@@ -30,42 +30,36 @@
* @author Dennis Schwerdel
* @since n3tpd/0.1
*/
-public class ListGroupCommand implements Command
-{
+public class ListGroupCommand implements Command {
@Override
- public String[] getSupportedCommandStrings()
- {
- return new String[] {"LISTGROUP"};
+ public String[] getSupportedCommandStrings() {
+ return new String[]{"LISTGROUP"};
}
@Override
- public boolean hasFinished()
- {
+ public boolean hasFinished() {
return true;
}
@Override
- public String impliedCapability()
- {
+ public String impliedCapability() {
return null;
}
@Override
- public boolean isStateful()
- {
+ public boolean isStateful() {
return false;
}
@Override
public void processLine(NNTPConnection conn, final String commandName, byte[] raw)
- throws IOException, StorageBackendException
- {
+ throws IOException, StorageBackendException {
final String[] command = commandName.split(" ");
- Channel group;
+ Group group;
if (command.length >= 2) {
- group = Channel.getByName(command[1]);
+ group = StorageManager.current().getGroup(command[1]);
} else {
group = conn.getCurrentChannel();
}
@@ -77,8 +71,8 @@
List ids = group.getArticleNumbers();
conn.println("211 " + ids.size() + " "
- + group.getFirstArticleNumber() + " "
- + group.getLastArticleNumber() + " list of article numbers follow");
+ + group.getFirstArticleNumber() + " "
+ + group.getLastArticleNumber() + " list of article numbers follow");
for (long id : ids) {
// One index number per line
conn.println(Long.toString(id));
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/NextPrevCommand.java
--- a/src/org/sonews/daemon/command/NextPrevCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/NextPrevCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,13 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.daemon.command;
import java.io.IOException;
import org.sonews.daemon.NNTPConnection;
import org.sonews.storage.Article;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
/**
@@ -30,39 +29,33 @@
* @author Dennis Schwerdel
* @since n3tpd/0.1
*/
-public class NextPrevCommand implements Command
-{
+public class NextPrevCommand implements Command {
@Override
- public String[] getSupportedCommandStrings()
- {
- return new String[] {"NEXT", "PREV"};
+ public String[] getSupportedCommandStrings() {
+ return new String[]{"NEXT", "PREV"};
}
@Override
- public boolean hasFinished()
- {
+ public boolean hasFinished() {
return true;
}
@Override
- public String impliedCapability()
- {
+ public String impliedCapability() {
return null;
}
@Override
- public boolean isStateful()
- {
+ public boolean isStateful() {
return false;
}
@Override
public void processLine(NNTPConnection conn, final String line, byte[] raw)
- throws IOException, StorageBackendException
- {
+ throws IOException, StorageBackendException {
final Article currA = conn.getCurrentArticle();
- final Channel currG = conn.getCurrentChannel();
+ final Group currG = conn.getCurrentChannel();
if (currA == null) {
conn.println("420 no current article has been selected");
@@ -85,10 +78,9 @@
}
}
- private void selectNewArticle(NNTPConnection conn, Article article, Channel grp,
- final int delta)
- throws IOException, StorageBackendException
- {
+ private void selectNewArticle(NNTPConnection conn, Article article, Group grp,
+ final int delta)
+ throws IOException, StorageBackendException {
assert article != null;
article = grp.getArticle(grp.getIndexOf(article) + delta);
@@ -98,8 +90,8 @@
} else {
conn.setCurrentArticle(article);
conn.println("223 " + conn.getCurrentChannel().getIndexOf(article)
- + " " + article.getMessageID()
- + " article retrieved - request text separately");
+ + " " + article.getMessageID()
+ + " article retrieved - request text separately");
}
}
}
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/StatCommand.java
--- a/src/org/sonews/daemon/command/StatCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/StatCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.daemon.command;
import java.io.IOException;
@@ -28,38 +27,32 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-public class StatCommand implements Command
-{
+public class StatCommand implements Command {
@Override
- public String[] getSupportedCommandStrings()
- {
- return new String[] {"STAT"};
+ public String[] getSupportedCommandStrings() {
+ return new String[]{"STAT"};
}
@Override
- public boolean hasFinished()
- {
+ public boolean hasFinished() {
return true;
}
@Override
- public String impliedCapability()
- {
+ public String impliedCapability() {
return null;
}
@Override
- public boolean isStateful()
- {
+ public boolean isStateful() {
return false;
}
// TODO: Method has various exit points => Refactor!
@Override
public void processLine(NNTPConnection conn, final String line, byte[] raw)
- throws IOException, StorageBackendException
- {
+ throws IOException, StorageBackendException {
final String[] command = line.split(" ");
Article article = null;
@@ -94,7 +87,7 @@
}
conn.println("223 " + conn.getCurrentChannel().getIndexOf(article) + " "
- + article.getMessageID()
- + " article retrieved - request text separately");
+ + article.getMessageID()
+ + " article retrieved - request text separately");
}
}
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/daemon/command/XDaemonCommand.java
--- a/src/org/sonews/daemon/command/XDaemonCommand.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/daemon/command/XDaemonCommand.java Sun Sep 11 15:05:04 2011 +0200
@@ -27,7 +27,6 @@
import org.sonews.storage.StorageManager;
import org.sonews.feed.FeedManager;
import org.sonews.feed.Subscription;
-import org.sonews.storage.Channel;
import org.sonews.storage.Group;
import org.sonews.util.Stats;
@@ -132,19 +131,19 @@
String flagName = commands[4];
if(commands[3].equalsIgnoreCase("SET")) {
if(flagName.equals("MAILINGLIST")) {
- group.setFlag(Channel.MAILINGLIST);
+ group.setFlag(Group.MAILINGLIST);
} else if(flagName.equals("DELETED")) {
- group.setFlag(Channel.DELETED);
+ group.setFlag(Group.DELETED);
} else if(flagName.equals("READONLY")) {
- group.setFlag(Channel.READONLY);
+ group.setFlag(Group.READONLY);
}
} else if(commands[3].equalsIgnoreCase("UNSET")) {
if(flagName.equals("MAILINGLIST")) {
- group.unsetFlag(Channel.MAILINGLIST);
+ group.unsetFlag(Group.MAILINGLIST);
} else if(flagName.equals("DELETED")) {
- group.unsetFlag(Channel.DELETED);
+ group.unsetFlag(Group.DELETED);
} else if(flagName.equals("READONLY")) {
- group.unsetFlag(Channel.READONLY);
+ group.unsetFlag(Group.READONLY);
}
} else {
conn.println("500 invalid command usage");
@@ -168,7 +167,7 @@
} else if (commands.length >= 3 && commands[1].equalsIgnoreCase("LOG")) {
Group group = null;
if (commands.length > 3) {
- group = (Group) Channel.getByName(commands[3]);
+ group = StorageManager.current().getGroup(commands[3]);
}
if (commands[2].equalsIgnoreCase("CONNECTED_CLIENTS")) {
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/storage/Channel.java
--- a/src/org/sonews/storage/Channel.java Sun Sep 11 14:19:19 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/*
- * SONEWS News Server
- * see AUTHORS for the list of contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.sonews.storage;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.sonews.util.Pair;
-
-/**
- * A logical communication Channel is the a generic structural element for sets
- * of messages; e.g. a Newsgroup for a set of Articles.
- * A Channel can either be a real set of messages or an aggregated set of
- * several subsets.
- * @author Christian Lins
- * @since sonews/1.0
- */
-public abstract class Channel {
-
- /**
- * If this flag is set the Group is no real newsgroup but a mailing list
- * mirror. In that case every posting and receiving mails must go through
- * the mailing list gateway.
- */
- public static final int MAILINGLIST = 0x1;
- /**
- * If this flag is set the Group is marked as readonly and the posting
- * is prohibited. This can be useful for groups that are synced only in
- * one direction.
- */
- public static final int READONLY = 0x2;
- /**
- * If this flag is set the Group is marked as deleted and must not occur
- * in any output. The deletion is done lazily by a low priority daemon.
- */
- public static final int DELETED = 0x80;
-
- public static List getAll() {
- List all = new ArrayList();
-
- /*List agroups = AggregatedGroup.getAll();
- if(agroups != null)
- {
- all.addAll(agroups);
- }*/
-
- List groups = Group.getAll();
- if (groups != null) {
- all.addAll(groups);
- }
-
- return all;
- }
-
- public static Channel getByName(String name)
- throws StorageBackendException {
- return StorageManager.current().getGroup(name);
- }
-
- public abstract Article getArticle(long idx)
- throws StorageBackendException;
-
- public abstract List> getArticleHeads(
- final long first, final long last)
- throws StorageBackendException;
-
- public abstract List getArticleNumbers()
- throws StorageBackendException;
-
- public abstract long getFirstArticleNumber()
- throws StorageBackendException;
-
- public abstract long getIndexOf(Article art)
- throws StorageBackendException;
-
- public abstract long getInternalID();
-
- public abstract long getLastArticleNumber()
- throws StorageBackendException;
-
- public abstract String getName();
-
- public abstract long getPostingsCount()
- throws StorageBackendException;
-
- public abstract boolean isDeleted();
-
- public abstract boolean isWriteable();
-}
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/storage/Group.java
--- a/src/org/sonews/storage/Group.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/storage/Group.java Sun Sep 11 15:05:04 2011 +0200
@@ -27,7 +27,7 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-public class Group extends Channel {
+public class Group {
/**
* If this flag is set the Group is no real newsgroup but a mailing list
@@ -56,7 +56,7 @@
/**
* @return List of all groups this server handles.
*/
- public static List getAll() {
+ public static List getAll() {
try {
return StorageManager.current().getGroups();
} catch (StorageBackendException ex) {
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/storage/Storage.java
--- a/src/org/sonews/storage/Storage.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/storage/Storage.java Sun Sep 11 15:05:04 2011 +0200
@@ -60,7 +60,7 @@
List> getArticleHeads(Group group, long first, long last)
throws StorageBackendException;
- List> getArticleHeaders(Channel channel, long start, long end,
+ List> getArticleHeaders(Group group, long start, long end,
String header, String pattern)
throws StorageBackendException;
@@ -74,7 +74,7 @@
throws StorageBackendException;
int getEventsCount(int eventType, long startTimestamp, long endTimestamp,
- Channel channel)
+ Group group)
throws StorageBackendException;
double getEventsPerHour(int key, long gid)
@@ -86,7 +86,7 @@
Group getGroup(String name)
throws StorageBackendException;
- List getGroups()
+ List getGroups()
throws StorageBackendException;
/**
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/storage/impl/HSQLDB.java
--- a/src/org/sonews/storage/impl/HSQLDB.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/storage/impl/HSQLDB.java Sun Sep 11 15:05:04 2011 +0200
@@ -18,9 +18,8 @@
package org.sonews.storage.impl;
import java.sql.SQLException;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.Storage;
-import org.sonews.storage.StorageBackendException;
/**
* A specialized JDBCDatabase supporting HSQLDB.
@@ -39,7 +38,7 @@
protected void prepareCountGroupsStatement() throws SQLException {
this.pstmtCountGroups = conn.prepareStatement(
"SELECT Count(group_id) FROM groups WHERE "
- + "BITAND(flags, " + Channel.DELETED + ") = 0");
+ + "BITAND(flags, " + Group.DELETED + ") = 0");
}
@Override
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/storage/impl/JDBCDatabase.java
--- a/src/org/sonews/storage/impl/JDBCDatabase.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/storage/impl/JDBCDatabase.java Sun Sep 11 15:05:04 2011 +0200
@@ -38,7 +38,6 @@
import org.sonews.feed.Subscription;
import org.sonews.storage.Article;
import org.sonews.storage.ArticleHead;
-import org.sonews.storage.Channel;
import org.sonews.storage.Group;
import org.sonews.storage.Storage;
import org.sonews.storage.StorageBackendException;
@@ -106,7 +105,7 @@
protected void prepareCountGroupsStatement() throws SQLException {
this.pstmtCountGroups = conn.prepareStatement(
"SELECT Count(group_id) FROM groups WHERE "
- + "flags & " + Channel.DELETED + " = 0");
+ + "flags & " + Group.DELETED + " = 0");
}
protected void prepareGetPostingsCountStatement() throws SQLException {
@@ -610,7 +609,7 @@
* @throws StorageBackendException
*/
@Override
- public List> getArticleHeaders(Channel group, long start,
+ public List> getArticleHeaders(Group group, long start,
long end, String headerKey, String patStr)
throws StorageBackendException, PatternSyntaxException
{
@@ -824,7 +823,7 @@
}
@Override
- public int getEventsCount(int type, long start, long end, Channel channel)
+ public int getEventsCount(int type, long start, long end, Group channel)
throws StorageBackendException
{
ResultSet rs = null;
@@ -868,11 +867,11 @@
* @throws StorageBackendException
*/
@Override
- public List getGroups()
+ public List getGroups()
throws StorageBackendException
{
ResultSet rs;
- List buffer = new ArrayList();
+ List buffer = new ArrayList();
Statement stmt = null;
try {
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/util/Purger.java
--- a/src/org/sonews/util/Purger.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/util/Purger.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.util;
import java.util.Date;
@@ -24,7 +23,6 @@
import org.sonews.config.Config;
import org.sonews.storage.Article;
import org.sonews.storage.Headers;
-import org.sonews.storage.Channel;
import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
import org.sonews.storage.StorageManager;
@@ -37,16 +35,14 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-public class Purger extends AbstractDaemon
-{
+public class Purger extends AbstractDaemon {
/**
* Loops through all messages and deletes them if their time
* has come.
*/
@Override
- public void run()
- {
+ public void run() {
try {
while (isRunning()) {
purgeDeleted();
@@ -62,10 +58,9 @@
}
private void purgeDeleted()
- throws StorageBackendException
- {
- List groups = StorageManager.current().getGroups();
- for (Channel channel : groups) {
+ throws StorageBackendException {
+ List groups = StorageManager.current().getGroups();
+ for (Group channel : groups) {
if (!(channel instanceof Group)) {
continue;
}
@@ -89,12 +84,11 @@
}
private void purgeOutdated()
- throws InterruptedException, StorageBackendException
- {
+ throws InterruptedException, StorageBackendException {
long articleMaximum =
- Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE);
+ Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE);
long lifetime =
- Config.inst().get("sonews.article.lifetime", -1);
+ Config.inst().get("sonews.article.lifetime", -1);
if (lifetime > 0 || articleMaximum < Stats.getInstance().getNumberOfNews()) {
Log.get().info("Purging old messages...");
diff -r e118b4d60029 -r b78e77619152 src/org/sonews/util/Stats.java
--- a/src/org/sonews/util/Stats.java Sun Sep 11 14:19:19 2011 +0200
+++ b/src/org/sonews/util/Stats.java Sun Sep 11 15:05:04 2011 +0200
@@ -15,12 +15,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package org.sonews.util;
import java.util.Calendar;
import org.sonews.config.Config;
-import org.sonews.storage.Channel;
+import org.sonews.storage.Group;
import org.sonews.storage.StorageBackendException;
import org.sonews.storage.StorageManager;
@@ -29,8 +28,7 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-public final class Stats
-{
+public final class Stats {
public static final byte CONNECTIONS = 1;
public static final byte POSTED_NEWS = 2;
@@ -40,15 +38,14 @@
public static final byte MLGW_RUNEND = 6;
private static Stats instance = new Stats();
- public static Stats getInstance()
- {
+ public static Stats getInstance() {
return Stats.instance;
}
- private Stats()
- {
+ private volatile int connectedClients = 0;
+
+ private Stats() {
}
- private volatile int connectedClients = 0;
/**
* A generic method that writes event data to the storage backend.
@@ -57,15 +54,13 @@
* @param type
* @param groupname
*/
- private void addEvent(byte type, String groupname)
- {
+ private void addEvent(byte type, String groupname) {
try {
if (Config.inst().get(Config.EVENTLOG, true)) {
-
- Channel group = Channel.getByName(groupname);
+ Group group = StorageManager.current().getGroup(groupname);
if (group != null) {
StorageManager.current().addEvent(
- System.currentTimeMillis(), type, group.getInternalID());
+ System.currentTimeMillis(), type, group.getInternalID());
}
} else {
Log.get().info("Group " + groupname + " does not exist.");
@@ -75,23 +70,19 @@
}
}
- public void clientConnect()
- {
+ public void clientConnect() {
this.connectedClients++;
}
- public void clientDisconnect()
- {
+ public void clientDisconnect() {
this.connectedClients--;
}
- public int connectedClients()
- {
+ public int connectedClients() {
return this.connectedClients;
}
- public int getNumberOfGroups()
- {
+ public int getNumberOfGroups() {
try {
return StorageManager.current().countGroups();
} catch (StorageBackendException ex) {
@@ -100,8 +91,7 @@
}
}
- public int getNumberOfNews()
- {
+ public int getNumberOfNews() {
try {
return StorageManager.current().countArticles();
} catch (StorageBackendException ex) {
@@ -111,8 +101,7 @@
}
public int getYesterdaysEvents(final byte eventType, final int hour,
- final Channel group)
- {
+ final Group group) {
// Determine the timestamp values for yesterday and the given hour
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
@@ -133,33 +122,27 @@
}
}
- public void mailPosted(String groupname)
- {
+ public void mailPosted(String groupname) {
addEvent(POSTED_NEWS, groupname);
}
- public void mailGatewayed(String groupname)
- {
+ public void mailGatewayed(String groupname) {
addEvent(GATEWAYED_NEWS, groupname);
}
- public void mailFeeded(String groupname)
- {
+ public void mailFeeded(String groupname) {
addEvent(FEEDED_NEWS, groupname);
}
- public void mlgwRunStart()
- {
+ public void mlgwRunStart() {
addEvent(MLGW_RUNSTART, "control");
}
- public void mlgwRunEnd()
- {
+ public void mlgwRunEnd() {
addEvent(MLGW_RUNEND, "control");
}
- private double perHour(int key, long gid)
- {
+ private double perHour(int key, long gid) {
try {
return StorageManager.current().getEventsPerHour(key, gid);
} catch (StorageBackendException ex) {
@@ -168,18 +151,15 @@
}
}
- public double postedPerHour(long gid)
- {
+ public double postedPerHour(long gid) {
return perHour(POSTED_NEWS, gid);
}
- public double gatewayedPerHour(long gid)
- {
+ public double gatewayedPerHour(long gid) {
return perHour(GATEWAYED_NEWS, gid);
}
- public double feededPerHour(long gid)
- {
+ public double feededPerHour(long gid) {
return perHour(FEEDED_NEWS, gid);
}
}