Not longer required to restart server when changing peering settings (#547).
authorcli
Wed, 26 Aug 2009 10:47:51 +0200
changeset 222541bdb54cb2
parent 21 4b2c8bedb094
child 23 e4345a26f81f
Not longer required to restart server when changing peering settings (#547).
org/sonews/feed/AbstractFeeder.java
org/sonews/feed/FeedManager.java
org/sonews/feed/PullFeeder.java
org/sonews/feed/PushFeeder.java
org/sonews/feed/Subscription.java
     1.1 --- a/org/sonews/feed/AbstractFeeder.java	Mon Aug 24 14:40:37 2009 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,41 +0,0 @@
     1.4 -/*
     1.5 - *   SONEWS News Server
     1.6 - *   see AUTHORS for the list of contributors
     1.7 - *
     1.8 - *   This program is free software: you can redistribute it and/or modify
     1.9 - *   it under the terms of the GNU General Public License as published by
    1.10 - *   the Free Software Foundation, either version 3 of the License, or
    1.11 - *   (at your option) any later version.
    1.12 - *
    1.13 - *   This program is distributed in the hope that it will be useful,
    1.14 - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 - *   GNU General Public License for more details.
    1.17 - *
    1.18 - *   You should have received a copy of the GNU General Public License
    1.19 - *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 - */
    1.21 -
    1.22 -package org.sonews.feed;
    1.23 -
    1.24 -import java.util.ArrayList;
    1.25 -import java.util.List;
    1.26 -import org.sonews.daemon.AbstractDaemon;
    1.27 -
    1.28 -/**
    1.29 - * Base class for PullFeeder and PushFeeder.
    1.30 - * @author Christian Lins
    1.31 - * @since sonews/0.5.0
    1.32 - */
    1.33 -abstract class AbstractFeeder extends AbstractDaemon
    1.34 -{
    1.35 -
    1.36 -  /** List of subscriptions that is processed by this feeder */
    1.37 -  protected List<Subscription> subscriptions = new ArrayList<Subscription>();
    1.38 -  
    1.39 -  public void addSubscription(final Subscription sub)
    1.40 -  {
    1.41 -    this.subscriptions.add(sub);
    1.42 -  }
    1.43 -  
    1.44 -}
     2.1 --- a/org/sonews/feed/FeedManager.java	Mon Aug 24 14:40:37 2009 +0200
     2.2 +++ b/org/sonews/feed/FeedManager.java	Wed Aug 26 10:47:51 2009 +0200
     2.3 @@ -18,10 +18,7 @@
     2.4  
     2.5  package org.sonews.feed;
     2.6  
     2.7 -import java.util.List;
     2.8  import org.sonews.storage.Article;
     2.9 -import org.sonews.storage.StorageBackendException;
    2.10 -import org.sonews.storage.StorageManager;
    2.11  
    2.12  /**
    2.13   * Controlls push and pull feeder.
    2.14 @@ -42,22 +39,8 @@
    2.15     * PullFeeder or PushFeeder.
    2.16     */
    2.17    public static synchronized void startFeeding()
    2.18 -    throws StorageBackendException
    2.19    {
    2.20 -    List<Subscription> subsPull = StorageManager.current()
    2.21 -      .getSubscriptions(TYPE_PULL);
    2.22 -    for(Subscription sub : subsPull)
    2.23 -    {
    2.24 -      pullFeeder.addSubscription(sub);
    2.25 -    }
    2.26      pullFeeder.start();
    2.27 -    
    2.28 -    List<Subscription> subsPush = StorageManager.current()
    2.29 -      .getSubscriptions(TYPE_PUSH);
    2.30 -    for(Subscription sub : subsPush)
    2.31 -    {
    2.32 -      pushFeeder.addSubscription(sub);
    2.33 -    }
    2.34      pushFeeder.start();
    2.35    }
    2.36    
     3.1 --- a/org/sonews/feed/PullFeeder.java	Mon Aug 24 14:40:37 2009 +0200
     3.2 +++ b/org/sonews/feed/PullFeeder.java	Wed Aug 26 10:47:51 2009 +0200
     3.3 @@ -27,9 +27,13 @@
     3.4  import java.net.UnknownHostException;
     3.5  import java.util.ArrayList;
     3.6  import java.util.HashMap;
     3.7 +import java.util.HashSet;
     3.8  import java.util.List;
     3.9  import java.util.Map;
    3.10 +import java.util.Set;
    3.11 +import java.util.logging.Level;
    3.12  import org.sonews.config.Config;
    3.13 +import org.sonews.daemon.AbstractDaemon;
    3.14  import org.sonews.util.Log;
    3.15  import org.sonews.storage.StorageBackendException;
    3.16  import org.sonews.storage.StorageManager;
    3.17 @@ -43,20 +47,23 @@
    3.18   * @author Christian Lins
    3.19   * @since sonews/0.5.0
    3.20   */
    3.21 -class PullFeeder extends AbstractFeeder
    3.22 +class PullFeeder extends AbstractDaemon
    3.23  {
    3.24    
    3.25    private Map<Subscription, Integer> highMarks = new HashMap<Subscription, Integer>();
    3.26    private BufferedReader             in;
    3.27    private PrintWriter                out;
    3.28 +  private Set<Subscription>          subscriptions = new HashSet<Subscription>();
    3.29    
    3.30 -  @Override
    3.31 -  public void addSubscription(final Subscription sub)
    3.32 +  private void addSubscription(final Subscription sub)
    3.33    {
    3.34 -    super.addSubscription(sub);
    3.35 -    
    3.36 -    // Set a initial highMark
    3.37 -    this.highMarks.put(sub, 0);
    3.38 +    subscriptions.add(sub);
    3.39 +
    3.40 +    if(!highMarks.containsKey(sub))
    3.41 +    {
    3.42 +      // Set a initial highMark
    3.43 +      this.highMarks.put(sub, 0);
    3.44 +    }
    3.45    }
    3.46    
    3.47    /**
    3.48 @@ -167,6 +174,21 @@
    3.49  
    3.50        try
    3.51        {
    3.52 +        this.subscriptions.clear();
    3.53 +        List<Subscription> subsPull = StorageManager.current()
    3.54 +          .getSubscriptions(FeedManager.TYPE_PULL);
    3.55 +        for(Subscription sub : subsPull)
    3.56 +        {
    3.57 +          addSubscription(sub);
    3.58 +        }
    3.59 +      }
    3.60 +      catch(StorageBackendException ex)
    3.61 +      {
    3.62 +        Log.get().log(Level.SEVERE, host, ex);
    3.63 +      }
    3.64 +
    3.65 +      try
    3.66 +      {
    3.67          for(Subscription sub : this.subscriptions)
    3.68          {
    3.69            host = sub.getHost();
     4.1 --- a/org/sonews/feed/PushFeeder.java	Mon Aug 24 14:40:37 2009 +0200
     4.2 +++ b/org/sonews/feed/PushFeeder.java	Wed Aug 26 10:47:51 2009 +0200
     4.3 @@ -19,9 +19,13 @@
     4.4  package org.sonews.feed;
     4.5  
     4.6  import java.io.IOException;
     4.7 +import java.util.List;
     4.8  import java.util.concurrent.ConcurrentLinkedQueue;
     4.9 +import org.sonews.daemon.AbstractDaemon;
    4.10  import org.sonews.storage.Article;
    4.11  import org.sonews.storage.Headers;
    4.12 +import org.sonews.storage.StorageBackendException;
    4.13 +import org.sonews.storage.StorageManager;
    4.14  import org.sonews.util.Log;
    4.15  import org.sonews.util.io.ArticleWriter;
    4.16  
    4.17 @@ -31,7 +35,7 @@
    4.18   * @author Christian Lins
    4.19   * @since sonews/0.5.0
    4.20   */
    4.21 -class PushFeeder extends AbstractFeeder
    4.22 +class PushFeeder extends AbstractDaemon
    4.23  {
    4.24    
    4.25    private ConcurrentLinkedQueue<Article> articleQueue = 
    4.26 @@ -49,10 +53,13 @@
    4.27            this.wait();
    4.28          }
    4.29          
    4.30 +        List<Subscription> subscriptions = StorageManager.current()
    4.31 +          .getSubscriptions(FeedManager.TYPE_PUSH);
    4.32 +
    4.33          Article  article = this.articleQueue.poll();
    4.34          String[] groups  = article.getHeader(Headers.NEWSGROUPS)[0].split(",");
    4.35          Log.get().info("PushFeed: " + article.getMessageID());
    4.36 -        for(Subscription sub : this.subscriptions)
    4.37 +        for(Subscription sub : subscriptions)
    4.38          {
    4.39            // Circle check
    4.40            if(article.getHeader(Headers.PATH)[0].contains(sub.getHost()))
    4.41 @@ -88,6 +95,10 @@
    4.42            }
    4.43          }
    4.44        }
    4.45 +      catch(StorageBackendException ex)
    4.46 +      {
    4.47 +        Log.get().severe(ex.toString());
    4.48 +      }
    4.49        catch(InterruptedException ex)
    4.50        {
    4.51          Log.get().warning("PushFeeder interrupted: " + ex);
     5.1 --- a/org/sonews/feed/Subscription.java	Mon Aug 24 14:40:37 2009 +0200
     5.2 +++ b/org/sonews/feed/Subscription.java	Wed Aug 26 10:47:51 2009 +0200
     5.3 @@ -40,6 +40,27 @@
     5.4      this.group    = group;
     5.5    }
     5.6  
     5.7 +  @Override
     5.8 +  public boolean equals(Object obj)
     5.9 +  {
    5.10 +    if(obj instanceof Subscription)
    5.11 +    {
    5.12 +      Subscription sub = (Subscription)obj;
    5.13 +      return sub.host.equals(host) && sub.group.equals(group) 
    5.14 +        && sub.port == port && sub.feedtype == feedtype;
    5.15 +    }
    5.16 +    else
    5.17 +    {
    5.18 +      return false;
    5.19 +    }
    5.20 +  }
    5.21 +
    5.22 +  @Override
    5.23 +  public int hashCode()
    5.24 +  {
    5.25 +    return host.hashCode() + port + feedtype + group.hashCode();
    5.26 +  }
    5.27 +
    5.28    public int getFeedtype()
    5.29    {
    5.30      return feedtype;