From: David ‘Bombe’ Roden Date: Fri, 11 Apr 2008 09:21:44 +0000 (+0000) Subject: add PersistentGet X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4cfdf9fa51d5b910ac92983b348934de61044c70;p=jSite2.git add PersistentGet git-svn-id: http://trooper/svn/projects/jSite/trunk@711 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/TODO b/TODO index 9eb078c..2bcf015 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,6 @@ GetRequestStatus IdentifierCollision ModifyConfig (since 1027) ModifyPersistentRequest -PersistentGet PersistentPutDir PersistentRequestModified (since 1016) PersistentRequestRemoved (since 1016) diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index d520fde..fd4fb76 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -104,6 +104,14 @@ public class FcpAdapter implements FcpListener { } /** + * @see net.pterodactylus.util.fcp.FcpListener#receivedPersistentGet(net.pterodactylus.util.fcp.FcpConnection, + * net.pterodactylus.util.fcp.PersistentGet) + */ + public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet) { + /* empty. */ + } + + /** * @see net.pterodactylus.util.fcp.FcpListener#receivedPersistentPut(net.pterodactylus.util.fcp.FcpConnection, * net.pterodactylus.util.fcp.PersistentPut) */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index d8c9698..fd6add0 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -292,6 +292,18 @@ public class FcpConnection { } /** + * Notifies all listeners that a “PersistentGet” message was received. + * + * @param persistentGet + * The “PersistentGet” message + */ + private void fireReceivedPersistentGet(PersistentGet persistentGet) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedPersistentGet(this, persistentGet); + } + } + + /** * Notifies all listeners that a “PersistentPut” message was received. * * @see FcpListener#receivedPersistentPut(FcpConnection, PersistentPut) @@ -480,6 +492,8 @@ public class FcpConnection { fireReceivedSimpleProgress(new SimpleProgress(fcpMessage)); } else if ("ProtocolError".equals(messageName)) { fireReceivedProtocolError(new ProtocolError(fcpMessage)); + } else if ("PersistentGet".equals(messageName)) { + fireReceivedPersistentGet(new PersistentGet(fcpMessage)); } else if ("PersistentPut".equals(messageName)) { fireReceivedPersistentPut(new PersistentPut(fcpMessage)); } else if ("URIGenerated".equals(messageName)) { diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index c32eb90..a9c3809 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -141,6 +141,16 @@ public interface FcpListener extends EventListener { public void receivedTestDDAComplete(FcpConnection fcpConnection, TestDDAComplete testDDAComplete); /** + * Notifies a listener that a “PersistentGet” was received. + * + * @param fcpConnection + * The connection that received the message + * @param persistentGet + * The “PersistentGet” message + */ + public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet); + + /** * Notifies a listener that a “PersistentPut” was received. * * @param fcpConnection diff --git a/src/net/pterodactylus/util/fcp/PersistentGet.java b/src/net/pterodactylus/util/fcp/PersistentGet.java new file mode 100644 index 0000000..a131c09 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/PersistentGet.java @@ -0,0 +1,155 @@ +/* + * ${project_name} - ${file_name} - + * Copyright \u00A9 ${year} 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.util.fcp; + +/** + * The “PersistentGet” message is sent to the client to inform it about a + * persistent download, either in the client-local queue or in the global queue. + * + * @author David Roden + * @version $Id$ + */ +public class PersistentGet extends BaseMessage { + + /** + * Creates a new “PersistentGet” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + PersistentGet(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the identifier of the request. + * + * @return The identifier of the request + */ + public String getIdentifier() { + return getField("Identifier"); + } + + /** + * Returns the URI of the request. + * + * @return The URI of the request + */ + public String getURI() { + return getField("URI"); + } + + /** + * Returns the verbosity of the request. + * + * @return The verbosity of the request + */ + public Verbosity getVerbosity() { + return Verbosity.valueOf(getField("Verbosity")); + } + + /** + * Returns the return type of the request. + * + * @return The return type of the request + */ + public ReturnType getReturnType() { + try { + return ReturnType.valueOf(getField("ReturnType")); + } catch (IllegalArgumentException iae1) { + return ReturnType.unknown; + } + } + + /** + * Returns the name of the file the data is downloaded to. This field will + * only be set if {@link #getReturnType()} is {@link ReturnType#disk}. + * + * @return The name of the file the data is downloaded to + */ + public String getFilename() { + return getField("Filename"); + } + + /** + * Returns the name of the temporary file. This field will only be set if + * {@link #getReturnType()} is {@link ReturnType#disk}. + * + * @return The name of the temporary file + */ + public String getTempFilename() { + return getField("TempFilename"); + } + + /** + * Returns the client token of the request. + * + * @return The client token of the request + */ + public String getClientToken() { + return getField("ClientToken"); + } + + /** + * Returns the priority of the request. + * + * @return The priority of the request + */ + public Priority getPriority() { + return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), 7)]; + } + + /** + * Returns the persistence of the request. + * + * @return The persistence of the request, or {@link Persistence#unknown} if + * the persistence could not be parsed + */ + public Persistence getPersistence() { + try { + return Persistence.valueOf(getField("Persistence")); + } catch (IllegalArgumentException iae1) { + return Persistence.unknown; + } + } + + /** + * Returns whether this request is on the global queue or on the + * client-local queue. + * + * @return true if the request is on the global queue, + * false if the request is on the client-local queue + */ + public boolean isGlobal() { + return Boolean.valueOf(getField("Global")); + } + + /** + * Returns the maximum number of retries for a failed block. + * + * @return The maximum number of retries for a failed block, -1 + * for endless retries, -2 if the number could not be + * parsed + */ + public int getMaxRetries() { + return FcpUtils.safeParseInt(getField("MaxRetries"), -2); + } + +}