src/org/sonews/feed/PushFeeder.java
changeset 62 be4e87479855
parent 35 ed84c8bdd87b
     1.1 --- a/src/org/sonews/feed/PushFeeder.java	Sun Aug 29 17:28:58 2010 +0200
     1.2 +++ b/src/org/sonews/feed/PushFeeder.java	Wed Sep 14 23:25:00 2011 +0200
     1.3 @@ -37,82 +37,65 @@
     1.4   */
     1.5  class PushFeeder extends AbstractDaemon
     1.6  {
     1.7 -  
     1.8 -  private ConcurrentLinkedQueue<Article> articleQueue = 
     1.9 -    new ConcurrentLinkedQueue<Article>();
    1.10 -  
    1.11 -  @Override
    1.12 -  public void run()
    1.13 -  {
    1.14 -    while(isRunning())
    1.15 -    {
    1.16 -      try
    1.17 -      {
    1.18 -        synchronized(this)
    1.19 -        {
    1.20 -          this.wait();
    1.21 -        }
    1.22 -        
    1.23 -        List<Subscription> subscriptions = StorageManager.current()
    1.24 -          .getSubscriptions(FeedManager.TYPE_PUSH);
    1.25  
    1.26 -        Article  article = this.articleQueue.poll();
    1.27 -        String[] groups  = article.getHeader(Headers.NEWSGROUPS)[0].split(",");
    1.28 -        Log.get().info("PushFeed: " + article.getMessageID());
    1.29 -        for(Subscription sub : subscriptions)
    1.30 -        {
    1.31 -          // Circle check
    1.32 -          if(article.getHeader(Headers.PATH)[0].contains(sub.getHost()))
    1.33 -          {
    1.34 -            Log.get().info(article.getMessageID() + " skipped for host "
    1.35 -              + sub.getHost());
    1.36 -            continue;
    1.37 -          }
    1.38 +	private ConcurrentLinkedQueue<Article> articleQueue =
    1.39 +		new ConcurrentLinkedQueue<Article>();
    1.40  
    1.41 -          try
    1.42 -          {
    1.43 -            for(String group : groups)
    1.44 -            {
    1.45 -              if(sub.getGroup().equals(group))
    1.46 -              {
    1.47 -                // Delete headers that may cause problems
    1.48 -                article.removeHeader(Headers.NNTP_POSTING_DATE);
    1.49 -                article.removeHeader(Headers.NNTP_POSTING_HOST);
    1.50 -                article.removeHeader(Headers.X_COMPLAINTS_TO);
    1.51 -                article.removeHeader(Headers.X_TRACE);
    1.52 -                article.removeHeader(Headers.XREF);
    1.53 -                
    1.54 -                // POST the message to remote server
    1.55 -                ArticleWriter awriter = new ArticleWriter(sub.getHost(), sub.getPort());
    1.56 -                awriter.writeArticle(article);
    1.57 -                break;
    1.58 -              }
    1.59 -            }
    1.60 -          }
    1.61 -          catch(IOException ex)
    1.62 -          {
    1.63 -            Log.get().warning(ex.toString());
    1.64 -          }
    1.65 -        }
    1.66 -      }
    1.67 -      catch(StorageBackendException ex)
    1.68 -      {
    1.69 -        Log.get().severe(ex.toString());
    1.70 -      }
    1.71 -      catch(InterruptedException ex)
    1.72 -      {
    1.73 -        Log.get().warning("PushFeeder interrupted: " + ex);
    1.74 -      }
    1.75 -    }
    1.76 -  }
    1.77 -  
    1.78 -  public void queueForPush(Article article)
    1.79 -  {
    1.80 -    this.articleQueue.add(article);
    1.81 -    synchronized(this)
    1.82 -    {
    1.83 -      this.notifyAll();
    1.84 -    }
    1.85 -  }
    1.86 -  
    1.87 +	@Override
    1.88 +	public void run()
    1.89 +	{
    1.90 +		while (isRunning()) {
    1.91 +			try {
    1.92 +				synchronized (this) {
    1.93 +					this.wait();
    1.94 +				}
    1.95 +
    1.96 +				List<Subscription> subscriptions = StorageManager.current().getSubscriptions(FeedManager.TYPE_PUSH);
    1.97 +
    1.98 +				Article article = this.articleQueue.poll();
    1.99 +				String[] groups = article.getHeader(Headers.NEWSGROUPS)[0].split(",");
   1.100 +				Log.get().info("PushFeed: " + article.getMessageID());
   1.101 +				for (Subscription sub : subscriptions) {
   1.102 +					// Circle check
   1.103 +					if (article.getHeader(Headers.PATH)[0].contains(sub.getHost())) {
   1.104 +						Log.get().info(article.getMessageID() + " skipped for host "
   1.105 +							+ sub.getHost());
   1.106 +						continue;
   1.107 +					}
   1.108 +
   1.109 +					try {
   1.110 +						for (String group : groups) {
   1.111 +							if (sub.getGroup().equals(group)) {
   1.112 +								// Delete headers that may cause problems
   1.113 +								article.removeHeader(Headers.NNTP_POSTING_DATE);
   1.114 +								article.removeHeader(Headers.NNTP_POSTING_HOST);
   1.115 +								article.removeHeader(Headers.X_COMPLAINTS_TO);
   1.116 +								article.removeHeader(Headers.X_TRACE);
   1.117 +								article.removeHeader(Headers.XREF);
   1.118 +
   1.119 +								// POST the message to remote server
   1.120 +								ArticleWriter awriter = new ArticleWriter(sub.getHost(), sub.getPort());
   1.121 +								awriter.writeArticle(article);
   1.122 +								break;
   1.123 +							}
   1.124 +						}
   1.125 +					} catch (IOException ex) {
   1.126 +						Log.get().warning(ex.toString());
   1.127 +					}
   1.128 +				}
   1.129 +			} catch (StorageBackendException ex) {
   1.130 +				Log.get().severe(ex.toString());
   1.131 +			} catch (InterruptedException ex) {
   1.132 +				Log.get().warning("PushFeeder interrupted: " + ex);
   1.133 +			}
   1.134 +		}
   1.135 +	}
   1.136 +
   1.137 +	public void queueForPush(Article article)
   1.138 +	{
   1.139 +		this.articleQueue.add(article);
   1.140 +		synchronized (this) {
   1.141 +			this.notifyAll();
   1.142 +		}
   1.143 +	}
   1.144  }