2 * jSite2 - InsertManager.java - Copyright © 2008 David Roden
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307, USA.
18 package net.pterodactylus.jsite.core;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
26 import net.pterodactylus.util.logging.Logging;
29 * Manages all currently running and past inserts.
31 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33 public class InsertManager {
36 private static final Logger logger = Logging.getLogger(InsertManager.class.getName());
38 /** The insert listeners. */
39 private final List<InsertListener> insertListeners = new ArrayList<InsertListener>();
46 * Adds an insert listener to the list of insert listeners.
48 * @param insertListener
49 * The insert listener to add
51 public void addInsertListener(InsertListener insertListener) {
52 logger.log(Level.FINEST, "addInsertListener(insertListener=" + insertListener + ")");
53 synchronized (insertListeners) {
54 insertListeners.add(insertListener);
59 * Removes an insert listener from the list of insert listeners.
61 * @param insertListener
62 * The insert listener to remove
64 public void removeInsertListener(InsertListener insertListener) {
65 logger.log(Level.FINEST, "removeInsertListener(insertListener=" + insertListener + ")");
66 synchronized (insertListeners) {
67 insertListeners.remove(insertListener);
72 * Notifies all listeners that an insert was added.
75 * The insert that was added
77 private void fireInsertAdded(Insert insert) {
78 synchronized (insertListeners) {
79 for (InsertListener insertListener : insertListeners) {
80 insertListener.insertAdded(insert);
86 * Notifies all listeners that an insert was removed.
89 * The insert that was removes
91 private void fireInsertRemoved(Insert insert) {
92 synchronized (insertListeners) {
93 for (InsertListener insertListener : insertListeners) {
94 insertListener.insertRemoved(insert);
100 * Notifies all listeners that an insert was started.
103 * The insert that was started
105 private void fireInsertStarted(Insert insert) {
106 synchronized (insertListeners) {
107 for (InsertListener insertListener : insertListeners) {
108 insertListener.insertStarted(insert);
114 * Notifies all listeners that an insert made some progress
117 * The insert that made some progress
119 private void fireInsertProgressed(Insert insert) {
120 synchronized (insertListeners) {
121 for (InsertListener insertListener : insertListeners) {
122 insertListener.insertProgressed(insert);
128 * Notifies all listeners that an insert generated a URI.
131 * The insert that generated a URI
133 private void fireInsertGeneratedURI(Insert insert, String uri) {
134 synchronized (insertListeners) {
135 for (InsertListener insertListener : insertListeners) {
136 insertListener.insertGeneratedURI(insert, uri);
142 * Notifies all listeners that an insert has finished.
145 * The insert that has finished
147 private void fireInsertFinished(Insert insert) {
148 synchronized (insertListeners) {
149 for (InsertListener insertListener : insertListeners) {
150 insertListener.insertFinished(insert);
160 * Starts the insert manager.
162 public void start() {
163 logger.log(Level.FINEST, "start()");
172 * Loads the configuration.
174 private void loadConfiguration() {
175 logger.log(Level.FINEST, "loadConfiguration()");