}
/**
+ * @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)
*/
}
/**
+ * 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)
*/
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));
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!
--- /dev/null
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp;
+
+/**
+ * The “ProtocolError” message signals that something has gone really wrong.
+ *
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @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 <code>true</code> 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 <code>-1</code> 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 <code>null</code> if there
+ * is none
+ */
+ public String getExtraDescription() {
+ return getField("ExtraDescription");
+ }
+
+ /**
+ * Returns whether the connection to the node can stay open.
+ *
+ * @return <code>true</code> when the connection has to be closed,
+ * <code>false</code> 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");
+ }
+
+}