Add some checks to prevent #13 happen.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.feed;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.concurrent.ConcurrentLinkedQueue;
24 import org.sonews.daemon.AbstractDaemon;
25 import org.sonews.storage.Article;
26 import org.sonews.storage.Headers;
27 import org.sonews.storage.StorageBackendException;
28 import org.sonews.storage.StorageManager;
29 import org.sonews.util.Log;
30 import org.sonews.util.io.ArticleWriter;
33 * Pushes new articles to remote newsservers. This feeder sleeps until a new
34 * message is posted to the sonews instance.
35 * @author Christian Lins
38 class PushFeeder extends AbstractDaemon
41 private ConcurrentLinkedQueue<Article> articleQueue =
42 new ConcurrentLinkedQueue<Article>();
56 List<Subscription> subscriptions = StorageManager.current()
57 .getSubscriptions(FeedManager.TYPE_PUSH);
59 Article article = this.articleQueue.poll();
60 String[] groups = article.getHeader(Headers.NEWSGROUPS)[0].split(",");
61 Log.get().info("PushFeed: " + article.getMessageID());
62 for(Subscription sub : subscriptions)
65 if(article.getHeader(Headers.PATH)[0].contains(sub.getHost()))
67 Log.get().info(article.getMessageID() + " skipped for host "
74 for(String group : groups)
76 if(sub.getGroup().equals(group))
78 // Delete headers that may cause problems
79 article.removeHeader(Headers.NNTP_POSTING_DATE);
80 article.removeHeader(Headers.NNTP_POSTING_HOST);
81 article.removeHeader(Headers.X_COMPLAINTS_TO);
82 article.removeHeader(Headers.X_TRACE);
83 article.removeHeader(Headers.XREF);
85 // POST the message to remote server
86 ArticleWriter awriter = new ArticleWriter(sub.getHost(), sub.getPort());
87 awriter.writeArticle(article);
94 Log.get().warning(ex.toString());
98 catch(StorageBackendException ex)
100 Log.get().severe(ex.toString());
102 catch(InterruptedException ex)
104 Log.get().warning("PushFeeder interrupted: " + ex);
109 public void queueForPush(Article article)
111 this.articleQueue.add(article);