diff -r 000000000000 -r 1090e2141798 org/sonews/feed/FeedManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/sonews/feed/FeedManager.java Wed Jul 01 10:48:22 2009 +0200 @@ -0,0 +1,71 @@ +/* + * 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.sql.SQLException; +import java.util.List; +import org.sonews.daemon.storage.Article; +import org.sonews.daemon.storage.Database; + +/** + * Controlls push and pull feeder. + * @author Christian Lins + * @since sonews/0.5.0 + */ +public final class FeedManager +{ + + public static final int TYPE_PULL = 0; + public static final int TYPE_PUSH = 1; + + private static PullFeeder pullFeeder = new PullFeeder(); + private static PushFeeder pushFeeder = new PushFeeder(); + + /** + * Reads the peer subscriptions from database and starts the appropriate + * PullFeeder or PushFeeder. + */ + public static synchronized void startFeeding() + throws SQLException + { + List subsPull = Database.getInstance() + .getSubscriptions(TYPE_PULL); + for(Subscription sub : subsPull) + { + pullFeeder.addSubscription(sub); + } + pullFeeder.start(); + + List subsPush = Database.getInstance() + .getSubscriptions(TYPE_PUSH); + for(Subscription sub : subsPush) + { + pushFeeder.addSubscription(sub); + } + pushFeeder.start(); + } + + public static void queueForPush(Article article) + { + pushFeeder.queueForPush(article); + } + + private FeedManager() {} + +}