[freenet-cvs] r20023 - trunk/apps/jFCPlib/src/net/pterodactylus/fcp

bombe at freenetproject.org bombe at freenetproject.org
Wed May 21 20:29:20 UTC 2008


Author: bombe
Date: 2008-05-21 20:29:20 +0000 (Wed, 21 May 2008)
New Revision: 20023

Modified:
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpAdapter.java
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnection.java
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnectionHandler.java
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpListener.java
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpMessage.java
   trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpTest.java
Log:
hand in exception on disconnects, if any
handle disconnects better
use logger instead of System.out

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpAdapter.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpAdapter.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpAdapter.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -21,7 +21,7 @@
 
 /**
  * Adapter for {@link FcpListener}.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe at freenetproject.org>
  * @version $Id$
  */
@@ -85,7 +85,7 @@
 
 	/**
 	 * {@inheritDoc}
-	 * 
+	 *
 	 * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
 	 */
 	public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
@@ -94,7 +94,7 @@
 
 	/**
 	 * {@inheritDoc}
-	 * 
+	 *
 	 * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
 	 */
 	public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
@@ -286,7 +286,7 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public void connectionClosed(FcpConnection fcpConnection) {
+	public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
 		/* empty. */
 	}
 

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnection.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnection.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnection.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -19,6 +19,7 @@
 
 package net.pterodactylus.fcp;
 
+import java.io.Closeable;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -31,15 +32,19 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 
 /**
  * An FCP connection to a Freenet node.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe at freenetproject.org>
  * @version $Id$
  */
