/**
* Notifies all listeners that the connection to the node was closed.
*
- * @see FcpListener#connectionClosed(FcpConnection)
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if there was no exception
+ * @see FcpListener#connectionClosed(FcpConnection, Throwable)
*/
- private void fireConnectionClosed() {
+ private void fireConnectionClosed(Throwable throwable) {
for (FcpListener fcpListener: fcpListeners) {
- fcpListener.connectionClosed(this);
+ fcpListener.connectionClosed(this, throwable);
}
}
* does nothing.
*/
public void close() {
- if (connectionHandler == null) {
- return;
- }
- logger.info("disconnecting…");
- FcpUtils.close(remoteSocket);
- connectionHandler.stop();
- connectionHandler = null;
- fireConnectionClosed();
+ handleDisconnect(null);
}
/**
/**
* Handles a disconnect from the node.
+ *
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if there was no exception
*/
- synchronized void handleDisconnect() {
+ synchronized void handleDisconnect(Throwable throwable) {
FcpUtils.close(remoteInputStream);
FcpUtils.close(remoteOutputStream);
FcpUtils.close(remoteSocket);
- connectionHandler = null;
- fireConnectionClosed();
+ if (connectionHandler != null) {
+ connectionHandler.stop();
+ connectionHandler = null;
+ }
+ fireConnectionClosed(throwable);
}
//
/**
* Interface for objects that want to be notified on certain FCP events.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/**
* Notifies a listener that a “NodeHello” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param nodeHello
/**
* Notifies a listener that a “CloseConnectionDuplicateClientName” message
* was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param closeConnectionDuplicateClientName
/**
* Notifies a listener that a “SSKKeypair” message was received.
- *
+ *
* @param fcpConnection
* The connection that received themessage
* @param sskKeypair
/**
* Notifies a listener that a “Peer” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param peer
/**
* Notifies a listener that an “EndListPeers” message was received.
- *
+ *
* @param fcpConnection
* The connection that recevied the message
* @param endListPeers
/**
* Notifies a listener that a “PeerNote” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param peerNote
/**
* Notifies a listener that an “EndListPeerNotes” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param endListPeerNotes
/**
* Notifies a listener that a “PeerRemoved” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param peerRemoved
/**
* Notifies a listener that a “NodeData” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param nodeData
/**
* Notifies a listener that a “TestDDAReply” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param testDDAReply
/**
* Notifies a listener that a “TestDDAComplete” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param testDDAComplete
/**
* Notifies a listener that a “PersistentGet” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param persistentGet
/**
* Notifies a listener that a “PersistentPut” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param persistentPut
/**
* Notifies a listener that a “EndListPersistentRequests” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param endListPersistentRequests
/**
* Notifies a listener that a “URIGenerated” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param uriGenerated
/**
* Notifies a listener that a “DataFound” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param dataFound
/**
* Notifies a listener that an “AllData” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param allData
/**
* Notifies a listener that a “SimpleProgress” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param simpleProgress
/**
* Notifies a listener that a “StartedCompression” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param startedCompression
/**
* Notifies a listener that a “FinishedCompression” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param finishedCompression
/**
* Notifies a listener that an “UnknownPeerNoteType” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param unknownPeerNoteType
/**
* Notifies a listener that a “UnknownNodeIdentifier” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param unknownNodeIdentifier
/**
* Notifies a listener that a “ConfigData” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param configData
/**
* Notifies a listener that a “GetFailed” message was recevied.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param getFailed
/**
* Notifies a listener that a “PutFailed” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param putFailed
/**
* Notifies a listener that an “IdentifierCollision” message was receied.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param identifierCollision
/**
* Notifies a listener that a “PersistentPutDir” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param persistentPutDir
/**
* Notifies a listener that a “PersistentRequestRemoved” message was
* received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param persistentRequestRemoved
/**
* Notifies a listener that a “SubscribedUSKUpdate” message was received.
- *
+ *
* @param fcpConnection
* The connection that recevied the message
* @param subscribedUSKUpdate
/**
* Notifies a listener that a “PluginInfo” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param pluginInfo
/**
* Notifies a listener that an “FCPPluginReply“ message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param fcpPluginReply
/**
* Notifies a listener that a “PersistentRequestModified” message was
* received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param persistentRequestModified
/**
* Notifies a listener that a “PutSuccessful” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param putSuccessful
/**
* Notifies a listener that a “PutFetchable” message was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param putFetchable
/**
* Notifies a listener that a “ProtocolError” was received.
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param 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!
- *
+ *
* @param fcpConnection
* The connection that received the message
* @param fcpMessage
* Notifies a listener that a connection was closed. A closed connection can
* be reestablished by calling {@link FcpConnection#connect()} on the same
* object again.
- *
+ *
* @param fcpConnection
* The connection that was closed.
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if there was no exception
*/
- public void connectionClosed(FcpConnection fcpConnection);
+ public void connectionClosed(FcpConnection fcpConnection, Throwable throwable);
}
/**
* Notifies all listeners that a client has disconnected.
+ *
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if there was no exception
*/
- private void fireClientDisconnected() {
+ private void fireClientDisconnected(Throwable throwable) {
for (HighLevelClientListener highLevelClientListener: highLevelClientListeners) {
- highLevelClientListener.clientDisconnected(this);
+ highLevelClientListener.clientDisconnected(this, throwable);
}
}
* Disconnects the client from the node.
*/
public void disconnect() {
- fcpConnection.close();
- fireClientDisconnected();
+ disconnect(null);
}
/**
}
/**
+ * Disconnects the client from the node, handing the given Throwable to
+ * {@link #fireClientDisconnected(Throwable)}.
+ *
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if there was no exception
+ */
+ private void disconnect(Throwable throwable) {
+ fcpConnection.close();
+ fireClientDisconnected(throwable);
+ }
+
+ /**
* FCP listener for {@link HighLevelClient}.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
//
/**
- * @see net.pterodactylus.fcp.FcpListener#connectionClosed(net.pterodactylus.fcp.FcpConnection)
+ * @see net.pterodactylus.fcp.FcpListener#connectionClosed(net.pterodactylus.fcp.FcpConnection,
+ * Throwable)
*/
@SuppressWarnings("synthetic-access")
- public void connectionClosed(FcpConnection fcpConnection) {
+ public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
if (fcpConnection != HighLevelClient.this.fcpConnection) {
return;
}
cancelIdentifier(null);
- disconnect();
+ disconnect(throwable);
}
/**