From: David ‘Bombe’ Roden Date: Thu, 10 Apr 2008 08:32:58 +0000 (+0000) Subject: add ProtocolError message X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=59ca7b4d7186dd08109ca405c897cb2a980b9935;p=jSite2.git add ProtocolError message git-svn-id: http://trooper/svn/projects/jSite/trunk@687 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index cdfbe03..6ec19e3 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#receivedProtocolError(net.pterodactylus.util.fcp.FcpConnection, + * net.pterodactylus.util.fcp.ProtocolError) + */ + public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) { + /* empty. */ + } + + /** * @see net.pterodactylus.util.fcp.FcpListener#receivedMessage(net.pterodactylus.util.fcp.FcpConnection, * net.pterodactylus.util.fcp.FcpMessage) */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 07a0916..dabb542 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -283,6 +283,18 @@ public class FcpConnection { } /** + * Notifies all listeners that a “ProtocolError” message was received. + * + * @param protocolError + * The “ProtocolError” message + */ + private void fireReceivedProtocolError(ProtocolError protocolError) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedProtocolError(this, protocolError); + } + } + + /** * Notifies all registered listeners that a message has been received. * * @see FcpListener#receivedMessage(FcpConnection, FcpMessage) @@ -356,7 +368,9 @@ public class FcpConnection { */ void handleMessage(FcpMessage fcpMessage) { String messageName = fcpMessage.getName(); - if ("Peer".equals(messageName)) { + if ("ProtocolError".equals(messageName)) { + fireReceivedProtocolError(new ProtocolError(fcpMessage)); + } else if ("Peer".equals(messageName)) { fireReceivedPeer(new Peer(fcpMessage)); } else if ("PeerNote".equals(messageName)) { fireReceivedPeerNote(new PeerNote(fcpMessage)); diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index 50156ab..f17cdd3 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 “ProtocolError” was received. + * + * @param fcpConnection + * The connection that received the message + * @param protocolError + * The “ProtocolError” message + */ + public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError); + + /** * Notifies a listener that a message has been received. This method is only * called if {@link FcpConnection#handleMessage(FcpMessage)} does not * recognize the message. Should that ever happen, please file a bug report! diff --git a/src/net/pterodactylus/util/fcp/ProtocolError.java b/src/net/pterodactylus/util/fcp/ProtocolError.java new file mode 100644 index 0000000..c812d42 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ProtocolError.java @@ -0,0 +1,86 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + +/** + * The “ProtocolError” message signals that something has gone really wrong. + * + * @author David Roden + * @version $Id$ + */ +public class ProtocolError extends BaseMessage { + + /** + * Creates a new “ProtocolError” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + public ProtocolError(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns whether the causing message had the “Global” flag set. + * + * @return true if the causing message had the “Global” flag + * set + */ + public boolean isGlobal() { + return Boolean.valueOf(getField("Global")); + } + + /** + * Returns the error code. + * + * @return The error code, or -1 if the error code could not + * be parsed + */ + public int getCode() { + try { + return Integer.valueOf(getField("Code")); + } catch (NumberFormatException nfe1) { + return -1; + } + } + + /** + * Returns the description of the error. + * + * @return The description of the error + */ + public String getCodeDescription() { + return getField("CodeDescription"); + } + + /** + * Returns some extra description of the error. + * + * @return Extra description of the error, or null if there + * is none + */ + public String getExtraDescription() { + return getField("ExtraDescription"); + } + + /** + * Returns whether the connection to the node can stay open. + * + * @return true when the connection has to be closed, + * false otherwise + */ + public boolean isFatal() { + return Boolean.valueOf(getField("Fatal")); + } + + /** + * The identifier of the causing request, if any. + * + * @return The identifier of the causing request + */ + public String getIdentifier() { + return getField("Identifier"); + } + +}