# HG changeset patch
# User cli
# Date 1251276471 -7200
# Node ID 2541bdb54cb224c9904d64a7e425a9d6dfdaf790
# Parent 4b2c8bedb094c125997fa79cc4dc77f99ff87bbe
Not longer required to restart server when changing peering settings (#547).
diff -r 4b2c8bedb094 -r 2541bdb54cb2 org/sonews/feed/AbstractFeeder.java
--- a/org/sonews/feed/AbstractFeeder.java Mon Aug 24 14:40:37 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +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.feed;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.sonews.daemon.AbstractDaemon;
-
-/**
- * Base class for PullFeeder and PushFeeder.
- * @author Christian Lins
- * @since sonews/0.5.0
- */
-abstract class AbstractFeeder extends AbstractDaemon
-{
-
- /** List of subscriptions that is processed by this feeder */
- protected List subscriptions = new ArrayList();
-
- public void addSubscription(final Subscription sub)
- {
- this.subscriptions.add(sub);
- }
-
-}
diff -r 4b2c8bedb094 -r 2541bdb54cb2 org/sonews/feed/FeedManager.java
--- a/org/sonews/feed/FeedManager.java Mon Aug 24 14:40:37 2009 +0200
+++ b/org/sonews/feed/FeedManager.java Wed Aug 26 10:47:51 2009 +0200
@@ -18,10 +18,7 @@
package org.sonews.feed;
-import java.util.List;
import org.sonews.storage.Article;
-import org.sonews.storage.StorageBackendException;
-import org.sonews.storage.StorageManager;
/**
* Controlls push and pull feeder.
@@ -42,22 +39,8 @@
* PullFeeder or PushFeeder.
*/
public static synchronized void startFeeding()
- throws StorageBackendException
{
- List subsPull = StorageManager.current()
- .getSubscriptions(TYPE_PULL);
- for(Subscription sub : subsPull)
- {
- pullFeeder.addSubscription(sub);
- }
pullFeeder.start();
-
- List subsPush = StorageManager.current()
- .getSubscriptions(TYPE_PUSH);
- for(Subscription sub : subsPush)
- {
- pushFeeder.addSubscription(sub);
- }
pushFeeder.start();
}
diff -r 4b2c8bedb094 -r 2541bdb54cb2 org/sonews/feed/PullFeeder.java
--- a/org/sonews/feed/PullFeeder.java Mon Aug 24 14:40:37 2009 +0200
+++ b/org/sonews/feed/PullFeeder.java Wed Aug 26 10:47:51 2009 +0200
@@ -27,9 +27,13 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
import org.sonews.config.Config;
+import org.sonews.daemon.AbstractDaemon;
import org.sonews.util.Log;
import org.sonews.storage.StorageBackendException;
import org.sonews.storage.StorageManager;
@@ -43,20 +47,23 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-class PullFeeder extends AbstractFeeder
+class PullFeeder extends AbstractDaemon
{
private Map highMarks = new HashMap();
private BufferedReader in;
private PrintWriter out;
+ private Set subscriptions = new HashSet();
- @Override
- public void addSubscription(final Subscription sub)
+ private void addSubscription(final Subscription sub)
{
- super.addSubscription(sub);
-
- // Set a initial highMark
- this.highMarks.put(sub, 0);
+ subscriptions.add(sub);
+
+ if(!highMarks.containsKey(sub))
+ {
+ // Set a initial highMark
+ this.highMarks.put(sub, 0);
+ }
}
/**
@@ -167,6 +174,21 @@
try
{
+ this.subscriptions.clear();
+ List subsPull = StorageManager.current()
+ .getSubscriptions(FeedManager.TYPE_PULL);
+ for(Subscription sub : subsPull)
+ {
+ addSubscription(sub);
+ }
+ }
+ catch(StorageBackendException ex)
+ {
+ Log.get().log(Level.SEVERE, host, ex);
+ }
+
+ try
+ {
for(Subscription sub : this.subscriptions)
{
host = sub.getHost();
diff -r 4b2c8bedb094 -r 2541bdb54cb2 org/sonews/feed/PushFeeder.java
--- a/org/sonews/feed/PushFeeder.java Mon Aug 24 14:40:37 2009 +0200
+++ b/org/sonews/feed/PushFeeder.java Wed Aug 26 10:47:51 2009 +0200
@@ -19,9 +19,13 @@
package org.sonews.feed;
import java.io.IOException;
+import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.sonews.daemon.AbstractDaemon;
import org.sonews.storage.Article;
import org.sonews.storage.Headers;
+import org.sonews.storage.StorageBackendException;
+import org.sonews.storage.StorageManager;
import org.sonews.util.Log;
import org.sonews.util.io.ArticleWriter;
@@ -31,7 +35,7 @@
* @author Christian Lins
* @since sonews/0.5.0
*/
-class PushFeeder extends AbstractFeeder
+class PushFeeder extends AbstractDaemon
{
private ConcurrentLinkedQueue articleQueue =
@@ -49,10 +53,13 @@
this.wait();
}
+ List subscriptions = StorageManager.current()
+ .getSubscriptions(FeedManager.TYPE_PUSH);
+
Article article = this.articleQueue.poll();
String[] groups = article.getHeader(Headers.NEWSGROUPS)[0].split(",");
Log.get().info("PushFeed: " + article.getMessageID());
- for(Subscription sub : this.subscriptions)
+ for(Subscription sub : subscriptions)
{
// Circle check
if(article.getHeader(Headers.PATH)[0].contains(sub.getHost()))
@@ -88,6 +95,10 @@
}
}
}
+ catch(StorageBackendException ex)
+ {
+ Log.get().severe(ex.toString());
+ }
catch(InterruptedException ex)
{
Log.get().warning("PushFeeder interrupted: " + ex);
diff -r 4b2c8bedb094 -r 2541bdb54cb2 org/sonews/feed/Subscription.java
--- a/org/sonews/feed/Subscription.java Mon Aug 24 14:40:37 2009 +0200
+++ b/org/sonews/feed/Subscription.java Wed Aug 26 10:47:51 2009 +0200
@@ -40,6 +40,27 @@
this.group = group;
}
+ @Override
+ public boolean equals(Object obj)
+ {
+ if(obj instanceof Subscription)
+ {
+ Subscription sub = (Subscription)obj;
+ return sub.host.equals(host) && sub.group.equals(group)
+ && sub.port == port && sub.feedtype == feedtype;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return host.hashCode() + port + feedtype + group.hashCode();
+ }
+
public int getFeedtype()
{
return feedtype;