From: David ‘Bombe’ Roden Date: Sat, 12 Apr 2008 12:39:48 +0000 (+0000) Subject: add PutFailed X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fb5dd27f667b4877ae07e1ecfd4be7dde4ae694a;p=jSite2.git add PutFailed git-svn-id: http://trooper/svn/projects/jSite/trunk@723 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/TODO b/TODO index 5a12502..1be61e9 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ PersistentPutDir PersistentRequestModified (since 1016) PersistentRequestRemoved (since 1016) PluginInfo (since 1075) -PutFailed PutFetchable PutSuccessful RemovePersistentRequest diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 7dc8b6e..3cc9842 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -12,58 +12,56 @@ package net.pterodactylus.util.fcp; public class FcpAdapter implements FcpListener { /** - * @see FcpListener#receivedNodeHello(FcpConnection, NodeHello) + * {@inheritDoc} */ public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) { /* empty. */ } /** - * @see FcpListener#receivedCloseConnectionDuplicateClientName(FcpConnection, - * CloseConnectionDuplicateClientName) + * {@inheritDoc} */ public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { /* empty. */ } /** - * @see FcpListener#receivedSSKKeypair(FcpConnection, SSKKeypair) + * {@inheritDoc} */ public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) { /* empty. */ } /** - * @see FcpListener#receivedPeer(FcpConnection, Peer) + * {@inheritDoc} */ public void receivedPeer(FcpConnection fcpConnection, Peer peer) { /* empty. */ } /** - * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers) + * {@inheritDoc} */ public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers) { /* empty. */ } /** - * @see FcpListener#receivedPeerNote(FcpConnection, PeerNote) + * {@inheritDoc} */ public void receivedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) { /* empty. */ } /** - * @see FcpListener#receivedEndListPeerNotes(FcpConnection, - * EndListPeerNotes) + * {@inheritDoc} */ public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) { /* empty. */ } /** - * @see FcpListener#receivedPeerRemoved(FcpConnection, PeerRemoved) + * {@inheritDoc} */ public void receivedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) { /* empty. */ @@ -88,117 +86,119 @@ public class FcpAdapter implements FcpListener { } /** - * @see FcpListener#receivedTestDDAComplete(FcpConnection, TestDDAComplete) + * {@inheritDoc} */ public void receivedTestDDAComplete(FcpConnection fcpConnection, TestDDAComplete testDDAComplete) { /* empty. */ } /** - * @see FcpListener#receivedPersistentGet(FcpConnection, PersistentGet) + * {@inheritDoc} */ public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet) { /* empty. */ } /** - * @see FcpListener#receivedPersistentPut(FcpConnection, PersistentPut) + * {@inheritDoc} */ public void receivedPersistentPut(FcpConnection fcpConnection, PersistentPut persistentPut) { /* empty. */ } /** - * @see FcpListener#receivedEndListPersistentRequests(FcpConnection, - * EndListPersistentRequests) + * {@inheritDoc} */ public void receivedEndListPersistentRequests(FcpConnection fcpConnection, EndListPersistentRequests endListPersistentRequests) { /* empty. */ } /** - * @see FcpListener#receivedURIGenerated(FcpConnection, URIGenerated) + * {@inheritDoc} */ public void receivedURIGenerated(FcpConnection fcpConnection, URIGenerated uriGenerated) { /* empty. */ } /** - * @see FcpListener#receivedDataFound(FcpConnection, DataFound) + * {@inheritDoc} */ public void receivedDataFound(FcpConnection fcpConnection, DataFound dataFound) { /* empty. */ } /** - * @see FcpListener#receivedAllData(FcpConnection, AllData) + * {@inheritDoc} */ public void receivedAllData(FcpConnection fcpConnection, AllData allData) { /* empty. */ } /** - * @see FcpListener#receivedSimpleProgress(FcpConnection, SimpleProgress) + * {@inheritDoc} */ public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress) { /* empty. */ } /** - * @see FcpListener#receivedStartedCompression(FcpConnection, - * StartedCompression) + * {@inheritDoc} */ public void receivedStartedCompression(FcpConnection fcpConnection, StartedCompression startedCompression) { /* empty. */ } /** - * @see FcpListener#receviedFinishedCompression(FcpConnection, - * FinishedCompression) + * {@inheritDoc} */ public void receviedFinishedCompression(FcpConnection fcpConnection, FinishedCompression finishedCompression) { /* empty. */ } /** - * @see FcpListener#receivedUnknownPeerNoteType(FcpConnection, - * UnknownPeerNoteType) + * {@inheritDoc} */ public void receivedUnknownPeerNoteType(FcpConnection fcpConnection, UnknownPeerNoteType unknownPeerNoteType) { /* empty. */ } /** - * @see FcpListener#receivedUnknownNodeIdentifier(FcpConnection, - * UnknownNodeIdentifier) + * {@inheritDoc} */ public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier) { /* empty. */ } /** - * @see FcpListener#receivedConfigData(FcpConnection, ConfigData) + * {@inheritDoc} */ public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) { /* empty. */ } /** - * @see FcpListener#receivedGetFailed(FcpConnection, GetFailed) + * {@inheritDoc} */ public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed) { /* empty. */ } /** - * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError) + * {@inheritDoc} + */ + public void receivedPutFailed(FcpConnection fcpConnection, PutFailed putFailed) { + /* empty. */ + } + + /** + * {@inheritDoc} */ public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) { /* empty. */ } /** - * @see FcpListener#receivedMessage(FcpConnection, FcpMessage) + * {@inheritDoc} */ public void receivedMessage(FcpConnection fcpConnection, FcpMessage fcpMessage) { /* empty. */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 6c6f991..0591b9f 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -456,13 +456,25 @@ public class FcpConnection { * @param getFailed * The “GetFailed” message */ - public void fireReceivedGetFailed(GetFailed getFailed) { + private void fireReceivedGetFailed(GetFailed getFailed) { for (FcpListener fcpListener: fcpListeners) { fcpListener.receivedGetFailed(this, getFailed); } } /** + * Notifies all listeners that a “PutFailed” message was received. + * + * @param putFailed + * The “PutFailed” message + */ + private void fireReceivedPutFailed(PutFailed putFailed) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedPutFailed(this, putFailed); + } + } + + /** * Notifies all listeners that a “ProtocolError” message was received. * * @param protocolError @@ -571,6 +583,8 @@ public class FcpConnection { fireReceivedFinishedCompression(new FinishedCompression(fcpMessage)); } else if ("GetFailed".equals(messageName)) { fireReceivedGetFailed(new GetFailed(fcpMessage)); + } else if ("PutFailed".equals(messageName)) { + fireReceivedPutFailed(new PutFailed(fcpMessage)); } else if ("DataFound".equals(messageName)) { fireReceivedDataFound(new DataFound(fcpMessage)); } else if ("AllData".equals(messageName)) { diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index 7af6309..6f02866 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -271,6 +271,16 @@ public interface FcpListener extends EventListener { public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed); /** + * Notifies a listener that a “PutFailed” message was received. + * + * @param fcpConnection + * The connection that received the message + * @param putFailed + * The “PutFailed” message + */ + public void receivedPutFailed(FcpConnection fcpConnection, PutFailed putFailed); + + /** * Notifies a listener that a “ProtocolError” was received. * * @param fcpConnection diff --git a/src/net/pterodactylus/util/fcp/PutFailed.java b/src/net/pterodactylus/util/fcp/PutFailed.java new file mode 100644 index 0000000..c9d36ff --- /dev/null +++ b/src/net/pterodactylus/util/fcp/PutFailed.java @@ -0,0 +1,178 @@ +/* + * jSite2 - GetFailed.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; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * The “PutFailed” message signals the client that a {@link ClientPut} request + * has failed. This also means that no further progress messages for that + * request will be sent. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class PutFailed extends BaseMessage { + + /** + * Creates a new “PutFailed” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + PutFailed(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the code of the error. + * + * @return The code of the error, or -1 if the error code + * could not be parsed + */ + public int getCode() { + return FcpUtils.safeParseInt(getField("Code")); + } + + /** + * Returns the identifier of the request. + * + * @return The identifier of the request + */ + public String getIdentifier() { + return getField("Identifier"); + } + + /** + * 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 description of the error code. + * + * @return The description of the error code + */ + public String getCodeDescription() { + return getField("CodeDescription"); + } + + /** + * Returns the extra description of the error. + * + * @return The extra description of the error + */ + public String getExtraDescription() { + return getField("ExtraDescription"); + } + + /** + * Returns the short description of the error. + * + * @return The short description of the error + */ + public String getShortCodeDescription() { + return getField("ShortCodeDescription"); + } + + /** + * Returns the expected URI of the request. + * + * @return The expected URI + */ + public String getExpectedURI() { + return getField("ExpectedURI"); + } + + /** + * Returns whether the request failed fatally. If a request fails fatally it + * can never complete, even with inifinite retries. + * + * @return true if the request failed fatally, + * false otherwise + */ + public boolean isFatal() { + return Boolean.valueOf(getField("Fatal")); + } + + /** + * Returns a list of complex error codes with the message. Use + * {@link #getComplexErrorDescription(int)} and + * {@link #getComplexErrorCount(int)} to get details. + * + * @return A list of complex error codes + */ + public int[] getComplexErrorCodes() { + Map allFields = getFields(); + List errorCodeList = new ArrayList(); + for (Entry field: allFields.entrySet()) { + String fieldKey = field.getKey(); + if (fieldKey.startsWith("Errors.")) { + int nextDot = fieldKey.indexOf('.', 7); + if (nextDot > -1) { + int errorCode = FcpUtils.safeParseInt(fieldKey.substring(7, nextDot)); + if (errorCode != -1) { + errorCodeList.add(errorCode); + } + } + } + } + int[] errorCodes = new int[errorCodeList.size()]; + int errorIndex = 0; + for (int errorCode: errorCodeList) { + errorCodes[errorIndex++] = errorCode; + } + return errorCodes; + } + + /** + * Returns the description of the complex error. You should only hand it + * error codes you got from {@link #getComplexErrorCodes()}! + * + * @param errorCode + * The error code + * @return The description of the complex error + */ + public String getComplexErrorDescription(int errorCode) { + return getField("Errors." + errorCode + ".Description"); + } + + /** + * Returns the count of the complex error. You should only hand it error + * codes you got from {@link #getComplexErrorCodes()}! + * + * @param errorCode + * The error code + * @return The count of the complex error, or -1 if the count + * could not be parsed + */ + public int getComplexErrorCount(int errorCode) { + return FcpUtils.safeParseInt(getField("Errors." + errorCode + ".Count")); + } + +}