-public class FcpConnection {
+public class FcpConnection implements Closeable {
 
+	/** Logger. */
+	private static final Logger logger = Logger.getLogger(FcpConnection.class.getName());
+
 	/** The default port for FCP v2. */
 	public static final int DEFAULT_PORT = 9481;
 
@@ -70,7 +75,7 @@
 	/**
 	 * Creates a new FCP connection to the freenet node running on localhost,
 	 * using the default port.
-	 * 
+	 *
 	 * @throws UnknownHostException
 	 *             if the hostname can not be resolved
 	 */
@@ -81,7 +86,7 @@
 	/**
 	 * Creates a new FCP connection to the Freenet node running on the given
 	 * host, listening on the default port.
-	 * 
+	 *
 	 * @param host
 	 *            The hostname of the Freenet node
 	 * @throws UnknownHostException
@@ -94,7 +99,7 @@
 	/**
 	 * Creates a new FCP connection to the Freenet node running on the given
 	 * host, listening on the given port.
-	 * 
+	 *
 	 * @param host
 	 *            The hostname of the Freenet node
 	 * @param port
@@ -109,7 +114,7 @@
 	/**
 	 * Creates a new FCP connection to the Freenet node running at the given
 	 * address, listening on the default port.
-	 * 
+	 *
 	 * @param address
 	 *            The address of the Freenet node
 	 */
@@ -120,7 +125,7 @@
 	/**
 	 * Creates a new FCP connection to the Freenet node running at the given
 	 * address, listening on the given port.
-	 * 
+	 *
 	 * @param address
 	 *            The address of the Freenet node
 	 * @param port
@@ -137,7 +142,7 @@
 
 	/**
 	 * Adds the given listener to the list of listeners.
-	 * 
+	 *
 	 * @param fcpListener
 	 *            The listener to add
 	 */
@@ -147,7 +152,7 @@
 
 	/**
 	 * Removes the given listener from the list of listeners.
-	 * 
+	 *
 	 * @param fcpListener
 	 *            The listener to remove
 	 */
@@ -157,7 +162,7 @@
 
 	/**
 	 * Notifies listeners that a “NodeHello” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedNodeHello(FcpConnection, NodeHello)
 	 * @param nodeHello
 	 *            The “NodeHello” message
@@ -171,7 +176,7 @@
 	/**
 	 * Notifies listeners that a “CloseConnectionDuplicateClientName” message
 	 * was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedCloseConnectionDuplicateClientName(FcpConnection,
 	 *      CloseConnectionDuplicateClientName)
 	 * @param closeConnectionDuplicateClientName
@@ -185,7 +190,7 @@
 
 	/**
 	 * Notifies listeners that a “SSKKeypair” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedSSKKeypair(FcpConnection, SSKKeypair)
 	 * @param sskKeypair
 	 *            The “SSKKeypair” message
@@ -198,7 +203,7 @@
 
 	/**
 	 * Notifies listeners that a “Peer” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPeer(FcpConnection, Peer)
 	 * @param peer
 	 *            The “Peer” message
@@ -211,7 +216,7 @@
 
 	/**
 	 * Notifies all listeners that an “EndListPeers” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers)
 	 * @param endListPeers
 	 *            The “EndListPeers” message
@@ -224,7 +229,7 @@
 
 	/**
 	 * Notifies all listeners that a “PeerNote” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPeerNote(FcpConnection, PeerNote)
 	 * @param peerNote
 	 */
@@ -236,7 +241,7 @@
 
 	/**
 	 * Notifies all listeners that an “EndListPeerNotes” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedEndListPeerNotes(FcpConnection,
 	 *      EndListPeerNotes)
 	 * @param endListPeerNotes
@@ -250,7 +255,7 @@
 
 	/**
 	 * Notifies all listeners that a “PeerRemoved” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPeerRemoved(FcpConnection, PeerRemoved)
 	 * @param peerRemoved
 	 *            The “PeerRemoved” message
@@ -263,7 +268,7 @@
 
 	/**
 	 * Notifies all listeners that a “NodeData” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
 	 * @param nodeData
 	 *            The “NodeData” message
@@ -276,7 +281,7 @@
 
 	/**
 	 * Notifies all listeners that a “TestDDAReply” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
 	 * @param testDDAReply
 	 *            The “TestDDAReply” message
@@ -289,7 +294,7 @@
 
 	/**
 	 * Notifies all listeners that a “TestDDAComplete” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedTestDDAComplete(FcpConnection, TestDDAComplete)
 	 * @param testDDAComplete
 	 *            The “TestDDAComplete” message
@@ -302,7 +307,7 @@
 
 	/**
 	 * Notifies all listeners that a “PersistentGet” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPersistentGet(FcpConnection, PersistentGet)
 	 * @param persistentGet
 	 *            The “PersistentGet” message
@@ -315,7 +320,7 @@
 
 	/**
 	 * Notifies all listeners that a “PersistentPut” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPersistentPut(FcpConnection, PersistentPut)
 	 * @param persistentPut
 	 *            The “PersistentPut” message
@@ -329,7 +334,7 @@
 	/**
 	 * Notifies all listeners that a “EndListPersistentRequests” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedEndListPersistentRequests(FcpConnection,
 	 *      EndListPersistentRequests)
 	 * @param endListPersistentRequests
@@ -343,7 +348,7 @@
 
 	/**
 	 * Notifies all listeners that a “URIGenerated” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedURIGenerated(FcpConnection, URIGenerated)
 	 * @param uriGenerated
 	 *            The “URIGenerated” message
@@ -356,7 +361,7 @@
 
 	/**
 	 * Notifies all listeners that a “DataFound” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedDataFound(FcpConnection, DataFound)
 	 * @param dataFound
 	 *            The “DataFound” message
@@ -369,7 +374,7 @@
 
 	/**
 	 * Notifies all listeners that an “AllData” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedAllData(FcpConnection, AllData)
 	 * @param allData
 	 *            The “AllData” message
@@ -382,7 +387,7 @@
 
 	/**
 	 * Notifies all listeners that a “SimpleProgress” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedSimpleProgress(FcpConnection, SimpleProgress)
 	 * @param simpleProgress
 	 *            The “SimpleProgress” message
@@ -395,7 +400,7 @@
 
 	/**
 	 * Notifies all listeners that a “StartedCompression” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedStartedCompression(FcpConnection,
 	 *      StartedCompression)
 	 * @param startedCompression
@@ -409,7 +414,7 @@
 
 	/**
 	 * Notifies all listeners that a “FinishedCompression” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receviedFinishedCompression(FcpConnection,
 	 *      FinishedCompression)
 	 * @param finishedCompression
@@ -424,7 +429,7 @@
 	/**
 	 * Notifies all listeners that an “UnknownPeerNoteType” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedUnknownPeerNoteType(FcpConnection,
 	 *      UnknownPeerNoteType)
 	 * @param unknownPeerNoteType
@@ -439,7 +444,7 @@
 	/**
 	 * Notifies all listeners that an “UnknownNodeIdentifier” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedUnknownNodeIdentifier(FcpConnection,
 	 *      UnknownNodeIdentifier)
 	 * @param unknownNodeIdentifier
@@ -453,7 +458,7 @@
 
 	/**
 	 * Notifies all listeners that a “ConfigData” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedConfigData(FcpConnection, ConfigData)
 	 * @param configData
 	 *            The “ConfigData” message
@@ -466,7 +471,7 @@
 
 	/**
 	 * Notifies all listeners that a “GetFailed” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedGetFailed(FcpConnection, GetFailed)
 	 * @param getFailed
 	 *            The “GetFailed” message
@@ -479,7 +484,7 @@
 
 	/**
 	 * Notifies all listeners that a “PutFailed” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPutFailed(FcpConnection, PutFailed)
 	 * @param putFailed
 	 *            The “PutFailed” message
@@ -493,7 +498,7 @@
 	/**
 	 * Notifies all listeners that an “IdentifierCollision” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedIdentifierCollision(FcpConnection,
 	 *      IdentifierCollision)
 	 * @param identifierCollision
@@ -507,7 +512,7 @@
 
 	/**
 	 * Notifies all listeners that an “PersistentPutDir” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPersistentPutDir(FcpConnection,
 	 *      PersistentPutDir)
 	 * @param persistentPutDir
@@ -522,7 +527,7 @@
 	/**
 	 * Notifies all listeners that a “PersistentRequestRemoved” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPersistentRequestRemoved(FcpConnection,
 	 *      PersistentRequestRemoved)
 	 * @param persistentRequestRemoved
@@ -536,7 +541,7 @@
 
 	/**
 	 * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
 	 *      SubscribedUSKUpdate)
 	 * @param subscribedUSKUpdate
@@ -550,7 +555,7 @@
 
 	/**
 	 * Notifies all listeners that a “PluginInfo” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPluginInfo(FcpConnection, PluginInfo)
 	 * @param pluginInfo
 	 *            The “PluginInfo” message
@@ -563,7 +568,7 @@
 
 	/**
 	 * Notifies all listeners that an “FCPPluginReply” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedFCPPluginReply(FcpConnection, FCPPluginReply)
 	 * @param fcpPluginReply
 	 *            The “FCPPluginReply” message
@@ -577,7 +582,7 @@
 	/**
 	 * Notifies all listeners that a “PersistentRequestModified” message was
 	 * received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPersistentRequestModified(FcpConnection,
 	 *      PersistentRequestModified)
 	 * @param persistentRequestModified
@@ -591,7 +596,7 @@
 
 	/**
 	 * Notifies all listeners that a “PutSuccessful” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPutSuccessful(FcpConnection, PutSuccessful)
 	 * @param putSuccessful
 	 *            The “PutSuccessful” message
@@ -604,7 +609,7 @@
 
 	/**
 	 * Notifies all listeners that a “PutFetchable” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedPutFetchable(FcpConnection, PutFetchable)
 	 * @param putFetchable
 	 *            The “PutFetchable” message
@@ -617,7 +622,7 @@
 
 	/**
 	 * Notifies all listeners that a “ProtocolError” message was received.
-	 * 
+	 *
 	 * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError)
 	 * @param protocolError
 	 *            The “ProtocolError” message
@@ -630,7 +635,7 @@
 
 	/**
 	 * Notifies all registered listeners that a message has been received.
-	 * 
+	 *
 	 * @see FcpListener#receivedMessage(FcpConnection, FcpMessage)
 	 * @param fcpMessage
 	 *            The message that was received
@@ -643,12 +648,15 @@
 
 	/**
 	 * 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);
 		}
 	}
 
@@ -658,7 +666,7 @@
 
 	/**
 	 * Connects to the node.
-	 * 
+	 *
 	 * @throws IOException
 	 *             if an I/O error occurs
 	 * @throws IllegalStateException
@@ -668,6 +676,7 @@
 		if (connectionHandler != null) {
 			throw new IllegalStateException("already connected, disconnect first");
 		}
+		logger.info("connecting to " + address + ":" + port + "…");
 		remoteSocket = new Socket(address, port);
 		remoteInputStream = remoteSocket.getInputStream();
 		remoteOutputStream = remoteSocket.getOutputStream();
@@ -677,27 +686,32 @@
 	/**
 	 * Disconnects from the node. If there is no connection to the node, this
 	 * method does nothing.
+	 *
+	 * @deprecated Use {@link #close()} instead
 	 */
+	@Deprecated
 	public synchronized void disconnect() {
-		if (connectionHandler == null) {
-			return;
-		}
-		FcpUtils.close(remoteSocket);
-		connectionHandler.stop();
-		connectionHandler = null;
-		fireConnectionClosed();
+		close();
 	}
 
 	/**
+	 * Closes the connection. If there is no connection to the node, this method
+	 * does nothing.
+	 */
+	public void close() {
+		handleDisconnect(null);
+	}
+
+	/**
 	 * Sends the given FCP message.
-	 * 
+	 *
 	 * @param fcpMessage
 	 *            The FCP message to send
 	 * @throws IOException
 	 *             if an I/O error occurs
 	 */
 	public synchronized void sendMessage(FcpMessage fcpMessage) throws IOException {
-		System.out.println("sending message: " + fcpMessage.getName());
+		logger.fine("sending message: " + fcpMessage.getName());
 		fcpMessage.write(remoteOutputStream);
 	}
 
@@ -708,11 +722,12 @@
 	/**
 	 * Handles the given message, notifying listeners. This message should only
 	 * be called by {@link FcpConnectionHandler}.
-	 * 
+	 *
 	 * @param fcpMessage
 	 *            The received message
 	 */
 	void handleMessage(FcpMessage fcpMessage) {
+		logger.fine("received message: " + fcpMessage.getName());
 		String messageName = fcpMessage.getName();
 		countMessage(messageName);
 		if ("SimpleProgress".equals(messageName)) {
@@ -804,13 +819,20 @@
 
 	/**
 	 * 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);
+		}
 	}
 
 	//
@@ -820,7 +842,7 @@
 	/**
 	 * Incremets the counter in {@link #incomingMessageStatistics} by <cod>1</code>
 	 * for the given message name.
-	 * 
+	 *
 	 * @param name
 	 *            The name of the message to count
 	 */
@@ -830,11 +852,12 @@
 			oldValue = incomingMessageStatistics.get(name);
 		}
 		incomingMessageStatistics.put(name, oldValue + 1);
+		logger.finest("count for " + name + ": " + (oldValue + 1));
 	}
 
 	/**
 	 * Returns a limited input stream from the node’s input stream.
-	 * 
+	 *
 	 * @param dataLength
 	 *            The length of the stream
 	 * @return The limited input stream
@@ -849,7 +872,7 @@
 	/**
 	 * A wrapper around an {@link InputStream} that only supplies a limit number
 	 * of bytes from the underlying input stream.
-	 * 
+	 *
 	 * @author <a href="mailto:dr at ina-germany.de">David Roden</a>
 	 * @version $Id$
 	 */
@@ -861,7 +884,7 @@
 		/**
 		 * Creates a new LimitedInputStream that supplies at most
 		 * <code>length</code> bytes from the given input stream.
-		 * 
+		 *
 		 * @param inputStream
 		 *            The input stream
 		 * @param length
@@ -926,7 +949,7 @@
 		/**
 		 * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
 		 * {@link #reset()} are not supported.
-		 * 
+		 *
 		 * @see java.io.FilterInputStream#mark(int)
 		 */
 		@Override
@@ -936,7 +959,7 @@
 
 		/**
 		 * {@inheritDoc}
-		 * 
+		 *
 		 * @see java.io.FilterInputStream#markSupported()
 		 * @return <code>false</code>
 		 */
@@ -948,7 +971,7 @@
 		/**
 		 * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
 		 * {@link #reset()} are not supported.
-		 * 
+		 *
 		 * @see java.io.FilterInputStream#reset()
 		 */
 		@Override
@@ -959,7 +982,7 @@
 		/**
 		 * Consumes the input stream, i.e. read all bytes until the limit is
 		 * reached.
-		 * 
+		 *
 		 * @throws IOException
 		 *             if an I/O error occurs
 		 */

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnectionHandler.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnectionHandler.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpConnectionHandler.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -26,7 +26,7 @@
 
 /**
  * Handles an FCP connection to a node.
- * 
+ *
  * @author David ‘Bombe’ Roden &lt;bombe at freenetproject.org&gt;
  * @version $Id$
  */
@@ -47,7 +47,7 @@
 	/**
 	 * Creates a new connection handler that operates on the given connection
 	 * and input stream.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The underlying FCP connection
 	 * @param remoteInputStream
@@ -63,6 +63,7 @@
 	 */
 	public void run() {
 		FcpMessage fcpMessage = null;
+		Throwable throwable = null;
 		while (true) {
 			synchronized (this) {
 				if (shouldStop) {
@@ -96,11 +97,12 @@
 				String value = line.substring(equalSign + 1);
 				assert fcpMessage != null: "fcp message is null";
 				fcpMessage.setField(field, value);
-			} catch (IOException e) {
+			} catch (IOException ioe1) {
+				throwable = ioe1;
 				break;
 			}
 		}
-		fcpConnection.handleDisconnect();
+		fcpConnection.handleDisconnect(throwable);
 	}
 
 	/**
@@ -119,7 +121,7 @@
 	/**
 	 * 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

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpListener.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpListener.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpListener.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -23,7 +23,7 @@
 
 /**
  * Interface for objects that want to be notified on certain FCP events.
- * 
+ *
  * @author David ‘Bombe’ Roden &lt;bombe at freenetproject.org&gt;
  * @version $Id$
  */
@@ -31,7 +31,7 @@
 
 	/**
 	 * Notifies a listener that a “NodeHello” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param nodeHello
@@ -42,7 +42,7 @@
 	/**
 	 * Notifies a listener that a “CloseConnectionDuplicateClientName” message
 	 * was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param closeConnectionDuplicateClientName
@@ -52,7 +52,7 @@
 
 	/**
 	 * Notifies a listener that a “SSKKeypair” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received themessage
 	 * @param sskKeypair
@@ -62,7 +62,7 @@
 
 	/**
 	 * Notifies a listener that a “Peer” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param peer
@@ -72,7 +72,7 @@
 
 	/**
 	 * Notifies a listener that an “EndListPeers” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that recevied the message
 	 * @param endListPeers
@@ -82,7 +82,7 @@
 
 	/**
 	 * Notifies a listener that a “PeerNote” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param peerNote
@@ -92,7 +92,7 @@
 
 	/**
 	 * Notifies a listener that an “EndListPeerNotes” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param endListPeerNotes
@@ -102,7 +102,7 @@
 
 	/**
 	 * Notifies a listener that a “PeerRemoved” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param peerRemoved
@@ -112,7 +112,7 @@
 
 	/**
 	 * Notifies a listener that a “NodeData” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param nodeData
@@ -122,7 +122,7 @@
 
 	/**
 	 * Notifies a listener that a “TestDDAReply” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param testDDAReply
@@ -132,7 +132,7 @@
 
 	/**
 	 * Notifies a listener that a “TestDDAComplete” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param testDDAComplete
@@ -142,7 +142,7 @@
 
 	/**
 	 * Notifies a listener that a “PersistentGet” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param persistentGet
@@ -152,7 +152,7 @@
 
 	/**
 	 * Notifies a listener that a “PersistentPut” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param persistentPut
@@ -162,7 +162,7 @@
 
 	/**
 	 * Notifies a listener that a “EndListPersistentRequests” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param endListPersistentRequests
@@ -172,7 +172,7 @@
 
 	/**
 	 * Notifies a listener that a “URIGenerated” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param uriGenerated
@@ -182,7 +182,7 @@
 
 	/**
 	 * Notifies a listener that a “DataFound” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param dataFound
@@ -192,7 +192,7 @@
 
 	/**
 	 * Notifies a listener that an “AllData” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param allData
@@ -202,7 +202,7 @@
 
 	/**
 	 * Notifies a listener that a “SimpleProgress” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param simpleProgress
@@ -212,7 +212,7 @@
 
 	/**
 	 * Notifies a listener that a “StartedCompression” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param startedCompression
@@ -222,7 +222,7 @@
 
 	/**
 	 * Notifies a listener that a “FinishedCompression” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param finishedCompression
@@ -232,7 +232,7 @@
 
 	/**
 	 * Notifies a listener that an “UnknownPeerNoteType” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param unknownPeerNoteType
@@ -242,7 +242,7 @@
 
 	/**
 	 * Notifies a listener that a “UnknownNodeIdentifier” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param unknownNodeIdentifier
@@ -252,7 +252,7 @@
 
 	/**
 	 * Notifies a listener that a “ConfigData” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param configData
@@ -262,7 +262,7 @@
 
 	/**
 	 * Notifies a listener that a “GetFailed” message was recevied.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param getFailed
@@ -272,7 +272,7 @@
 
 	/**
 	 * Notifies a listener that a “PutFailed” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param putFailed
@@ -282,7 +282,7 @@
 
 	/**
 	 * Notifies a listener that an “IdentifierCollision” message was receied.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param identifierCollision
@@ -292,7 +292,7 @@
 
 	/**
 	 * Notifies a listener that a “PersistentPutDir” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param persistentPutDir
@@ -303,7 +303,7 @@
 	/**
 	 * Notifies a listener that a “PersistentRequestRemoved” message was
 	 * received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param persistentRequestRemoved
@@ -313,7 +313,7 @@
 
 	/**
 	 * Notifies a listener that a “SubscribedUSKUpdate” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that recevied the message
 	 * @param subscribedUSKUpdate
@@ -323,7 +323,7 @@
 
 	/**
 	 * Notifies a listener that a “PluginInfo” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param pluginInfo
@@ -333,7 +333,7 @@
 
 	/**
 	 * Notifies a listener that an “FCPPluginReply“ message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param fcpPluginReply
@@ -344,7 +344,7 @@
 	/**
 	 * Notifies a listener that a “PersistentRequestModified” message was
 	 * received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param persistentRequestModified
@@ -354,7 +354,7 @@
 
 	/**
 	 * Notifies a listener that a “PutSuccessful” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param putSuccessful
@@ -364,7 +364,7 @@
 
 	/**
 	 * Notifies a listener that a “PutFetchable” message was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param putFetchable
@@ -374,7 +374,7 @@
 
 	/**
 	 * Notifies a listener that a “ProtocolError” was received.
-	 * 
+	 *
 	 * @param fcpConnection
 	 *            The connection that received the message
 	 * @param protocolError
@@ -386,7 +386,7 @@
 	 * 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
@@ -398,10 +398,13 @@
 	 * 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);
 
 }

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpMessage.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpMessage.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpMessage.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -32,7 +32,7 @@
  * An FCP message. FCP messages consist of a name, an arbitrary amount of
  * “fields” (i.e. key-value pairs), a message end marker, and optional payload
  * data that follows the marker.
- * 
+ *
  * @author David ‘Bombe’ Roden &lt;bombe at freenetproject.org&gt;
  * @version $Id$
  */
@@ -52,7 +52,7 @@
 
 	/**
 	 * Creates a new FCP message with the given name.
-	 * 
+	 *
 	 * @param name
 	 *            The name of the FCP message
 	 */
@@ -64,7 +64,7 @@
 	 * Creates a new FCP message with the given name and the given payload input
 	 * stream. The payload input stream is not read until the message is sent to
 	 * the node using {@link FcpConnection#sendMessage(FcpMessage)}.
-	 * 
+	 *
 	 * @param name
 	 *            The name of the message
 	 * @param payloadInputStream
@@ -77,7 +77,7 @@
 
 	/**
 	 * Returns the name of the message.
-	 * 
+	 *
 	 * @return The name of the message
 	 */
 	public String getName() {
@@ -86,7 +86,7 @@
 
 	/**
 	 * Checks whether this message has a field with the given name.
-	 * 
+	 *
 	 * @param field
 	 *            The name of the field to check for
 	 * @return <code>true</code> if the message has a field with the given
@@ -99,7 +99,7 @@
 	/**
 	 * Sets the field with the given name to the given value. If the field
 	 * already exists in this message it is overwritten.
-	 * 
+	 *
 	 * @param field
 	 *            The name of the field
 	 * @param value
@@ -114,7 +114,7 @@
 
 	/**
 	 * Returns the value of the given field.
-	 * 
+	 *
 	 * @param field
 	 *            The name of the field
 	 * @return The value of the field, or <code>null</code> if there is no
@@ -126,7 +126,7 @@
 
 	/**
 	 * Returns all fields of this message.
-	 * 
+	 *
 	 * @return All fields of this message
 	 */
 	public Map<String, String> getFields() {
@@ -142,7 +142,7 @@
 
 	/**
 	 * Sets the payload input stream of the message.
-	 * 
+	 *
 	 * @param payloadInputStream
 	 *            The payload input stream
 	 */
@@ -156,7 +156,7 @@
 	 * the payload is written to the given output stream after the message as
 	 * well. That means that this method can only be called once because on the
 	 * second invocation the payload input stream could not be read (again).
-	 * 
+	 *
 	 * @param outputStream
 	 *            The output stream to write the message to
 	 * @throws IOException
@@ -171,8 +171,8 @@
 		outputStream.flush();
 		if (payloadInputStream != null) {
 			FcpUtils.copy(payloadInputStream, outputStream);
+			outputStream.flush();
 		}
-		outputStream.flush();
 	}
 
 	//
@@ -182,7 +182,7 @@
 	/**
 	 * Writes the given line (followed by {@link #LINEFEED} to the given output
 	 * stream, using UTF-8 as encoding.
-	 * 
+	 *
 	 * @param outputStream
 	 *            The output stream to write to
 	 * @param line

Modified: trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpTest.java
===================================================================
--- trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpTest.java	2008-05-21 18:34:27 UTC (rev 20022)
+++ trunk/apps/jFCPlib/src/net/pterodactylus/fcp/FcpTest.java	2008-05-21 20:29:20 UTC (rev 20023)
@@ -25,7 +25,7 @@
 
 /**
  * Tests various commands and the FCP connection.
- * 
+ *
  * @author David ‘Bombe’ Roden &lt;bombe at freenetproject.org&gt;
  * @version $Id$
  */
@@ -49,7 +49,7 @@
 	 */
 	@Override
 	protected void tearDown() throws Exception {
-		fcpConnection.disconnect();
+		fcpConnection.close();
 	}
 
 	/**
@@ -62,7 +62,7 @@
 
 	/**
 	 * Generates an SSK key pair.
-	 * 
+	 *
 	 * @throws IOException
 	 *             if an I/O error occurs
 	 * @throws InterruptedException




More information about the cvs mailing list