*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class CoreImpl implements Core, NodeListener, RequestListener, InsertListener {
+public class CoreImpl implements Core, NodeListener {
/** The logger. */
private static final Logger logger = Logging.getLogger(CoreImpl.class.getName());
/** The node manager. */
private NodeManager nodeManager;
- /** The request manager. */
- /* TODO - remove */
- @SuppressWarnings("unused")
- private RequestManager requestManager;
-
- /** The insert manager. */
- private InsertManager insertManager;
-
//
// LISTENER MANAGEMENT
//
}
/**
- * Sets the request manager to use.
- *
- * @param requestManager
- * The request manager to use
- */
- public void setRequestManager(RequestManager requestManager) {
- this.requestManager = requestManager;
- }
-
- /**
- * Sets the insert manager to use.
- *
- * @param insertManager
- * The insert manager to use
- */
- public void setInsertManager(InsertManager insertManager) {
- this.insertManager = insertManager;
- }
-
- /**
* {@inheritDoc}
*/
public List<Node> getNodes() {
*/
public void insertProject(Node node, Project project) {
logger.log(Level.FINEST, "insertProject(node=" + node + ", project=" + project + ")");
- insertManager.insertProject(project, node);
}
/**
coreListenerSupport.fireNodeDisconnected(node, throwable);
}
- //
- // INTERFACE RequestListener
- //
-
- /**
- * {@inheritDoc}
- */
- public void requestAdded(Request request) {
- /* TODO - find project and process request */
- }
-
- /**
- * @see net.pterodactylus.jsite.core.RequestListener#requestProgressed(Request)
- */
- public void requestProgressed(Request request) {
- /* TODO - find project and process request */
- }
-
- /**
- * @see net.pterodactylus.jsite.core.RequestListener#requestRemoved(net.pterodactylus.jsite.core.Request)
- */
- public void requestRemoved(Request request) {
- /* TODO - find project and process request */
- }
-
- /**
- * @see net.pterodactylus.jsite.core.RequestListener#requestGeneratedURI(net.pterodactylus.jsite.core.Request,
- * java.lang.String)
- */
- public void requestGeneratedURI(Request request, String uri) {
- /* TODO - find project and process request */
- }
-
- /**
- * @see net.pterodactylus.jsite.core.RequestListener#requestFinished(net.pterodactylus.jsite.core.Request)
- */
- public void requestFinished(Request request) {
- /* TODO - find project and process request */
- }
-
- //
- // INTERFACE InsertListener
- //
-
- /**
- * {@inheritDoc}
- */
- public void insertAdded(Insert insert) {
- /* TODO */
- }
-
- /**
- * {@inheritDoc}
- */
- public void insertRemoved(Insert insert) {
- /* TODO */
- }
-
- /**
- * {@inheritDoc}
- */
- public void insertStarted(Insert insert) {
- /* TODO */
- }
-
- /**
- * {@inheritDoc}
- */
- public void insertProgressed(Insert insert) {
- /* TODO */
- }
-
- /**
- * {@inheritDoc}
- */
- public void insertGeneratedURI(Insert insert, String uri) {
- /* TODO */
- }
-
- /**
- * {@inheritDoc}
- */
- public void insertFinished(Insert insert) {
- /* TODO */
- }
-
}
+++ /dev/null
-/*
- * jSite2 - Insert.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;
-
-/**
- * Represents a currently running or past insert.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class Insert extends Request {
-
- /** The project that was inserted. */
- private final Project project;
-
- /** The start time of the insert. */
- private final long startTime;
-
- /** The end time of the insert. */
- private long endTime;
-
- /**
- * Creates a new insert that starts now.
- *
- * @param project
- * The project that is inserted
- * @param node
- * The node the project is inserted to
- * @param identifier
- * The identifier of the insert request
- */
- public Insert(Project project, Node node, String identifier) {
- this(project, node, identifier, System.currentTimeMillis());
- }
-
- /**
- * Creates a new insert.
- *
- * @param project
- * The project that is inserted
- * @param node
- * The node the project is inserted to
- * @param identifier
- * The identifier of the insert request
- * @param startTime
- * The time the insert was started
- */
- public Insert(Project project, Node node, String identifier, long startTime) {
- super(node, identifier);
- this.project = project;
- this.startTime = startTime;
- }
-
- /**
- * Returns the project that is inserted.
- *
- * @return The inserted project
- */
- public Project getProject() {
- return project;
- }
-
- /**
- * Returns the start time of the insert.
- *
- * @return The start time of the insert
- */
- public long getStartTime() {
- return startTime;
- }
-
- /**
- * Returns the end time of the insert. If the insert has not yet finished,
- * <code>-1</code> is returned.
- *
- * @return The end time of the insert, or <code>-1</code> if the insert is
- * still running
- */
- public long getEndTime() {
- return endTime;
- }
-
- /**
- * Sets the end time of the insert.
- *
- * @param endTime
- * The end time of the insert
- */
- public void setEndTime(long endTime) {
- this.endTime = endTime;
- }
-
-}
+++ /dev/null
-/*
- * jSite2 - InsertListener.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.EventListener;
-
-/**
- * Interface for objects that want to be notified on events emitted by the
- * {@link InsertManager}.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public interface InsertListener extends EventListener {
-
- /**
- * Notifies a listener that an insert was added.
- *
- * @param insert
- * The insert that was added
- */
- public void insertAdded(Insert insert);
-
- /**
- * Notifies a listener that an insert was removed.
- *
- * @param insert
- * The insert that was removed
- */
- public void insertRemoved(Insert insert);
-
- /**
- * Notifies a listener that an insert was started.
- *
- * @param insert
- * The insert that was started
- */
- public void insertStarted(Insert insert);
-
- /**
- * Notifies a listener that an insert made some progress.
- *
- * @param insert
- * The insert that made some progress
- */
- public void insertProgressed(Insert insert);
-
- /**
- * Notifies listeners that an insert generated a URI.
- *
- * @param insert
- * The insert that generated a URI
- * @param uri
- * The generated URI
- */
- public void insertGeneratedURI(Insert insert, String uri);
-
- /**
- * Notifies a listener that an insert has finished.
- *
- * @param insert
- * The insert that has finished
- */
- public void insertFinished(Insert insert);
-
-}
+++ /dev/null
-/*
- * jSite-next - InsertListenerSupport.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 net.pterodactylus.util.event.ListenerManager;
-
-/**
- * Helper class that fires {@link InsertListener} events.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class InsertListenerSupport extends ListenerManager<InsertListener> {
-
- /**
- * Notifies all listeners that the insert was added.
- *
- * @see InsertListener#insertAdded(Insert)
- * @param insert
- * The insert that was added
- */
- public void fireInsertAdded(Insert insert) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertAdded(insert);
- }
- }
-
- /**
- * Notifies all listeners that the insert was removed.
- *
- * @see InsertListener#insertRemoved(Insert)
- * @param insert
- * The insert that was removed
- */
- public void fireInsertRemoved(Insert insert) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertRemoved(insert);
- }
- }
-
- /**
- * Notifies all listeners that the insert was started.
- *
- * @see InsertListener#insertStarted(Insert)
- * @param insert
- * The insert that was started
- */
- public void fireInsertStarted(Insert insert) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertStarted(insert);
- }
- }
-
- /**
- * Notifies all listeners that the insert made progress.
- *
- * @see InsertListener#insertProgressed(Insert)
- * @param insert
- * The insert that made progress
- */
- public void fireInsertProgressed(Insert insert) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertProgressed(insert);
- }
- }
-
- /**
- * Notifies all listeners that the insert generated a URI.
- *
- * @see InsertListener#insertGeneratedURI(Insert, String)
- * @param insert
- * The insert that generated a URI
- * @param generatedUri
- * The URI that was generated
- */
- public void fireInsertGeneratedURI(Insert insert, String generatedUri) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertGeneratedURI(insert, generatedUri);
- }
- }
-
- /**
- * Notifies all listeners that the insert has finished.
- *
- * @see InsertListener#insertFinished(Insert)
- * @param insert
- * The insert that was finished
- */
- public void fireInsertFinished(Insert insert) {
- for (InsertListener insertListener : getListeners()) {
- insertListener.insertFinished(insert);
- }
- }
-
-}
+++ /dev/null
-/*
- * 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.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import net.pterodactylus.util.logging.Logging;
-
-/**
- * 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 listener support. */
- private final InsertListenerSupport insertListenerSupport = new InsertListenerSupport();
-
- /** Mapping from insert IDs to inserts. */
- private final Map<String, Insert> inserts = new HashMap<String, Insert>();
-
- //
- // 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 + ")");
- insertListenerSupport.addListener(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 + ")");
- insertListenerSupport.removeListener(insertListener);
- }
-
- //
- // ACTIONS
- //
-
- /**
- * Starts to insert the given project.
- *
- * @param project
- * The project to insert
- * @param node
- * The node to insert the project to if the project does not
- * specify a node
- */
- public void insertProject(Project project, Node node) {
- logger.log(Level.FINEST, "insertProject(project=" + project + ",node=" + node + ")");
- String insertId = "insert-" + project.getId();
- Insert newInsert = new Insert(project, node, insertId);
- inserts.put(insertId, newInsert);
- saveConfiguration();
- insertListenerSupport.fireInsertAdded(newInsert);
- /* TODO - start insert */
- }
-
- /**
- * 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()");
- }
-
- /**
- * Saves the configuration.
- */
- private void saveConfiguration() {
- logger.log(Level.FINEST, "saveConfiguration()");
- }
-
-}
+++ /dev/null
-/*
- * jSite2 - Request.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 net.pterodactylus.util.beans.AbstractBean;
-
-/**
- * A request is an ongoing download or upload reported by the freenet node.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class Request extends AbstractBean {
-
- /**
- * The type of a request.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public enum Type {
-
- /** Type of request is unknown. */
- unknown,
-
- /** The request is a Get request. */
- get,
-
- /** The request is a Put request. */
- put,
-
- /** The request is a PutDir request. */
- putDir
-
- }
-
- /** Name of the “type” property. */
- public static final String PROPERTY_TYPE = "type";
-
- /** Name of the “client token” property. */
- public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
-
- /** Name of the “finished” property. */
- public static final String PROPERTY_FINISHED = "finished";
-
- /** Name of the “successful” property. */
- public static final String PROPERTY_SUCCESSFUL = "successful";
-
- /** Name of the “fetchable” property. */
- public static final String PROPERTY_FETCHABLE = "fetchable";
-
- /** Name of the “URI” property. */
- public static final String PROPERTY_URI = "uri";
-
- /** Name of the “total blocks” property. */
- public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
-
- /** Name of the “required blocks” property. */
- public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
-
- /** Name of the “successful blocks” property. */
- public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
-
- /** Name of the “failed blocks” property. */
- public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
-
- /** Name of the “fatally failed blocks” property. */
- public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
-
- /** Name of the “total finalized” property. */
- public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
-
- /** The node the request belongs to. */
- private final Node node;
-
- /** The identifier of the request. */
- private final String identifier;
-
- /** The type of the request. */
- private Type type;
-
- /** The client token of the request. */
- private String clientToken;
-
- /** Whether the request is finished. */
- private boolean finished;
-
- /** Whether the request was finished successfully. */
- private boolean successful;
-
- /** Whether the data is already fetchable (in case of put requests). */
- private boolean fetchable;
-
- /** The generated URI. */
- private String uri;
-
- /** The total number of blocks. */
- private int totalBlocks;
-
- /** The required number of blocks. */
- private int requiredBlocks;
-
- /** The number of successful blocks. */
- private int successfulBlocks;
-
- /** The number of failedBlocks. */
- private int failedBlocks;
-
- /** The number of fatally failed blocks. */
- private int fatallyFailedBlocks;
-
- /** Whether the total number has been finalized. */
- private boolean totalFinalized;
-
- /**
- * Creates a new request with the given identifier.
- *
- * @param node
- * The node the request belongs to
- * @param identifier
- * The identifier of the request
- */
- Request(Node node, String identifier) {
- this.node = node;
- this.identifier = identifier;
- }
-
- //
- // EVENT MANAGEMENT
- //
-
- /**
- * Returns the node the request belongs to.
- *
- * @return The node the request belongs to
- */
- public Node getNode() {
- return node;
- }
-
- /**
- * Returns the identifier of the request. It is unique per node.
- *
- * @return The identifier of the request
- */
- public String getIdentifier() {
- return identifier;
- }
-
- /**
- * Returns the type of the request.
- *
- * @return The type of the request
- */
-
- public Type getType() {
- return type;
- }
-
- /**
- * Sets the type of the request.
- *
- * @param type
- * The type of the request
- */
- void setType(Type type) {
- Type oldType = this.type;
- this.type = type;
- fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
- }
-
- /**
- * Returns the client token of the request.
- *
- * @return The client token of the request
- */
- public String getClientToken() {
- return clientToken;
- }
-
- /**
- * Sets the client token of the request.
- *
- * @param clientToken
- * The client token of the request
- */
- void setClientToken(String clientToken) {
- String oldClientToken = this.clientToken;
- this.clientToken = clientToken;
- fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
- }
-
- /**
- * Returns whether the request has finished.
- *
- * @see #isSuccessful()
- * @return <code>true</code> if the request is finished,
- * <code>false</code> otherwise
- */
- public boolean isFinished() {
- return finished;
- }
-
- /**
- * Sets whether the request has finished.
- *
- * @param finished
- * <code>true</code> if the request has finished,
- * <code>false</code> otherwise
- */
- void setFinished(boolean finished) {
- boolean oldFinished = this.finished;
- this.finished = finished;
- firePropertyChange(PROPERTY_FINISHED, oldFinished, finished);
- }
-
- /**
- * Returns whether the request finished successfully. This value will only
- * have meaning if {@link #isFinished()} returns <code>true</code>.
- *
- * @return <code>true</code> if the request finished successfully,
- * <code>false</code> otherwise
- */
- public boolean isSuccessful() {
- return successful;
- }
-
- /**
- * Sets whether this request finished successfully.
- *
- * @param successful
- * <code>true</code> if the request finished successfully,
- * <code>false</code> otherwise
- */
- void setSuccessful(boolean successful) {
- boolean oldSuccessful = this.successful;
- this.successful = successful;
- firePropertyChange(PROPERTY_SUCCESSFUL, oldSuccessful, successful);
- }
-
- /**
- * Returns whether the data inserted by this {@link Type#put} or
- * {@link Type#putDir} request is already fetchable by other clients.
- *
- * @return <code>true</code> if the data is already fetchable,
- * <code>false</code> otherwise
- */
- public boolean isFetchable() {
- return fetchable;
- }
-
- /**
- * Sets whether the data inserted by this {@link Type#put} or
- * {@link Type#putDir} request is already fetchable by other clients.
- *
- * @param fetchable
- * <code>true</code> if the data is already fetchable,
- * <code>false</code> otherwise
- */
- void setFetchable(boolean fetchable) {
- boolean oldFetchable = this.fetchable;
- this.fetchable = fetchable;
- firePropertyChange(PROPERTY_FETCHABLE, oldFetchable, fetchable);
- }
-
- /**
- * Returns the URI generated by this request.
- *
- * @return The generated URI
- */
- public String getURI() {
- return uri;
- }
-
- /**
- * Sets the URI generated by this request.
- *
- * @param uri
- * The generated URI
- */
- void setURI(String uri) {
- this.uri = uri;
- }
-
- /**
- * Returns the total number of blocks of a request. Until
- * {@link #isTotalFinalized()} returns <code>true</code> this value may
- * change!
- *
- * @return The total number of blocks of a request
- */
- public int getTotalBlocks() {
- return totalBlocks;
- }
-
- /**
- * Sets the total number of blocks of a request.
- *
- * @param totalBlocks
- * The total number of blocks
- */
- void setTotalBlocks(int totalBlocks) {
- int oldTotalBlocks = this.totalBlocks;
- this.totalBlocks = totalBlocks;
- fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
- }
-
- /**
- * @return the requiredBlocks
- */
- public int getRequiredBlocks() {
- return requiredBlocks;
- }
-
- /**
- * @param requiredBlocks
- * the requiredBlocks to set
- */
- void setRequiredBlocks(int requiredBlocks) {
- int oldRequiredBlocks = this.requiredBlocks;
- this.requiredBlocks = requiredBlocks;
- fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
- }
-
- /**
- * @return the successfulBlocks
- */
- public int getSuccessfulBlocks() {
- return successfulBlocks;
- }
-
- /**
- * @param successfulBlocks
- * the successfulBlocks to set
- */
- void setSuccessfulBlocks(int successfulBlocks) {
- int oldSuccessfulBlocks = this.successfulBlocks;
- this.successfulBlocks = successfulBlocks;
- fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
- }
-
- /**
- * @return the failedBlocks
- */
- public int getFailedBlocks() {
- return failedBlocks;
- }
-
- /**
- * @param failedBlocks
- * the failedBlocks to set
- */
- void setFailedBlocks(int failedBlocks) {
- int oldFailedBlocks = this.failedBlocks;
- this.failedBlocks = failedBlocks;
- fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
- }
-
- /**
- * @return the fatallyFailedBlocks
- */
- public int getFatallyFailedBlocks() {
- return fatallyFailedBlocks;
- }
-
- /**
- * @param fatallyFailedBlocks
- * the fatallyFailedBlocks to set
- */
- void setFatallyFailedBlocks(int fatallyFailedBlocks) {
- int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
- this.fatallyFailedBlocks = fatallyFailedBlocks;
- fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
- }
-
- /**
- * @return the totalFinalized
- */
- public boolean isTotalFinalized() {
- return totalFinalized;
- }
-
- /**
- * @param totalFinalized
- * the totalFinalized to set
- */
- void setTotalFinalized(boolean totalFinalized) {
- boolean oldTotalFinalized = this.totalFinalized;
- this.totalFinalized = totalFinalized;
- fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);
- }
-
-}
+++ /dev/null
-/*
- * jSite2 - RequestListener.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.EventListener;
-
-/**
- * Interface for objects that want to be notified on request events.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public interface RequestListener extends EventListener {
-
- /**
- * Notifies a listener that a request was added to a node.
- *
- * @param request
- * The request that was added
- */
- public void requestAdded(Request request);
-
- /**
- * Notifies a listener that a request made progress.
- *
- * @param request
- * The request
- */
- public void requestProgressed(Request request);
-
- /**
- * Notifies a listener that a request was removed.
- *
- * @param request
- * The request that was removed
- */
- public void requestRemoved(Request request);
-
- /**
- * Notifies a listener that a Put request has generated a URI.
- *
- * @param request
- * The request that generated a URI
- * @param uri
- * The generated URI
- */
- public void requestGeneratedURI(Request request, String uri);
-
- /**
- * Notifies a listener that a request has completed.
- *
- * @param request
- * The finished request
- */
- public void requestFinished(Request request);
-
-}
+++ /dev/null
-/*
- * jSite-next - RequestListenerManager.java -
- * Copyright © 2009 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 net.pterodactylus.util.event.ListenerManager;
-
-/**
- * Manager for {@link RequestListener} event listeners.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class RequestListenerManager extends ListenerManager<RequestListener> {
-
- /**
- * Notifies all listeners that a request was added.
- *
- * @see RequestListener#requestAdded(Request)
- * @param request
- * The added request
- */
- public void fireRequestAdded(Request request) {
- for (RequestListener requestListener : getListeners()) {
- requestListener.requestAdded(request);
- }
- }
-
- /**
- * Notifies all listeners that a request has made progress.
- *
- * @see RequestListener#requestProgressed(Request)
- * @param request
- * The request that made progress
- */
- public void fireRequestProgressed(Request request) {
- for (RequestListener requestListener : getListeners()) {
- requestListener.requestProgressed(request);
- }
- }
-
- /**
- * Notifies all listeners that a request was removed.
- *
- * @see RequestListener#requestRemoved(Request)
- * @param request
- * The removed request
- */
- public void fireRequestRemoved(Request request) {
- for (RequestListener requestListener : getListeners()) {
- requestListener.requestRemoved(request);
- }
- }
-
- /**
- * Notifies all listeners that a request generated a URI.
- *
- * @see RequestListener#requestGeneratedURI(Request, String)
- * @param request
- * The request that generated the URI
- * @param uri
- * The generated URI
- */
- public void fireRequestGeneratedURI(Request request, String uri) {
- for (RequestListener requestListener : getListeners()) {
- requestListener.requestGeneratedURI(request, uri);
- }
- }
-
- /**
- * Notifies all listeners that a request finished.
- *
- * @see RequestListener#requestFinished(Request)
- * @param request
- * The finished request
- */
- public void fireRequestFinished(Request request) {
- for (RequestListener requestListener : getListeners()) {
- requestListener.requestFinished(request);
- }
- }
-
-}
+++ /dev/null
-/*
- * jSite2 - RequestManager.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.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import net.pterodactylus.util.logging.Logging;
-
-/**
- * The request manager keeps track of all the request on all connected nodes.
- * The request manager is added to the {@link NodeManager} as a
- * {@link NodeListener} so that it can fire request-removed events in case a
- * node is disconnected.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class RequestManager implements NodeListener {
-
- /** Logger. */
- private static final Logger logger = Logging.getLogger(RequestManager.class.getName());
-
- /** Request listeners. */
- private List<RequestListener> requestListeners = Collections.synchronizedList(new ArrayList<RequestListener>());
-
- /** The node manager. */
- private NodeManager nodeManager;
-
- /** Request lists for all nodes. */
- private Map<Node, Map<String, Request>> nodeRequests = Collections.synchronizedMap(new HashMap<Node, Map<String, Request>>());
-
- //
- // EVENT MANAGEMENT
- //
-
- /**
- * Adds a request listener.
- *
- * @param requestListener
- * The request listener to add
- */
- public void addRequestListener(RequestListener requestListener) {
- requestListeners.add(requestListener);
- }
-
- /**
- * Removes a request listener.
- *
- * @param requestListener
- * The request listener to remove
- */
- public void removeRequestListener(RequestListener requestListener) {
- requestListeners.remove(requestListener);
- }
-
- /**
- * Notifies all listeners that a request was added.
- *
- * @param request
- * The request that was added
- */
- private void fireRequestAdded(Request request) {
- for (RequestListener requestListener : requestListeners) {
- requestListener.requestAdded(request);
- }
- }
-
- /**
- * Notifies all listeners that a request progressed.
- *
- * @param request
- * The request
- */
- private void fireRequestProgressed(Request request) {
- for (RequestListener requestListener : requestListeners) {
- requestListener.requestProgressed(request);
- }
- }
-
- /**
- * Notifies all listeners that a request was removed.
- *
- * @param request
- * The request that was removed
- */
- private void fireRequestRemoved(Request request) {
- for (RequestListener requestListener : requestListeners) {
- requestListener.requestRemoved(request);
- }
- }
-
- /**
- * Notifies all listeners that a request has finished.
- *
- * @see RequestListener#requestFinished(Request)
- * @param request
- * The request that has finished
- */
- private void fireRequestFinished(Request request) {
- for (RequestListener requestListener : requestListeners) {
- requestListener.requestFinished(request);
- }
- }
-
- /**
- * Notifies all listeners that a request has generated a URI.
- *
- * @see RequestListener#requestGeneratedURI(Request, String)
- * @param request
- * The request that has generated a URI
- * @param uri
- * The generated URI
- */
- private void fireRequestGeneratedURI(Request request, String uri) {
- for (RequestListener requestListener : requestListeners) {
- requestListener.requestGeneratedURI(request, uri);
- }
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Sets the node manager to use.
- *
- * @param nodeManager
- * The node manager
- */
- public void setNodeManager(NodeManager nodeManager) {
- this.nodeManager = nodeManager;
- }
-
- //
- // ACTIONS
- //
-
- //
- // PRIVATE ACTIONS
- //
-
- /**
- * Requests a list of all running requests from a node. This method will
- * block until the request has been sent!
- *
- * @param node
- * The node to get all requests for
- * @throws IOException
- * if an I/O error occurs while communicating with the node
- * @throws JSiteException
- * if there is a problem with the node
- */
- private void getRequests(final Node node) throws IOException, JSiteException {
- }
-
- //
- // INTERFACE NodeListener
- //
-
- /**
- * {@inheritDoc}
- */
- public void nodeAdded(Node node) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void nodeRemoved(Node node) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void nodeConnected(Node node) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void nodeConnectionFailed(Node node, Throwable cause) {
- /* we don't care about this. */
- }
-
- /**
- * {@inheritDoc}
- */
- public void nodeDisconnected(Node node, Throwable throwable) {
- Map<String, Request> identifierRequests = nodeRequests.get(node);
- if (identifierRequests == null) {
- logger.warning("got node without request map: " + node);
- return;
- }
- for (Request request : identifierRequests.values()) {
- fireRequestRemoved(request);
- }
- identifierRequests.clear();
- }
-
-}