From 51a5b3dbcfa9ffd520195e112e818ca88b8538ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 13 Jun 2008 18:00:34 +0200 Subject: [PATCH] first skeleton --- .../pterodactylus/jsite/core/InsertManager.java | 184 +++++++++++++++++++-- 1 file changed, 167 insertions(+), 17 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/InsertManager.java b/src/net/pterodactylus/jsite/core/InsertManager.java index 8e1083a..be8cc5e 100644 --- a/src/net/pterodactylus/jsite/core/InsertManager.java +++ b/src/net/pterodactylus/jsite/core/InsertManager.java @@ -1,28 +1,178 @@ /* - * jSite2 - InsertManager.java - - * Copyright © 2008 David Roden - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * jSite2 - InsertManager.java - Copyright © 2008 David Roden + * + * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. */ package net.pterodactylus.jsite.core; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** - * TODO + * Manages all currently running and past inserts. + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class InsertManager { + /** Logger. */ + private static final Logger logger = Logging.getLogger(InsertManager.class.getName()); + + /** The insert listeners. */ + private final List insertListeners = new ArrayList(); + + // + // EVENT MANAGEMENT + // + + /** + * Adds an insert listener to the list of insert listeners. + * + * @param insertListener + * The insert listener to add + */ + public void addInsertListener(InsertListener insertListener) { + logger.log(Level.FINEST, "addInsertListener(insertListener=" + insertListener + ")"); + synchronized (insertListeners) { + insertListeners.add(insertListener); + } + } + + /** + * Removes an insert listener from the list of insert listeners. + * + * @param insertListener + * The insert listener to remove + */ + public void removeInsertListener(InsertListener insertListener) { + logger.log(Level.FINEST, "removeInsertListener(insertListener=" + insertListener + ")"); + synchronized (insertListeners) { + insertListeners.remove(insertListener); + } + } + + /** + * Notifies all listeners that an insert was added. + * + * @param insert + * The insert that was added + */ + private void fireInsertAdded(Insert insert) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertAdded(insert); + } + } + } + + /** + * Notifies all listeners that an insert was removed. + * + * @param insert + * The insert that was removes + */ + private void fireInsertRemoved(Insert insert) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertRemoved(insert); + } + } + } + + /** + * Notifies all listeners that an insert was started. + * + * @param insert + * The insert that was started + */ + private void fireInsertStarted(Insert insert) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertStarted(insert); + } + } + } + + /** + * Notifies all listeners that an insert made some progress + * + * @param insert + * The insert that made some progress + */ + private void fireInsertProgressed(Insert insert) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertProgressed(insert); + } + } + } + + /** + * Notifies all listeners that an insert generated a URI. + * + * @param insert + * The insert that generated a URI + */ + private void fireInsertGeneratedURI(Insert insert, String uri) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertGeneratedURI(insert, uri); + } + } + } + + /** + * Notifies all listeners that an insert has finished. + * + * @param insert + * The insert that has finished + */ + private void fireInsertFinished(Insert insert) { + synchronized (insertListeners) { + for (InsertListener insertListener : insertListeners) { + insertListener.insertFinished(insert); + } + } + } + + // + // ACTIONS + // + + /** + * Starts the insert manager. + */ + public void start() { + logger.log(Level.FINEST, "start()"); + loadConfiguration(); + } + + // + // PRIVATE METHODS + // + + /** + * Loads the configuration. + */ + private void loadConfiguration() { + logger.log(Level.FINEST, "loadConfiguration()"); + } + } -- 2.7.4