From: David ‘Bombe’ Roden Date: Sat, 12 Apr 2008 13:33:12 +0000 (+0000) Subject: add PersistentPutDir X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b27920eb552020751ee19fb3eea3aa08a2ccae5e;p=jSite2.git add PersistentPutDir git-svn-id: http://trooper/svn/projects/jSite/trunk@725 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/TODO b/TODO index 8965128..7c5fc9e 100644 --- a/TODO +++ b/TODO @@ -6,7 +6,6 @@ GetPluginInfo (since 1075) GetRequestStatus ModifyConfig (since 1027) ModifyPersistentRequest -PersistentPutDir PersistentRequestModified (since 1016) PersistentRequestRemoved (since 1016) PluginInfo (since 1075) diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 59cfae5..e7afce4 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -200,6 +200,13 @@ public class FcpAdapter implements FcpListener { /** * {@inheritDoc} */ + public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir) { + /* empty. */ + } + + /** + * {@inheritDoc} + */ public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) { /* empty. */ } diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index e3ddf7c..fa3673d 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -488,6 +488,18 @@ public class FcpConnection { } /** + * Notifies all listeners that an “PersistentPutDir” message was received. + * + * @param persistentPutDir + * The “PersistentPutDir” message + */ + private void fireReceivedPersistentPutDir(PersistentPutDir persistentPutDir) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedPersistentPutDir(this, persistentPutDir); + } + } + + /** * Notifies all listeners that a “ProtocolError” message was received. * * @param protocolError @@ -582,6 +594,8 @@ public class FcpConnection { fireReceivedPersistentGet(new PersistentGet(fcpMessage)); } else if ("PersistentPut".equals(messageName)) { fireReceivedPersistentPut(new PersistentPut(fcpMessage)); + } else if ("PersistentPutDir".equals(messageName)) { + fireReceivedPersistentPutDir(new PersistentPutDir(fcpMessage)); } else if ("URIGenerated".equals(messageName)) { fireReceivedURIGenerated(new URIGenerated(fcpMessage)); } else if ("EndListPersistentRequests".equals(messageName)) { diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index e07bc6d..b4b1094 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -291,6 +291,16 @@ public interface FcpListener extends EventListener { public void receivedIdentifierCollision(FcpConnection fcpConnection, IdentifierCollision identifierCollision); /** + * Notifies a listener that a “PersistentPutDir” message was received. + * + * @param fcpConnection + * The connection that received the message + * @param persistentPutDir + * The “PersistentPutDir” message + */ + public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir); + + /** * Notifies a listener that a “ProtocolError” was received. * * @param fcpConnection diff --git a/src/net/pterodactylus/util/fcp/PersistentPutDir.java b/src/net/pterodactylus/util/fcp/PersistentPutDir.java new file mode 100644 index 0000000..412bd3d --- /dev/null +++ b/src/net/pterodactylus/util/fcp/PersistentPutDir.java @@ -0,0 +1,173 @@ +/* + * jSite2 - PersistentPutDir.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.util.fcp; + +/** + * A “PersistentPutDir” is the response to a {@link ClientPutDir} message. It is + * also sent as a possible response to a {@link ListPersistentRequests} message. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class PersistentPutDir extends BaseMessage { + + /** + * Creates a new “PersistentPutDir” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + PersistentPutDir(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 priority of the request. + * + * @return The priority of the request + */ + public Priority getPriority() { + return Priority.valueOf(getField("PriorityClass")); + } + + /** + * Returns whether the request is on the global queue. + * + * @return true if the request is on the global queue, + * false if it is on the client-local queue + */ + public boolean isGlobal() { + return Boolean.valueOf(getField("Global")); + } + + /** + * Returns the maximum number of retries for failed blocks. + * + * @return The maximum number of retries, or -1 for endless + * retries, or -2 if the number could not be parsed + */ + public int getMaxRetries() { + return FcpUtils.safeParseInt(getField("MaxRetries"), -2); + } + + /** + * Returns the number of files in the request. + * + * @return The number of files in the request + */ + public int getFileCount() { + int fileCount = -1; + while (getField("Files." + ++fileCount + ".UploadFrom") != null) { /* + * do + * nothing. + */ + } + return fileCount; + } + + /** + * Returns the name of the file at the given index. The index is counted + * from 0. + * + * @param fileIndex + * The index of the file + * @return The name of the file at the given index + */ + public String getFileName(int fileIndex) { + return getField("Files." + fileIndex + ".Name"); + } + + /** + * Returns the length of the file at the given index. The index is counted + * from 0. + * + * @param fileIndex + * The index of the file + * @return The length of the file at the given index + */ + public long getFileDataLength(int fileIndex) { + return FcpUtils.safeParseLong(getField("Files." + fileIndex + ".DataLength")); + } + + /** + * Returns the upload source of the file at the given index. The index is + * counted from 0. + * + * @param fileIndex + * The index of the file + * @return The upload source of the file at the given index + */ + public UploadFrom getFileUploadFrom(int fileIndex) { + return UploadFrom.valueOf(getField("Files." + fileIndex + ".UploadFrom")); + } + + /** + * Returns the content type of the file at the given index. The index is + * counted from 0. + * + * @param fileIndex + * The index of the file + * @return The content type of the file at the given index + */ + public String getFileMetadataContentType(int fileIndex) { + return getField("Files." + fileIndex + ".Metadata.ContentType"); + } + + /** + * Returns the filename of the file at the given index. This value is only + * returned if {@link #getFileUploadFrom(int)} is returning + * {@link UploadFrom#disk}. The index is counted from 0. + * + * @param fileIndex + * The index of the file + * @return The filename of the file at the given index + */ + public String getFileFilename(int fileIndex) { + return getField("Files." + fileIndex + ".Filename"); + } + +}