From: David ‘Bombe’ Roden Date: Fri, 23 May 2008 15:49:14 +0000 (+0000) Subject: remove request events from core listener X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d5afe3e2bde1f3a21cec6f3b3f1e57f7fdac3618;p=jSite2.git remove request events from core listener complete requests with more progress stuff git-svn-id: http://trooper/svn/projects/jSite/trunk@939 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index cf5a941..15f217d 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -268,42 +268,6 @@ public class CoreImpl implements Core, NodeListener, RequestListener { } } - /** - * Notifies all listeners that a request was added to a node. - * - * @param request - * The request that was added - */ - private void fireRequestAdded(Request request) { - for (CoreListener coreListener: coreListeners) { - coreListener.requestAdded(request); - } - } - - /** - * Notifies all listeners that a request progressed. - * - * @param request - * The request - */ - private void fireRequestProgressed(Request request) { - for (CoreListener coreListener: coreListeners) { - coreListener.requestProgressed(request); - } - } - - /** - * Notifies all listeners that a request was removed. - * - * @param request - * The request that was removed - */ - private void fireRequestRemoved(Request request) { - for (CoreListener coreListener: coreListeners) { - coreListener.requestRemoved(request); - } - } - // // ACCESSORS // @@ -522,21 +486,35 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void requestAdded(Request request) { - fireRequestAdded(request); + /* TODO - find project and process request */ } /** * @see net.pterodactylus.jsite.core.RequestListener#requestProgressed(Request) */ public void requestProgressed(Request request) { - fireRequestProgressed(request); + /* TODO - find project and process request */ } /** * @see net.pterodactylus.jsite.core.RequestListener#requestRemoved(net.pterodactylus.jsite.core.Request) */ public void requestRemoved(Request request) { - fireRequestRemoved(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 */ + } } diff --git a/src/net/pterodactylus/jsite/core/CoreListener.java b/src/net/pterodactylus/jsite/core/CoreListener.java index d5d8cdc..e2d4946 100644 --- a/src/net/pterodactylus/jsite/core/CoreListener.java +++ b/src/net/pterodactylus/jsite/core/CoreListener.java @@ -19,6 +19,8 @@ package net.pterodactylus.jsite.core; +import net.pterodactylus.jsite.project.Project; + /** * Interface definition for user interfaces. * @@ -184,31 +186,58 @@ public interface CoreListener { public void nodeDisconnected(Node node, Throwable throwable); // - // request stuff + // project insertion stuff // /** - * Notifies a listener that a request was added to a node. + * Notifies a listener that a project insert started. + * + * @param project + * The project that is now inserting + */ + public void projectInsertStarted(Project project); + + /** + * Notifies a listener that a project insert made progress. * - * @param request - * The request that was added + * @param project + * The project that made progress + * @param totalBlocks + * The number of total blocks + * @param requiredBlocks + * The number of required blocks + * @param successfulBlocks + * The number of successfully inserted blocks + * @param failedBlocks + * The number of blocks that could not be inserted + * @param fatallyFailedBlocks + * The number of blocks that can not be inserted even with + * retries + * @param finalizedTotal + * true if the number of total blocks is already + * finalized, false otherwise */ - public void requestAdded(Request request); + public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal); /** - * Notifies a listener that a request made some progress. + * Notifies a listener that a project insert has generated a URI. * - * @param request - * The request that made the progress + * @param project + * The project that generated a URI + * @param uri + * The URI that was generated */ - public void requestProgressed(Request request); + public void projectInsertGeneratedURI(Project project, String uri); /** - * Notifies a listener that a request was removed. + * Notifies a listener that a project insert has finished. * - * @param request - * The request that was removed + * @param project + * The project that has finished + * @param success + * true if the project was inserted successfully, + * false otherwise */ - public void requestRemoved(Request request); + public void projectInsertFinished(Project project, boolean success); } diff --git a/src/net/pterodactylus/jsite/core/Request.java b/src/net/pterodactylus/jsite/core/Request.java index 6f05e7b..702e135 100644 --- a/src/net/pterodactylus/jsite/core/Request.java +++ b/src/net/pterodactylus/jsite/core/Request.java @@ -66,6 +66,9 @@ public class Request extends AbstractBean { /** 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"; @@ -105,6 +108,9 @@ public class Request extends AbstractBean { /** 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; @@ -275,6 +281,25 @@ public class Request extends AbstractBean { } /** + * 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 true this value may * change! diff --git a/src/net/pterodactylus/jsite/core/RequestListener.java b/src/net/pterodactylus/jsite/core/RequestListener.java index 27ce517..b7ba758 100644 --- a/src/net/pterodactylus/jsite/core/RequestListener.java +++ b/src/net/pterodactylus/jsite/core/RequestListener.java @@ -53,4 +53,22 @@ public interface RequestListener extends EventListener { */ 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); + } diff --git a/src/net/pterodactylus/jsite/core/RequestManager.java b/src/net/pterodactylus/jsite/core/RequestManager.java index 4e23d79..8f73b8d 100644 --- a/src/net/pterodactylus/jsite/core/RequestManager.java +++ b/src/net/pterodactylus/jsite/core/RequestManager.java @@ -126,6 +126,34 @@ public class RequestManager implements NodeListener, HighLevelProgressListener { } } + /** + * 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 // @@ -308,13 +336,24 @@ public class RequestManager implements NodeListener, HighLevelProgressListener { identifierRequests.put(identifier, request); fireRequestAdded(request); } - request.setTotalBlocks(highLevelProgress.getTotalBlocks()); - request.setRequiredBlocks(highLevelProgress.getRequiredBlocks()); - request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks()); - request.setFailedBlocks(highLevelProgress.getFailedBlocks()); - request.setFatallyFailedBlocks(highLevelProgress.getFatallyFailedBlocks()); - request.setTotalFinalized(highLevelProgress.isTotalFinalized()); - fireRequestProgressed(request); + if (highLevelProgress.isFinished()) { + request.setFinished(true); + request.setSuccessful(!highLevelProgress.isFailed()); + fireRequestFinished(request); + } else if (highLevelProgress.isFetchable()) { + /* TODO - ignore? */ + } else if (highLevelProgress.getURI() != null) { + request.setURI(highLevelProgress.getURI()); + fireRequestGeneratedURI(request, highLevelProgress.getURI()); + } else { + request.setTotalBlocks(highLevelProgress.getTotalBlocks()); + request.setRequiredBlocks(highLevelProgress.getRequiredBlocks()); + request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks()); + request.setFailedBlocks(highLevelProgress.getFailedBlocks()); + request.setFatallyFailedBlocks(highLevelProgress.getFatallyFailedBlocks()); + request.setTotalFinalized(highLevelProgress.isTotalFinalized()); + fireRequestProgressed(request); + } } } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index b32694c..3c073be 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -48,7 +48,6 @@ import net.pterodactylus.jsite.core.Core; import net.pterodactylus.jsite.core.CoreListener; import net.pterodactylus.jsite.core.JSiteException; import net.pterodactylus.jsite.core.Node; -import net.pterodactylus.jsite.core.Request; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.gui.I18nAction; import net.pterodactylus.jsite.project.Project; @@ -978,25 +977,34 @@ public class SwingInterface implements CoreListener, LoggingListener { } /** - * {@inheritDoc} + * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.project.Project) */ - public void requestAdded(Request request) { - logger.log(Level.INFO, "request added to node: " + request + ", " + request.getNode()); - /* TODO - implement */ + public void projectInsertStarted(Project project) { + /* TODO - show in interface */ } /** - * {@inheritDoc} + * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.project.Project, + * int, int, int, int, int, boolean) + */ + public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal) { + /* TODO - show in interface */ + } + + /** + * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.project.Project, + * java.lang.String) */ - public void requestProgressed(Request request) { - /* TODO - implement */ + public void projectInsertGeneratedURI(Project project, String uri) { + /* TODO - show in interface */ } /** - * @see net.pterodactylus.jsite.core.CoreListener#requestRemoved(net.pterodactylus.jsite.core.Request) + * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.project.Project, + * boolean) */ - public void requestRemoved(Request request) { - /* TODO - implement */ + public void projectInsertFinished(Project project, boolean success) { + /* TODO - show in interface */ } //