git-svn-id: http://trooper/svn/projects/jFCPlib/branch/high-level-client@848
c3eda9e8-030b-0410-8277-
bc7414b0a119
/**
* Adapter for {@link FcpListener}.
/**
* Adapter for {@link FcpListener}.
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
* @see FcpListener#receivedNodeData(FcpConnection, NodeData)
*/
public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
* @see FcpListener#receivedNodeData(FcpConnection, NodeData)
*/
public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
* @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
*/
public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
* @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
*/
public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
- public void connectionClosed(FcpConnection fcpConnection) {
+ public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
/**
* Notifies all listeners that the connection to the node was closed.
*
/**
* 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) {
for (FcpListener fcpListener: fcpListeners) {
- fcpListener.connectionClosed(this);
+ fcpListener.connectionClosed(this, throwable);
* does nothing.
*/
public void close() {
* 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.
/**
* 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);
FcpUtils.close(remoteInputStream);
FcpUtils.close(remoteOutputStream);
FcpUtils.close(remoteSocket);
- connectionHandler = null;
- fireConnectionClosed();
+ if (connectionHandler != null) {
+ connectionHandler.stop();
+ connectionHandler = null;
+ }
+ fireConnectionClosed(throwable);
/**
* Handles an FCP connection to a node.
/**
* Handles an FCP connection to a node.
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/**
* Creates a new connection handler that operates on the given connection
* and input stream.
/**
* Creates a new connection handler that operates on the given connection
* and input stream.
* @param fcpConnection
* The underlying FCP connection
* @param remoteInputStream
* @param fcpConnection
* The underlying FCP connection
* @param remoteInputStream
*/
public void run() {
FcpMessage fcpMessage = null;
*/
public void run() {
FcpMessage fcpMessage = null;
+ Throwable throwable = null;
while (true) {
synchronized (this) {
if (shouldStop) {
while (true) {
synchronized (this) {
if (shouldStop) {
assert fcpMessage != null: "fcp message is null";
fcpMessage.setField(field, value);
} catch (IOException e) {
assert fcpMessage != null: "fcp message is null";
fcpMessage.setField(field, value);
} catch (IOException e) {
- fcpConnection.handleDisconnect();
+ fcpConnection.handleDisconnect(throwable);
/**
* Reads bytes from {@link #remoteInputStream} until ‘\r’ or ‘\n’ are
* encountered and decodes the read bytes using UTF-8.
/**
* Reads bytes from {@link #remoteInputStream} until ‘\r’ or ‘\n’ are
* encountered and decodes the read bytes using UTF-8.
* @return The decoded line
* @throws IOException
* if an I/O error occurs
* @return The decoded line
* @throws IOException
* if an I/O error occurs
/**
* Interface for objects that want to be notified on certain FCP events.
/**
* Interface for objects that want to be notified on certain FCP events.
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/**
* Notifies a listener that a “NodeHello” message was received.
/**
* Notifies a listener that a “NodeHello” message was received.
* @param fcpConnection
* The connection that received the message
* @param nodeHello
* @param fcpConnection
* The connection that received the message
* @param nodeHello
/**
* Notifies a listener that a “CloseConnectionDuplicateClientName” message
* was received.
/**
* Notifies a listener that a “CloseConnectionDuplicateClientName” message
* was received.
* @param fcpConnection
* The connection that received the message
* @param closeConnectionDuplicateClientName
* @param fcpConnection
* The connection that received the message
* @param closeConnectionDuplicateClientName
/**
* Notifies a listener that a “SSKKeypair” message was received.
/**
* Notifies a listener that a “SSKKeypair” message was received.
* @param fcpConnection
* The connection that received themessage
* @param sskKeypair
* @param fcpConnection
* The connection that received themessage
* @param sskKeypair
/**
* Notifies a listener that a “Peer” message was received.
/**
* Notifies a listener that a “Peer” message was received.
* @param fcpConnection
* The connection that received the message
* @param peer
* @param fcpConnection
* The connection that received the message
* @param peer
/**
* Notifies a listener that an “EndListPeers” message was received.
/**
* Notifies a listener that an “EndListPeers” message was received.
* @param fcpConnection
* The connection that recevied the message
* @param endListPeers
* @param fcpConnection
* The connection that recevied the message
* @param endListPeers
/**
* Notifies a listener that a “PeerNote” message was received.
/**
* Notifies a listener that a “PeerNote” message was received.
* @param fcpConnection
* The connection that received the message
* @param peerNote
* @param fcpConnection
* The connection that received the message
* @param peerNote
/**
* Notifies a listener that an “EndListPeerNotes” message was received.
/**
* Notifies a listener that an “EndListPeerNotes” message was received.
* @param fcpConnection
* The connection that received the message
* @param endListPeerNotes
* @param fcpConnection
* The connection that received the message
* @param endListPeerNotes
/**
* Notifies a listener that a “PeerRemoved” message was received.
/**
* Notifies a listener that a “PeerRemoved” message was received.
* @param fcpConnection
* The connection that received the message
* @param peerRemoved
* @param fcpConnection
* The connection that received the message
* @param peerRemoved
/**
* Notifies a listener that a “NodeData” message was received.
/**
* Notifies a listener that a “NodeData” message was received.
* @param fcpConnection
* The connection that received the message
* @param nodeData
* @param fcpConnection
* The connection that received the message
* @param nodeData
/**
* Notifies a listener that a “TestDDAReply” message was received.
/**
* Notifies a listener that a “TestDDAReply” message was received.
* @param fcpConnection
* The connection that received the message
* @param testDDAReply
* @param fcpConnection
* The connection that received the message
* @param testDDAReply
/**
* Notifies a listener that a “TestDDAComplete” was received.
/**
* Notifies a listener that a “TestDDAComplete” was received.
* @param fcpConnection
* The connection that received the message
* @param testDDAComplete
* @param fcpConnection
* The connection that received the message
* @param testDDAComplete
/**
* Notifies a listener that a “PersistentGet” was received.
/**
* Notifies a listener that a “PersistentGet” was received.
* @param fcpConnection
* The connection that received the message
* @param persistentGet
* @param fcpConnection
* The connection that received the message
* @param persistentGet
/**
* Notifies a listener that a “PersistentPut” was received.
/**
* Notifies a listener that a “PersistentPut” was received.
* @param fcpConnection
* The connection that received the message
* @param persistentPut
* @param fcpConnection
* The connection that received the message
* @param persistentPut
/**
* Notifies a listener that a “EndListPersistentRequests” was received.
/**
* Notifies a listener that a “EndListPersistentRequests” was received.
* @param fcpConnection
* The connection that received the message
* @param endListPersistentRequests
* @param fcpConnection
* The connection that received the message
* @param endListPersistentRequests
/**
* Notifies a listener that a “URIGenerated” was received.
/**
* Notifies a listener that a “URIGenerated” was received.
* @param fcpConnection
* The connection that received the message
* @param uriGenerated
* @param fcpConnection
* The connection that received the message
* @param uriGenerated
/**
* Notifies a listener that a “DataFound” was received.
/**
* Notifies a listener that a “DataFound” was received.
* @param fcpConnection
* The connection that received the message
* @param dataFound
* @param fcpConnection
* The connection that received the message
* @param dataFound
/**
* Notifies a listener that an “AllData” was received.
/**
* Notifies a listener that an “AllData” was received.
* @param fcpConnection
* The connection that received the message
* @param allData
* @param fcpConnection
* The connection that received the message
* @param allData
/**
* Notifies a listener that a “SimpleProgress” was received.
/**
* Notifies a listener that a “SimpleProgress” was received.
* @param fcpConnection
* The connection that received the message
* @param simpleProgress
* @param fcpConnection
* The connection that received the message
* @param simpleProgress
/**
* Notifies a listener that a “StartedCompression” was received.
/**
* Notifies a listener that a “StartedCompression” was received.
* @param fcpConnection
* The connection that received the message
* @param startedCompression
* @param fcpConnection
* The connection that received the message
* @param startedCompression
/**
* Notifies a listener that a “FinishedCompression” was received.
/**
* Notifies a listener that a “FinishedCompression” was received.
* @param fcpConnection
* The connection that received the message
* @param finishedCompression
* @param fcpConnection
* The connection that received the message
* @param finishedCompression
/**
* Notifies a listener that an “UnknownPeerNoteType” was received.
/**
* Notifies a listener that an “UnknownPeerNoteType” was received.
* @param fcpConnection
* The connection that received the message
* @param unknownPeerNoteType
* @param fcpConnection
* The connection that received the message
* @param unknownPeerNoteType
/**
* Notifies a listener that a “UnknownNodeIdentifier” message was received.
/**
* Notifies a listener that a “UnknownNodeIdentifier” message was received.
* @param fcpConnection
* The connection that received the message
* @param unknownNodeIdentifier
* @param fcpConnection
* The connection that received the message
* @param unknownNodeIdentifier
/**
* Notifies a listener that a “ConfigData” message was received.
/**
* Notifies a listener that a “ConfigData” message was received.
* @param fcpConnection
* The connection that received the message
* @param configData
* @param fcpConnection
* The connection that received the message
* @param configData
/**
* Notifies a listener that a “GetFailed” message was recevied.
/**
* Notifies a listener that a “GetFailed” message was recevied.
* @param fcpConnection
* The connection that received the message
* @param getFailed
* @param fcpConnection
* The connection that received the message
* @param getFailed
/**
* Notifies a listener that a “PutFailed” message was received.
/**
* Notifies a listener that a “PutFailed” message was received.
* @param fcpConnection
* The connection that received the message
* @param putFailed
* @param fcpConnection
* The connection that received the message
* @param putFailed
/**
* Notifies a listener that an “IdentifierCollision” message was receied.
/**
* Notifies a listener that an “IdentifierCollision” message was receied.
* @param fcpConnection
* The connection that received the message
* @param identifierCollision
* @param fcpConnection
* The connection that received the message
* @param identifierCollision
/**
* Notifies a listener that a “PersistentPutDir” message was received.
/**
* Notifies a listener that a “PersistentPutDir” message was received.
* @param fcpConnection
* The connection that received the message
* @param persistentPutDir
* @param fcpConnection
* The connection that received the message
* @param persistentPutDir
/**
* Notifies a listener that a “PersistentRequestRemoved” message was
* received.
/**
* Notifies a listener that a “PersistentRequestRemoved” message was
* received.
* @param fcpConnection
* The connection that received the message
* @param persistentRequestRemoved
* @param fcpConnection
* The connection that received the message
* @param persistentRequestRemoved
/**
* Notifies a listener that a “SubscribedUSKUpdate” message was received.
/**
* Notifies a listener that a “SubscribedUSKUpdate” message was received.
* @param fcpConnection
* The connection that recevied the message
* @param subscribedUSKUpdate
* @param fcpConnection
* The connection that recevied the message
* @param subscribedUSKUpdate
/**
* Notifies a listener that a “PluginInfo” message was received.
/**
* Notifies a listener that a “PluginInfo” message was received.
* @param fcpConnection
* The connection that received the message
* @param pluginInfo
* @param fcpConnection
* The connection that received the message
* @param pluginInfo
/**
* Notifies a listener that an “FCPPluginReply“ message was received.
/**
* Notifies a listener that an “FCPPluginReply“ message was received.
* @param fcpConnection
* The connection that received the message
* @param fcpPluginReply
* @param fcpConnection
* The connection that received the message
* @param fcpPluginReply
/**
* Notifies a listener that a “PersistentRequestModified” message was
* received.
/**
* Notifies a listener that a “PersistentRequestModified” message was
* received.
* @param fcpConnection
* The connection that received the message
* @param persistentRequestModified
* @param fcpConnection
* The connection that received the message
* @param persistentRequestModified
/**
* Notifies a listener that a “PutSuccessful” message was received.
/**
* Notifies a listener that a “PutSuccessful” message was received.
* @param fcpConnection
* The connection that received the message
* @param putSuccessful
* @param fcpConnection
* The connection that received the message
* @param putSuccessful
/**
* Notifies a listener that a “PutFetchable” message was received.
/**
* Notifies a listener that a “PutFetchable” message was received.
* @param fcpConnection
* The connection that received the message
* @param putFetchable
* @param fcpConnection
* The connection that received the message
* @param putFetchable
/**
* Notifies a listener that a “ProtocolError” was received.
/**
* Notifies a listener that a “ProtocolError” was received.
* @param fcpConnection
* The connection that received the message
* @param protocolError
* @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!
* 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
* @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.
* 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 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.
/**
* 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) {
for (HighLevelClientListener highLevelClientListener: highLevelClientListeners) {
- highLevelClientListener.clientDisconnected(this);
+ highLevelClientListener.clientDisconnected(this, throwable);
* Disconnects the client from the node.
*/
public void disconnect() {
* Disconnects the client from the node.
*/
public void disconnect() {
- fcpConnection.close();
- fireClientDisconnected();
+ * 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>
* 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")
*/
@SuppressWarnings("synthetic-access")
- public void connectionClosed(FcpConnection fcpConnection) {
+ public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
if (fcpConnection != HighLevelClient.this.fcpConnection) {
return;
}
cancelIdentifier(null);
if (fcpConnection != HighLevelClient.this.fcpConnection) {
return;
}
cancelIdentifier(null);
*
* @param highLevelClient
* The client that was disconnected
*
* @param highLevelClient
* The client that was disconnected
+ * @param throwable
+ * The exception that caused the disconnect, or <code>null</code>
+ * if no exception occured
- public void clientDisconnected(HighLevelClient highLevelClient);
+ public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable);