Merge Channel and Group classes.
authorcli
Sun Sep 11 15:05:04 2011 +0200 (2011-09-11)
changeset 48b78e77619152
parent 47 e118b4d60029
child 49 8df94bfd3e2f
Merge Channel and Group classes.
src/org/sonews/daemon/NNTPConnection.java
src/org/sonews/daemon/command/ArticleCommand.java
src/org/sonews/daemon/command/GroupCommand.java
src/org/sonews/daemon/command/ListCommand.java
src/org/sonews/daemon/command/ListGroupCommand.java
src/org/sonews/daemon/command/NextPrevCommand.java
src/org/sonews/daemon/command/StatCommand.java
src/org/sonews/daemon/command/XDaemonCommand.java
src/org/sonews/storage/Channel.java
src/org/sonews/storage/Group.java
src/org/sonews/storage/Storage.java
src/org/sonews/storage/impl/HSQLDB.java
src/org/sonews/storage/impl/JDBCDatabase.java
src/org/sonews/util/Purger.java
src/org/sonews/util/Stats.java
     1.1 --- a/src/org/sonews/daemon/NNTPConnection.java	Sun Sep 11 14:19:19 2011 +0200
     1.2 +++ b/src/org/sonews/daemon/NNTPConnection.java	Sun Sep 11 15:05:04 2011 +0200
     1.3 @@ -32,7 +32,7 @@
     1.4  import java.util.TimerTask;
     1.5  import org.sonews.daemon.command.Command;
     1.6  import org.sonews.storage.Article;
     1.7 -import org.sonews.storage.Channel;
     1.8 +import org.sonews.storage.Group;
     1.9  import org.sonews.storage.StorageBackendException;
    1.10  import org.sonews.util.Log;
    1.11  import org.sonews.util.Stats;
    1.12 @@ -54,7 +54,7 @@
    1.13  	private Charset charset = Charset.forName("UTF-8");
    1.14  	private Command command = null;
    1.15  	private Article currentArticle = null;
    1.16 -	private Channel currentGroup = null;
    1.17 +	private Group currentGroup = null;
    1.18  	private volatile long lastActivity = System.currentTimeMillis();
    1.19  	private ChannelLineBuffers lineBuffers = new ChannelLineBuffers();
    1.20  	private int readLock = 0;
    1.21 @@ -196,7 +196,7 @@
    1.22  	/**
    1.23  	 * @return The currently selected communication channel (not SocketChannel)
    1.24  	 */
    1.25 -	public Channel getCurrentChannel()
    1.26 +	public Group getCurrentChannel()
    1.27  	{
    1.28  		return this.currentGroup;
    1.29  	}
    1.30 @@ -206,7 +206,7 @@
    1.31  		this.currentArticle = article;
    1.32  	}
    1.33  
    1.34 -	public void setCurrentGroup(final Channel group)
    1.35 +	public void setCurrentGroup(final Group group)
    1.36  	{
    1.37  		this.currentGroup = group;
    1.38  	}
     2.1 --- a/src/org/sonews/daemon/command/ArticleCommand.java	Sun Sep 11 14:19:19 2011 +0200
     2.2 +++ b/src/org/sonews/daemon/command/ArticleCommand.java	Sun Sep 11 15:05:04 2011 +0200
     2.3 @@ -15,13 +15,12 @@
     2.4   *   You should have received a copy of the GNU General Public License
     2.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     2.6   */
     2.7 -
     2.8  package org.sonews.daemon.command;
     2.9  
    2.10  import java.io.IOException;
    2.11  import org.sonews.storage.Article;
    2.12  import org.sonews.daemon.NNTPConnection;
    2.13 -import org.sonews.storage.Channel;
    2.14 +import org.sonews.storage.Group;
    2.15  import org.sonews.storage.StorageBackendException;
    2.16  
    2.17  /**
    2.18 @@ -30,38 +29,32 @@
    2.19   * @author Dennis Schwerdel
    2.20   * @since n3tpd/0.1
    2.21   */
    2.22 -public class ArticleCommand implements Command
    2.23 -{
    2.24 +public class ArticleCommand implements Command {
    2.25  
    2.26  	@Override
    2.27 -	public String[] getSupportedCommandStrings()
    2.28 -	{
    2.29 -		return new String[] {"ARTICLE", "BODY", "HEAD"};
    2.30 +	public String[] getSupportedCommandStrings() {
    2.31 +		return new String[]{"ARTICLE", "BODY", "HEAD"};
    2.32  	}
    2.33  
    2.34  	@Override
    2.35 -	public boolean hasFinished()
    2.36 -	{
    2.37 +	public boolean hasFinished() {
    2.38  		return true;
    2.39  	}
    2.40  
    2.41  	@Override
    2.42 -	public String impliedCapability()
    2.43 -	{
    2.44 +	public String impliedCapability() {
    2.45  		return null;
    2.46  	}
    2.47  
    2.48  	@Override
    2.49 -	public boolean isStateful()
    2.50 -	{
    2.51 +	public boolean isStateful() {
    2.52  		return false;
    2.53  	}
    2.54  
    2.55  	// TODO: Refactor this method to reduce its complexity!
    2.56  	@Override
    2.57  	public void processLine(NNTPConnection conn, final String line, byte[] raw)
    2.58 -		throws IOException
    2.59 -	{
    2.60 +			throws IOException {
    2.61  		final String[] command = line.split(" ");
    2.62  
    2.63  		Article article = null;
    2.64 @@ -82,7 +75,7 @@
    2.65  		} else {
    2.66  			// Message Number
    2.67  			try {
    2.68 -				Channel currentGroup = conn.getCurrentChannel();
    2.69 +				Group currentGroup = conn.getCurrentChannel();
    2.70  				if (currentGroup == null) {
    2.71  					conn.println("400 no group selected");
    2.72  					return;
    2.73 @@ -105,7 +98,7 @@
    2.74  
    2.75  		if (command[0].equalsIgnoreCase("ARTICLE")) {
    2.76  			conn.println("220 " + artIndex + " " + article.getMessageID()
    2.77 -				+ " article retrieved - head and body follow");
    2.78 +					+ " article retrieved - head and body follow");
    2.79  			conn.println(article.getHeaderSource());
    2.80  			conn.println("");
    2.81  			conn.println(article.getBody());
    2.82 @@ -144,7 +137,7 @@
    2.83  		 *  message-id    Article message-id
    2.84  		 */ else if (command[0].equalsIgnoreCase("HEAD")) {
    2.85  			conn.println("221 " + artIndex + " " + article.getMessageID()
    2.86 -				+ " Headers follow (multi-line)");
    2.87 +					+ " Headers follow (multi-line)");
    2.88  			conn.println(article.getHeaderSource());
    2.89  			conn.println(".");
    2.90  		}
     3.1 --- a/src/org/sonews/daemon/command/GroupCommand.java	Sun Sep 11 14:19:19 2011 +0200
     3.2 +++ b/src/org/sonews/daemon/command/GroupCommand.java	Sun Sep 11 15:05:04 2011 +0200
     3.3 @@ -20,8 +20,9 @@
     3.4  
     3.5  import java.io.IOException;
     3.6  import org.sonews.daemon.NNTPConnection;
     3.7 -import org.sonews.storage.Channel;
     3.8 +import org.sonews.storage.Group;
     3.9  import org.sonews.storage.StorageBackendException;
    3.10 +import org.sonews.storage.StorageManager;
    3.11  
    3.12  /**
    3.13   * Class handling the GROUP command.
    3.14 @@ -78,9 +79,9 @@
    3.15  	{
    3.16  		final String[] command = line.split(" ");
    3.17  
    3.18 -		Channel group;
    3.19 +		Group group;
    3.20  		if (command.length >= 2) {
    3.21 -			group = Channel.getByName(command[1]);
    3.22 +			group = StorageManager.current().getGroup(command[1]);
    3.23  			if (group == null || group.isDeleted()) {
    3.24  				conn.println("411 no such news group");
    3.25  			} else {
     4.1 --- a/src/org/sonews/daemon/command/ListCommand.java	Sun Sep 11 14:19:19 2011 +0200
     4.2 +++ b/src/org/sonews/daemon/command/ListCommand.java	Sun Sep 11 15:05:04 2011 +0200
     4.3 @@ -24,7 +24,7 @@
     4.4  import java.util.regex.Pattern;
     4.5  import java.util.regex.PatternSyntaxException;
     4.6  import org.sonews.daemon.NNTPConnection;
     4.7 -import org.sonews.storage.Channel;
     4.8 +import org.sonews.storage.Group;
     4.9  import org.sonews.storage.StorageBackendException;
    4.10  import org.sonews.util.Log;
    4.11  
    4.12 @@ -74,8 +74,8 @@
    4.13  				conn.println(".");
    4.14  			} else if (command[1].equalsIgnoreCase("NEWSGROUPS")) {
    4.15  				conn.println("215 information follows");
    4.16 -				final List<Channel> list = Channel.getAll();
    4.17 -				for (Channel g : list) {
    4.18 +				final List<Group> list = Group.getAll();
    4.19 +				for (Group g : list) {
    4.20  					conn.println(g.getName() + "\t" + "-");
    4.21  				}
    4.22  				conn.println(".");
    4.23 @@ -103,10 +103,10 @@
    4.24  	private void printGroupInfo(NNTPConnection conn, String pattern)
    4.25  		throws IOException, StorageBackendException
    4.26  	{
    4.27 -		final List<Channel> groups = Channel.getAll();
    4.28 +		final List<Group> groups = Group.getAll();
    4.29  		if (groups != null) {
    4.30  			conn.println("215 list of newsgroups follows");
    4.31 -			for (Channel g : groups) {
    4.32 +			for (Group g : groups) {
    4.33  				try {
    4.34  					Matcher matcher = pattern == null
    4.35  						? null : Pattern.compile(pattern).matcher(g.getName());
     5.1 --- a/src/org/sonews/daemon/command/ListGroupCommand.java	Sun Sep 11 14:19:19 2011 +0200
     5.2 +++ b/src/org/sonews/daemon/command/ListGroupCommand.java	Sun Sep 11 15:05:04 2011 +0200
     5.3 @@ -15,14 +15,14 @@
     5.4   *   You should have received a copy of the GNU General Public License
     5.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     5.6   */
     5.7 -
     5.8  package org.sonews.daemon.command;
     5.9  
    5.10  import java.io.IOException;
    5.11  import java.util.List;
    5.12  import org.sonews.daemon.NNTPConnection;
    5.13 -import org.sonews.storage.Channel;
    5.14 +import org.sonews.storage.Group;
    5.15  import org.sonews.storage.StorageBackendException;
    5.16 +import org.sonews.storage.StorageManager;
    5.17  
    5.18  /**
    5.19   * Class handling the LISTGROUP command.
    5.20 @@ -30,42 +30,36 @@
    5.21   * @author Dennis Schwerdel
    5.22   * @since n3tpd/0.1
    5.23   */
    5.24 -public class ListGroupCommand implements Command
    5.25 -{
    5.26 +public class ListGroupCommand implements Command {
    5.27  
    5.28  	@Override
    5.29 -	public String[] getSupportedCommandStrings()
    5.30 -	{
    5.31 -		return new String[] {"LISTGROUP"};
    5.32 +	public String[] getSupportedCommandStrings() {
    5.33 +		return new String[]{"LISTGROUP"};
    5.34  	}
    5.35  
    5.36  	@Override
    5.37 -	public boolean hasFinished()
    5.38 -	{
    5.39 +	public boolean hasFinished() {
    5.40  		return true;
    5.41  	}
    5.42  
    5.43  	@Override
    5.44 -	public String impliedCapability()
    5.45 -	{
    5.46 +	public String impliedCapability() {
    5.47  		return null;
    5.48  	}
    5.49  
    5.50  	@Override
    5.51 -	public boolean isStateful()
    5.52 -	{
    5.53 +	public boolean isStateful() {
    5.54  		return false;
    5.55  	}
    5.56  
    5.57  	@Override
    5.58  	public void processLine(NNTPConnection conn, final String commandName, byte[] raw)
    5.59 -		throws IOException, StorageBackendException
    5.60 -	{
    5.61 +			throws IOException, StorageBackendException {
    5.62  		final String[] command = commandName.split(" ");
    5.63  
    5.64 -		Channel group;
    5.65 +		Group group;
    5.66  		if (command.length >= 2) {
    5.67 -			group = Channel.getByName(command[1]);
    5.68 +			group = StorageManager.current().getGroup(command[1]);
    5.69  		} else {
    5.70  			group = conn.getCurrentChannel();
    5.71  		}
    5.72 @@ -77,8 +71,8 @@
    5.73  
    5.74  		List<Long> ids = group.getArticleNumbers();
    5.75  		conn.println("211 " + ids.size() + " "
    5.76 -			+ group.getFirstArticleNumber() + " "
    5.77 -			+ group.getLastArticleNumber() + " list of article numbers follow");
    5.78 +				+ group.getFirstArticleNumber() + " "
    5.79 +				+ group.getLastArticleNumber() + " list of article numbers follow");
    5.80  		for (long id : ids) {
    5.81  			// One index number per line
    5.82  			conn.println(Long.toString(id));
     6.1 --- a/src/org/sonews/daemon/command/NextPrevCommand.java	Sun Sep 11 14:19:19 2011 +0200
     6.2 +++ b/src/org/sonews/daemon/command/NextPrevCommand.java	Sun Sep 11 15:05:04 2011 +0200
     6.3 @@ -15,13 +15,12 @@
     6.4   *   You should have received a copy of the GNU General Public License
     6.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     6.6   */
     6.7 -
     6.8  package org.sonews.daemon.command;
     6.9  
    6.10  import java.io.IOException;
    6.11  import org.sonews.daemon.NNTPConnection;
    6.12  import org.sonews.storage.Article;
    6.13 -import org.sonews.storage.Channel;
    6.14 +import org.sonews.storage.Group;
    6.15  import org.sonews.storage.StorageBackendException;
    6.16  
    6.17  /**
    6.18 @@ -30,39 +29,33 @@
    6.19   * @author Dennis Schwerdel
    6.20   * @since n3tpd/0.1
    6.21   */
    6.22 -public class NextPrevCommand implements Command
    6.23 -{
    6.24 +public class NextPrevCommand implements Command {
    6.25  
    6.26  	@Override
    6.27 -	public String[] getSupportedCommandStrings()
    6.28 -	{
    6.29 -		return new String[] {"NEXT", "PREV"};
    6.30 +	public String[] getSupportedCommandStrings() {
    6.31 +		return new String[]{"NEXT", "PREV"};
    6.32  	}
    6.33  
    6.34  	@Override
    6.35 -	public boolean hasFinished()
    6.36 -	{
    6.37 +	public boolean hasFinished() {
    6.38  		return true;
    6.39  	}
    6.40  
    6.41  	@Override
    6.42 -	public String impliedCapability()
    6.43 -	{
    6.44 +	public String impliedCapability() {
    6.45  		return null;
    6.46  	}
    6.47  
    6.48  	@Override
    6.49 -	public boolean isStateful()
    6.50 -	{
    6.51 +	public boolean isStateful() {
    6.52  		return false;
    6.53  	}
    6.54  
    6.55  	@Override
    6.56  	public void processLine(NNTPConnection conn, final String line, byte[] raw)
    6.57 -		throws IOException, StorageBackendException
    6.58 -	{
    6.59 +			throws IOException, StorageBackendException {
    6.60  		final Article currA = conn.getCurrentArticle();
    6.61 -		final Channel currG = conn.getCurrentChannel();
    6.62 +		final Group currG = conn.getCurrentChannel();
    6.63  
    6.64  		if (currA == null) {
    6.65  			conn.println("420 no current article has been selected");
    6.66 @@ -85,10 +78,9 @@
    6.67  		}
    6.68  	}
    6.69  
    6.70 -	private void selectNewArticle(NNTPConnection conn, Article article, Channel grp,
    6.71 -		final int delta)
    6.72 -		throws IOException, StorageBackendException
    6.73 -	{
    6.74 +	private void selectNewArticle(NNTPConnection conn, Article article, Group grp,
    6.75 +			final int delta)
    6.76 +			throws IOException, StorageBackendException {
    6.77  		assert article != null;
    6.78  
    6.79  		article = grp.getArticle(grp.getIndexOf(article) + delta);
    6.80 @@ -98,8 +90,8 @@
    6.81  		} else {
    6.82  			conn.setCurrentArticle(article);
    6.83  			conn.println("223 " + conn.getCurrentChannel().getIndexOf(article)
    6.84 -				+ " " + article.getMessageID()
    6.85 -				+ " article retrieved - request text separately");
    6.86 +					+ " " + article.getMessageID()
    6.87 +					+ " article retrieved - request text separately");
    6.88  		}
    6.89  	}
    6.90  }
     7.1 --- a/src/org/sonews/daemon/command/StatCommand.java	Sun Sep 11 14:19:19 2011 +0200
     7.2 +++ b/src/org/sonews/daemon/command/StatCommand.java	Sun Sep 11 15:05:04 2011 +0200
     7.3 @@ -15,7 +15,6 @@
     7.4   *   You should have received a copy of the GNU General Public License
     7.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     7.6   */
     7.7 -
     7.8  package org.sonews.daemon.command;
     7.9  
    7.10  import java.io.IOException;
    7.11 @@ -28,38 +27,32 @@
    7.12   * @author Christian Lins
    7.13   * @since sonews/0.5.0
    7.14   */
    7.15 -public class StatCommand implements Command
    7.16 -{
    7.17 +public class StatCommand implements Command {
    7.18  
    7.19  	@Override
    7.20 -	public String[] getSupportedCommandStrings()
    7.21 -	{
    7.22 -		return new String[] {"STAT"};
    7.23 +	public String[] getSupportedCommandStrings() {
    7.24 +		return new String[]{"STAT"};
    7.25  	}
    7.26  
    7.27  	@Override
    7.28 -	public boolean hasFinished()
    7.29 -	{
    7.30 +	public boolean hasFinished() {
    7.31  		return true;
    7.32  	}
    7.33  
    7.34  	@Override
    7.35 -	public String impliedCapability()
    7.36 -	{
    7.37 +	public String impliedCapability() {
    7.38  		return null;
    7.39  	}
    7.40  
    7.41  	@Override
    7.42 -	public boolean isStateful()
    7.43 -	{
    7.44 +	public boolean isStateful() {
    7.45  		return false;
    7.46  	}
    7.47  
    7.48  	// TODO: Method has various exit points => Refactor!
    7.49  	@Override
    7.50  	public void processLine(NNTPConnection conn, final String line, byte[] raw)
    7.51 -		throws IOException, StorageBackendException
    7.52 -	{
    7.53 +			throws IOException, StorageBackendException {
    7.54  		final String[] command = line.split(" ");
    7.55  
    7.56  		Article article = null;
    7.57 @@ -94,7 +87,7 @@
    7.58  		}
    7.59  
    7.60  		conn.println("223 " + conn.getCurrentChannel().getIndexOf(article) + " "
    7.61 -			+ article.getMessageID()
    7.62 -			+ " article retrieved - request text separately");
    7.63 +				+ article.getMessageID()
    7.64 +				+ " article retrieved - request text separately");
    7.65  	}
    7.66  }
     8.1 --- a/src/org/sonews/daemon/command/XDaemonCommand.java	Sun Sep 11 14:19:19 2011 +0200
     8.2 +++ b/src/org/sonews/daemon/command/XDaemonCommand.java	Sun Sep 11 15:05:04 2011 +0200
     8.3 @@ -27,7 +27,6 @@
     8.4  import org.sonews.storage.StorageManager;
     8.5  import org.sonews.feed.FeedManager;
     8.6  import org.sonews.feed.Subscription;
     8.7 -import org.sonews.storage.Channel;
     8.8  import org.sonews.storage.Group;
     8.9  import org.sonews.util.Stats;
    8.10  
    8.11 @@ -132,19 +131,19 @@
    8.12  				String flagName = commands[4];
    8.13  				if(commands[3].equalsIgnoreCase("SET")) {
    8.14  					if(flagName.equals("MAILINGLIST")) {
    8.15 -						group.setFlag(Channel.MAILINGLIST);
    8.16 +						group.setFlag(Group.MAILINGLIST);
    8.17  					} else if(flagName.equals("DELETED")) {
    8.18 -						group.setFlag(Channel.DELETED);
    8.19 +						group.setFlag(Group.DELETED);
    8.20  					} else if(flagName.equals("READONLY")) {
    8.21 -						group.setFlag(Channel.READONLY);
    8.22 +						group.setFlag(Group.READONLY);
    8.23  					}
    8.24  				} else if(commands[3].equalsIgnoreCase("UNSET")) {
    8.25  					if(flagName.equals("MAILINGLIST")) {
    8.26 -						group.unsetFlag(Channel.MAILINGLIST);
    8.27 +						group.unsetFlag(Group.MAILINGLIST);
    8.28  					} else if(flagName.equals("DELETED")) {
    8.29 -						group.unsetFlag(Channel.DELETED);
    8.30 +						group.unsetFlag(Group.DELETED);
    8.31  					} else if(flagName.equals("READONLY")) {
    8.32 -						group.unsetFlag(Channel.READONLY);
    8.33 +						group.unsetFlag(Group.READONLY);
    8.34  					}
    8.35  				} else {
    8.36  					conn.println("500 invalid command usage");
    8.37 @@ -168,7 +167,7 @@
    8.38  			} else if (commands.length >= 3 && commands[1].equalsIgnoreCase("LOG")) {
    8.39  				Group group = null;
    8.40  				if (commands.length > 3) {
    8.41 -					group = (Group) Channel.getByName(commands[3]);
    8.42 +					group = StorageManager.current().getGroup(commands[3]);
    8.43  				}
    8.44  
    8.45  				if (commands[2].equalsIgnoreCase("CONNECTED_CLIENTS")) {
     9.1 --- a/src/org/sonews/storage/Channel.java	Sun Sep 11 14:19:19 2011 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,103 +0,0 @@
     9.4 -/*
     9.5 - *   SONEWS News Server
     9.6 - *   see AUTHORS for the list of contributors
     9.7 - *
     9.8 - *   This program is free software: you can redistribute it and/or modify
     9.9 - *   it under the terms of the GNU General Public License as published by
    9.10 - *   the Free Software Foundation, either version 3 of the License, or
    9.11 - *   (at your option) any later version.
    9.12 - *
    9.13 - *   This program is distributed in the hope that it will be useful,
    9.14 - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 - *   GNU General Public License for more details.
    9.17 - *
    9.18 - *   You should have received a copy of the GNU General Public License
    9.19 - *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    9.20 - */
    9.21 -package org.sonews.storage;
    9.22 -
    9.23 -import java.util.ArrayList;
    9.24 -import java.util.List;
    9.25 -import org.sonews.util.Pair;
    9.26 -
    9.27 -/**
    9.28 - * A logical communication Channel is the a generic structural element for sets
    9.29 - * of messages; e.g. a Newsgroup for a set of Articles.
    9.30 - * A Channel can either be a real set of messages or an aggregated set of
    9.31 - * several subsets.
    9.32 - * @author Christian Lins
    9.33 - * @since sonews/1.0
    9.34 - */
    9.35 -public abstract class Channel {
    9.36 -
    9.37 -	/**
    9.38 -	 * If this flag is set the Group is no real newsgroup but a mailing list
    9.39 -	 * mirror. In that case every posting and receiving mails must go through
    9.40 -	 * the mailing list gateway.
    9.41 -	 */
    9.42 -	public static final int MAILINGLIST = 0x1;
    9.43 -	/**
    9.44 -	 * If this flag is set the Group is marked as readonly and the posting
    9.45 -	 * is prohibited. This can be useful for groups that are synced only in
    9.46 -	 * one direction.
    9.47 -	 */
    9.48 -	public static final int READONLY = 0x2;
    9.49 -	/**
    9.50 -	 * If this flag is set the Group is marked as deleted and must not occur
    9.51 -	 * in any output. The deletion is done lazily by a low priority daemon.
    9.52 -	 */
    9.53 -	public static final int DELETED = 0x80;
    9.54 -
    9.55 -	public static List<Channel> getAll() {
    9.56 -		List<Channel> all = new ArrayList<Channel>();
    9.57 -
    9.58 -		/*List<Channel> agroups = AggregatedGroup.getAll();
    9.59 -		if(agroups != null)
    9.60 -		{
    9.61 -		all.addAll(agroups);
    9.62 -		}*/
    9.63 -
    9.64 -		List<Channel> groups = Group.getAll();
    9.65 -		if (groups != null) {
    9.66 -			all.addAll(groups);
    9.67 -		}
    9.68 -
    9.69 -		return all;
    9.70 -	}
    9.71 -
    9.72 -	public static Channel getByName(String name)
    9.73 -			throws StorageBackendException {
    9.74 -		return StorageManager.current().getGroup(name);
    9.75 -	}
    9.76 -
    9.77 -	public abstract Article getArticle(long idx)
    9.78 -			throws StorageBackendException;
    9.79 -
    9.80 -	public abstract List<Pair<Long, ArticleHead>> getArticleHeads(
    9.81 -			final long first, final long last)
    9.82 -			throws StorageBackendException;
    9.83 -
    9.84 -	public abstract List<Long> getArticleNumbers()
    9.85 -			throws StorageBackendException;
    9.86 -
    9.87 -	public abstract long getFirstArticleNumber()
    9.88 -			throws StorageBackendException;
    9.89 -
    9.90 -	public abstract long getIndexOf(Article art)
    9.91 -			throws StorageBackendException;
    9.92 -
    9.93 -	public abstract long getInternalID();
    9.94 -
    9.95 -	public abstract long getLastArticleNumber()
    9.96 -			throws StorageBackendException;
    9.97 -
    9.98 -	public abstract String getName();
    9.99 -
   9.100 -	public abstract long getPostingsCount()
   9.101 -			throws StorageBackendException;
   9.102 -
   9.103 -	public abstract boolean isDeleted();
   9.104 -
   9.105 -	public abstract boolean isWriteable();
   9.106 -}
    10.1 --- a/src/org/sonews/storage/Group.java	Sun Sep 11 14:19:19 2011 +0200
    10.2 +++ b/src/org/sonews/storage/Group.java	Sun Sep 11 15:05:04 2011 +0200
    10.3 @@ -27,7 +27,7 @@
    10.4   * @author Christian Lins
    10.5   * @since sonews/0.5.0
    10.6   */
    10.7 -public class Group extends Channel {
    10.8 +public class Group {
    10.9  
   10.10  	/**
   10.11  	 * If this flag is set the Group is no real newsgroup but a mailing list
   10.12 @@ -56,7 +56,7 @@
   10.13  	/**
   10.14  	 * @return List of all groups this server handles.
   10.15  	 */
   10.16 -	public static List<Channel> getAll() {
   10.17 +	public static List<Group> getAll() {
   10.18  		try {
   10.19  			return StorageManager.current().getGroups();
   10.20  		} catch (StorageBackendException ex) {
    11.1 --- a/src/org/sonews/storage/Storage.java	Sun Sep 11 14:19:19 2011 +0200
    11.2 +++ b/src/org/sonews/storage/Storage.java	Sun Sep 11 15:05:04 2011 +0200
    11.3 @@ -60,7 +60,7 @@
    11.4  	List<Pair<Long, ArticleHead>> getArticleHeads(Group group, long first, long last)
    11.5  			throws StorageBackendException;
    11.6  
    11.7 -	List<Pair<Long, String>> getArticleHeaders(Channel channel, long start, long end,
    11.8 +	List<Pair<Long, String>> getArticleHeaders(Group group, long start, long end,
    11.9  			String header, String pattern)
   11.10  			throws StorageBackendException;
   11.11  
   11.12 @@ -74,7 +74,7 @@
   11.13  			throws StorageBackendException;
   11.14  
   11.15  	int getEventsCount(int eventType, long startTimestamp, long endTimestamp,
   11.16 -			Channel channel)
   11.17 +			Group group)
   11.18  			throws StorageBackendException;
   11.19  
   11.20  	double getEventsPerHour(int key, long gid)
   11.21 @@ -86,7 +86,7 @@
   11.22  	Group getGroup(String name)
   11.23  			throws StorageBackendException;
   11.24  
   11.25 -	List<Channel> getGroups()
   11.26 +	List<Group> getGroups()
   11.27  			throws StorageBackendException;
   11.28  
   11.29  	/**
    12.1 --- a/src/org/sonews/storage/impl/HSQLDB.java	Sun Sep 11 14:19:19 2011 +0200
    12.2 +++ b/src/org/sonews/storage/impl/HSQLDB.java	Sun Sep 11 15:05:04 2011 +0200
    12.3 @@ -18,9 +18,8 @@
    12.4  package org.sonews.storage.impl;
    12.5  
    12.6  import java.sql.SQLException;
    12.7 -import org.sonews.storage.Channel;
    12.8 +import org.sonews.storage.Group;
    12.9  import org.sonews.storage.Storage;
   12.10 -import org.sonews.storage.StorageBackendException;
   12.11  
   12.12  /**
   12.13   * A specialized JDBCDatabase supporting HSQLDB.
   12.14 @@ -39,7 +38,7 @@
   12.15  	protected void prepareCountGroupsStatement() throws SQLException {
   12.16  		this.pstmtCountGroups = conn.prepareStatement(
   12.17  				"SELECT Count(group_id) FROM groups WHERE "
   12.18 -				+ "BITAND(flags, " + Channel.DELETED + ") = 0");
   12.19 +				+ "BITAND(flags, " + Group.DELETED + ") = 0");
   12.20  	}
   12.21  
   12.22  	@Override
    13.1 --- a/src/org/sonews/storage/impl/JDBCDatabase.java	Sun Sep 11 14:19:19 2011 +0200
    13.2 +++ b/src/org/sonews/storage/impl/JDBCDatabase.java	Sun Sep 11 15:05:04 2011 +0200
    13.3 @@ -38,7 +38,6 @@
    13.4  import org.sonews.feed.Subscription;
    13.5  import org.sonews.storage.Article;
    13.6  import org.sonews.storage.ArticleHead;
    13.7 -import org.sonews.storage.Channel;
    13.8  import org.sonews.storage.Group;
    13.9  import org.sonews.storage.Storage;
   13.10  import org.sonews.storage.StorageBackendException;
   13.11 @@ -106,7 +105,7 @@
   13.12  	protected void prepareCountGroupsStatement() throws SQLException {
   13.13  		this.pstmtCountGroups = conn.prepareStatement(
   13.14  				"SELECT Count(group_id) FROM groups WHERE "
   13.15 -				+ "flags & " + Channel.DELETED + " = 0");
   13.16 +				+ "flags & " + Group.DELETED + " = 0");
   13.17  	}
   13.18  
   13.19  	protected void prepareGetPostingsCountStatement() throws SQLException {
   13.20 @@ -610,7 +609,7 @@
   13.21  	 * @throws StorageBackendException
   13.22  	 */
   13.23  	@Override
   13.24 -	public List<Pair<Long, String>> getArticleHeaders(Channel group, long start,
   13.25 +	public List<Pair<Long, String>> getArticleHeaders(Group group, long start,
   13.26  		long end, String headerKey, String patStr)
   13.27  		throws StorageBackendException, PatternSyntaxException
   13.28  	{
   13.29 @@ -824,7 +823,7 @@
   13.30  	}
   13.31  
   13.32  	@Override
   13.33 -	public int getEventsCount(int type, long start, long end, Channel channel)
   13.34 +	public int getEventsCount(int type, long start, long end, Group channel)
   13.35  		throws StorageBackendException
   13.36  	{
   13.37  		ResultSet rs = null;
   13.38 @@ -868,11 +867,11 @@
   13.39  	 * @throws StorageBackendException
   13.40  	 */
   13.41  	@Override
   13.42 -	public List<Channel> getGroups()
   13.43 +	public List<Group> getGroups()
   13.44  		throws StorageBackendException
   13.45  	{
   13.46  		ResultSet rs;
   13.47 -		List<Channel> buffer = new ArrayList<Channel>();
   13.48 +		List<Group> buffer = new ArrayList<Group>();
   13.49  		Statement stmt = null;
   13.50  
   13.51  		try {
    14.1 --- a/src/org/sonews/util/Purger.java	Sun Sep 11 14:19:19 2011 +0200
    14.2 +++ b/src/org/sonews/util/Purger.java	Sun Sep 11 15:05:04 2011 +0200
    14.3 @@ -15,7 +15,6 @@
    14.4   *   You should have received a copy of the GNU General Public License
    14.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    14.6   */
    14.7 -
    14.8  package org.sonews.util;
    14.9  
   14.10  import java.util.Date;
   14.11 @@ -24,7 +23,6 @@
   14.12  import org.sonews.config.Config;
   14.13  import org.sonews.storage.Article;
   14.14  import org.sonews.storage.Headers;
   14.15 -import org.sonews.storage.Channel;
   14.16  import org.sonews.storage.Group;
   14.17  import org.sonews.storage.StorageBackendException;
   14.18  import org.sonews.storage.StorageManager;
   14.19 @@ -37,16 +35,14 @@
   14.20   * @author Christian Lins
   14.21   * @since sonews/0.5.0
   14.22   */
   14.23 -public class Purger extends AbstractDaemon
   14.24 -{
   14.25 +public class Purger extends AbstractDaemon {
   14.26  
   14.27  	/**
   14.28  	 * Loops through all messages and deletes them if their time
   14.29  	 * has come.
   14.30  	 */
   14.31  	@Override
   14.32 -	public void run()
   14.33 -	{
   14.34 +	public void run() {
   14.35  		try {
   14.36  			while (isRunning()) {
   14.37  				purgeDeleted();
   14.38 @@ -62,10 +58,9 @@
   14.39  	}
   14.40  
   14.41  	private void purgeDeleted()
   14.42 -		throws StorageBackendException
   14.43 -	{
   14.44 -		List<Channel> groups = StorageManager.current().getGroups();
   14.45 -		for (Channel channel : groups) {
   14.46 +			throws StorageBackendException {
   14.47 +		List<Group> groups = StorageManager.current().getGroups();
   14.48 +		for (Group channel : groups) {
   14.49  			if (!(channel instanceof Group)) {
   14.50  				continue;
   14.51  			}
   14.52 @@ -89,12 +84,11 @@
   14.53  	}
   14.54  
   14.55  	private void purgeOutdated()
   14.56 -		throws InterruptedException, StorageBackendException
   14.57 -	{
   14.58 +			throws InterruptedException, StorageBackendException {
   14.59  		long articleMaximum =
   14.60 -			Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE);
   14.61 +				Config.inst().get("sonews.article.maxnum", Long.MAX_VALUE);
   14.62  		long lifetime =
   14.63 -			Config.inst().get("sonews.article.lifetime", -1);
   14.64 +				Config.inst().get("sonews.article.lifetime", -1);
   14.65  
   14.66  		if (lifetime > 0 || articleMaximum < Stats.getInstance().getNumberOfNews()) {
   14.67  			Log.get().info("Purging old messages...");
    15.1 --- a/src/org/sonews/util/Stats.java	Sun Sep 11 14:19:19 2011 +0200
    15.2 +++ b/src/org/sonews/util/Stats.java	Sun Sep 11 15:05:04 2011 +0200
    15.3 @@ -15,12 +15,11 @@
    15.4   *   You should have received a copy of the GNU General Public License
    15.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15.6   */
    15.7 -
    15.8  package org.sonews.util;
    15.9  
   15.10  import java.util.Calendar;
   15.11  import org.sonews.config.Config;
   15.12 -import org.sonews.storage.Channel;
   15.13 +import org.sonews.storage.Group;
   15.14  import org.sonews.storage.StorageBackendException;
   15.15  import org.sonews.storage.StorageManager;
   15.16  
   15.17 @@ -29,8 +28,7 @@
   15.18   * @author Christian Lins
   15.19   * @since sonews/0.5.0
   15.20   */
   15.21 -public final class Stats
   15.22 -{
   15.23 +public final class Stats {
   15.24  
   15.25  	public static final byte CONNECTIONS = 1;
   15.26  	public static final byte POSTED_NEWS = 2;
   15.27 @@ -40,15 +38,14 @@
   15.28  	public static final byte MLGW_RUNEND = 6;
   15.29  	private static Stats instance = new Stats();
   15.30  
   15.31 -	public static Stats getInstance()
   15.32 -	{
   15.33 +	public static Stats getInstance() {
   15.34  		return Stats.instance;
   15.35  	}
   15.36  
   15.37 -	private Stats()
   15.38 -	{
   15.39 +	private volatile int connectedClients = 0;
   15.40 +
   15.41 +	private Stats() {
   15.42  	}
   15.43 -	private volatile int connectedClients = 0;
   15.44  
   15.45  	/**
   15.46  	 * A generic method that writes event data to the storage backend.
   15.47 @@ -57,15 +54,13 @@
   15.48  	 * @param type
   15.49  	 * @param groupname
   15.50  	 */
   15.51 -	private void addEvent(byte type, String groupname)
   15.52 -	{
   15.53 +	private void addEvent(byte type, String groupname) {
   15.54  		try {
   15.55  			if (Config.inst().get(Config.EVENTLOG, true)) {
   15.56 -
   15.57 -				Channel group = Channel.getByName(groupname);
   15.58 +				Group group = StorageManager.current().getGroup(groupname);
   15.59  				if (group != null) {
   15.60  					StorageManager.current().addEvent(
   15.61 -						System.currentTimeMillis(), type, group.getInternalID());
   15.62 +							System.currentTimeMillis(), type, group.getInternalID());
   15.63  				}
   15.64  			} else {
   15.65  				Log.get().info("Group " + groupname + " does not exist.");
   15.66 @@ -75,23 +70,19 @@
   15.67  		}
   15.68  	}
   15.69  
   15.70 -	public void clientConnect()
   15.71 -	{
   15.72 +	public void clientConnect() {
   15.73  		this.connectedClients++;
   15.74  	}
   15.75  
   15.76 -	public void clientDisconnect()
   15.77 -	{
   15.78 +	public void clientDisconnect() {
   15.79  		this.connectedClients--;
   15.80  	}
   15.81  
   15.82 -	public int connectedClients()
   15.83 -	{
   15.84 +	public int connectedClients() {
   15.85  		return this.connectedClients;
   15.86  	}
   15.87  
   15.88 -	public int getNumberOfGroups()
   15.89 -	{
   15.90 +	public int getNumberOfGroups() {
   15.91  		try {
   15.92  			return StorageManager.current().countGroups();
   15.93  		} catch (StorageBackendException ex) {
   15.94 @@ -100,8 +91,7 @@
   15.95  		}
   15.96  	}
   15.97  
   15.98 -	public int getNumberOfNews()
   15.99 -	{
  15.100 +	public int getNumberOfNews() {
  15.101  		try {
  15.102  			return StorageManager.current().countArticles();
  15.103  		} catch (StorageBackendException ex) {
  15.104 @@ -111,8 +101,7 @@
  15.105  	}
  15.106  
  15.107  	public int getYesterdaysEvents(final byte eventType, final int hour,
  15.108 -		final Channel group)
  15.109 -	{
  15.110 +			final Group group) {
  15.111  		// Determine the timestamp values for yesterday and the given hour
  15.112  		Calendar cal = Calendar.getInstance();
  15.113  		int year = cal.get(Calendar.YEAR);
  15.114 @@ -133,33 +122,27 @@
  15.115  		}
  15.116  	}
  15.117  
  15.118 -	public void mailPosted(String groupname)
  15.119 -	{
  15.120 +	public void mailPosted(String groupname) {
  15.121  		addEvent(POSTED_NEWS, groupname);
  15.122  	}
  15.123  
  15.124 -	public void mailGatewayed(String groupname)
  15.125 -	{
  15.126 +	public void mailGatewayed(String groupname) {
  15.127  		addEvent(GATEWAYED_NEWS, groupname);
  15.128  	}
  15.129  
  15.130 -	public void mailFeeded(String groupname)
  15.131 -	{
  15.132 +	public void mailFeeded(String groupname) {
  15.133  		addEvent(FEEDED_NEWS, groupname);
  15.134  	}
  15.135  
  15.136 -	public void mlgwRunStart()
  15.137 -	{
  15.138 +	public void mlgwRunStart() {
  15.139  		addEvent(MLGW_RUNSTART, "control");
  15.140  	}
  15.141  
  15.142 -	public void mlgwRunEnd()
  15.143 -	{
  15.144 +	public void mlgwRunEnd() {
  15.145  		addEvent(MLGW_RUNEND, "control");
  15.146  	}
  15.147  
  15.148 -	private double perHour(int key, long gid)
  15.149 -	{
  15.150 +	private double perHour(int key, long gid) {
  15.151  		try {
  15.152  			return StorageManager.current().getEventsPerHour(key, gid);
  15.153  		} catch (StorageBackendException ex) {
  15.154 @@ -168,18 +151,15 @@
  15.155  		}
  15.156  	}
  15.157  
  15.158 -	public double postedPerHour(long gid)
  15.159 -	{
  15.160 +	public double postedPerHour(long gid) {
  15.161  		return perHour(POSTED_NEWS, gid);
  15.162  	}
  15.163  
  15.164 -	public double gatewayedPerHour(long gid)
  15.165 -	{
  15.166 +	public double gatewayedPerHour(long gid) {
  15.167  		return perHour(GATEWAYED_NEWS, gid);
  15.168  	}
  15.169  
  15.170 -	public double feededPerHour(long gid)
  15.171 -	{
  15.172 +	public double feededPerHour(long gid) {
  15.173  		return perHour(FEEDED_NEWS, gid);
  15.174  	}
  15.175  }