Use listener manager.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 17 Mar 2009 23:34:32 +0000 (00:34 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 19 Mar 2009 22:09:09 +0000 (23:09 +0100)
src/net/pterodactylus/fcp/FcpConnection.java

index 05d8815..a80c610 100644 (file)
@@ -27,16 +27,14 @@ import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.Socket;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
 import java.util.Collections;
 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 &lt;bombe@freenetproject.org&gt;
  */
 public class FcpConnection implements Closeable {
@@ -47,8 +45,8 @@ public class FcpConnection implements Closeable {
        /** The default port for FCP v2. */
        public static final int DEFAULT_PORT = 9481;
 
-       /** The list of FCP listeners. */
-       private final List<FcpListener> fcpListeners = new ArrayList<FcpListener>();
+       /** Listener management. */
+       private final FcpListenerManager fcpListenerManager = new FcpListenerManager(this);
 
        /** The address of the node. */
        private final InetAddress address;
@@ -74,7 +72,7 @@ public class FcpConnection implements Closeable {
        /**
         * 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
         */
@@ -85,7 +83,7 @@ public class FcpConnection implements Closeable {
        /**
         * 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
@@ -98,7 +96,7 @@ public class FcpConnection implements Closeable {
        /**
         * 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
@@ -113,7 +111,7 @@ public class FcpConnection implements Closeable {
        /**
         * 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
         */
@@ -124,7 +122,7 @@ public class FcpConnection implements Closeable {
        /**
         * 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
@@ -141,522 +139,22 @@ public class FcpConnection implements Closeable {
 
        /**
         * Adds the given listener to the list of listeners.
-        * 
+        *
         * @param fcpListener
         *            The listener to add
         */
        public void addFcpListener(FcpListener fcpListener) {
-               fcpListeners.add(fcpListener);
+               fcpListenerManager.addListener(fcpListener);
        }
 
        /**
         * Removes the given listener from the list of listeners.
-        * 
+        *
         * @param fcpListener
         *            The listener to remove
         */
        public void removeFcpListener(FcpListener fcpListener) {
-               fcpListeners.remove(fcpListener);
-       }
-
-       /**
-        * Notifies listeners that a “NodeHello” message was received.
-        * 
-        * @see FcpListener#receivedNodeHello(FcpConnection, NodeHello)
-        * @param nodeHello
-        *            The “NodeHello” message
-        */
-       private void fireReceivedNodeHello(NodeHello nodeHello) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedNodeHello(this, nodeHello);
-               }
-       }
-
-       /**
-        * Notifies listeners that a “CloseConnectionDuplicateClientName” message
-        * was received.
-        * 
-        * @see FcpListener#receivedCloseConnectionDuplicateClientName(FcpConnection,
-        *      CloseConnectionDuplicateClientName)
-        * @param closeConnectionDuplicateClientName
-        *            The “CloseConnectionDuplicateClientName” message
-        */
-       private void fireReceivedCloseConnectionDuplicateClientName(CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedCloseConnectionDuplicateClientName(this, closeConnectionDuplicateClientName);
-               }
-       }
-
-       /**
-        * Notifies listeners that a “SSKKeypair” message was received.
-        * 
-        * @see FcpListener#receivedSSKKeypair(FcpConnection, SSKKeypair)
-        * @param sskKeypair
-        *            The “SSKKeypair” message
-        */
-       private void fireReceivedSSKKeypair(SSKKeypair sskKeypair) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedSSKKeypair(this, sskKeypair);
-               }
-       }
-
-       /**
-        * Notifies listeners that a “Peer” message was received.
-        * 
-        * @see FcpListener#receivedPeer(FcpConnection, Peer)
-        * @param peer
-        *            The “Peer” message
-        */
-       private void fireReceivedPeer(Peer peer) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPeer(this, peer);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “EndListPeers” message was received.
-        * 
-        * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers)
-        * @param endListPeers
-        *            The “EndListPeers” message
-        */
-       private void fireReceivedEndListPeers(EndListPeers endListPeers) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedEndListPeers(this, endListPeers);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PeerNote” message was received.
-        * 
-        * @see FcpListener#receivedPeerNote(FcpConnection, PeerNote)
-        * @param peerNote
-        */
-       private void fireReceivedPeerNote(PeerNote peerNote) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPeerNote(this, peerNote);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “EndListPeerNotes” message was received.
-        * 
-        * @see FcpListener#receivedEndListPeerNotes(FcpConnection,
-        *      EndListPeerNotes)
-        * @param endListPeerNotes
-        *            The “EndListPeerNotes” message
-        */
-       private void fireReceivedEndListPeerNotes(EndListPeerNotes endListPeerNotes) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedEndListPeerNotes(this, endListPeerNotes);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PeerRemoved” message was received.
-        * 
-        * @see FcpListener#receivedPeerRemoved(FcpConnection, PeerRemoved)
-        * @param peerRemoved
-        *            The “PeerRemoved” message
-        */
-       private void fireReceivedPeerRemoved(PeerRemoved peerRemoved) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPeerRemoved(this, peerRemoved);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “NodeData” message was received.
-        * 
-        * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
-        * @param nodeData
-        *            The “NodeData” message
-        */
-       private void fireReceivedNodeData(NodeData nodeData) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedNodeData(this, nodeData);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “TestDDAReply” message was received.
-        * 
-        * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
-        * @param testDDAReply
-        *            The “TestDDAReply” message
-        */
-       private void fireReceivedTestDDAReply(TestDDAReply testDDAReply) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedTestDDAReply(this, testDDAReply);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “TestDDAComplete” message was received.
-        * 
-        * @see FcpListener#receivedTestDDAComplete(FcpConnection, TestDDAComplete)
-        * @param testDDAComplete
-        *            The “TestDDAComplete” message
-        */
-       private void fireReceivedTestDDAComplete(TestDDAComplete testDDAComplete) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedTestDDAComplete(this, testDDAComplete);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PersistentGet” message was received.
-        * 
-        * @see FcpListener#receivedPersistentGet(FcpConnection, PersistentGet)
-        * @param persistentGet
-        *            The “PersistentGet” message
-        */
-       private void fireReceivedPersistentGet(PersistentGet persistentGet) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPersistentGet(this, persistentGet);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PersistentPut” message was received.
-        * 
-        * @see FcpListener#receivedPersistentPut(FcpConnection, PersistentPut)
-        * @param persistentPut
-        *            The “PersistentPut” message
-        */
-       private void fireReceivedPersistentPut(PersistentPut persistentPut) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPersistentPut(this, persistentPut);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “EndListPersistentRequests” message was
-        * received.
-        * 
-        * @see FcpListener#receivedEndListPersistentRequests(FcpConnection,
-        *      EndListPersistentRequests)
-        * @param endListPersistentRequests
-        *            The “EndListPersistentRequests” message
-        */
-       private void fireReceivedEndListPersistentRequests(EndListPersistentRequests endListPersistentRequests) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedEndListPersistentRequests(this, endListPersistentRequests);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “URIGenerated” message was received.
-        * 
-        * @see FcpListener#receivedURIGenerated(FcpConnection, URIGenerated)
-        * @param uriGenerated
-        *            The “URIGenerated” message
-        */
-       private void fireReceivedURIGenerated(URIGenerated uriGenerated) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedURIGenerated(this, uriGenerated);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “DataFound” message was received.
-        * 
-        * @see FcpListener#receivedDataFound(FcpConnection, DataFound)
-        * @param dataFound
-        *            The “DataFound” message
-        */
-       private void fireReceivedDataFound(DataFound dataFound) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedDataFound(this, dataFound);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “AllData” message was received.
-        * 
-        * @see FcpListener#receivedAllData(FcpConnection, AllData)
-        * @param allData
-        *            The “AllData” message
-        */
-       private void fireReceivedAllData(AllData allData) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedAllData(this, allData);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “SimpleProgress” message was received.
-        * 
-        * @see FcpListener#receivedSimpleProgress(FcpConnection, SimpleProgress)
-        * @param simpleProgress
-        *            The “SimpleProgress” message
-        */
-       private void fireReceivedSimpleProgress(SimpleProgress simpleProgress) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedSimpleProgress(this, simpleProgress);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “StartedCompression” message was received.
-        * 
-        * @see FcpListener#receivedStartedCompression(FcpConnection,
-        *      StartedCompression)
-        * @param startedCompression
-        *            The “StartedCompression” message
-        */
-       private void fireReceivedStartedCompression(StartedCompression startedCompression) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedStartedCompression(this, startedCompression);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “FinishedCompression” message was received.
-        * 
-        * @see FcpListener#receviedFinishedCompression(FcpConnection,
-        *      FinishedCompression)
-        * @param finishedCompression
-        *            The “FinishedCompression” message
-        */
-       private void fireReceivedFinishedCompression(FinishedCompression finishedCompression) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receviedFinishedCompression(this, finishedCompression);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “UnknownPeerNoteType” message was
-        * received.
-        * 
-        * @see FcpListener#receivedUnknownPeerNoteType(FcpConnection,
-        *      UnknownPeerNoteType)
-        * @param unknownPeerNoteType
-        *            The “UnknownPeerNoteType” message
-        */
-       private void fireReceivedUnknownPeerNoteType(UnknownPeerNoteType unknownPeerNoteType) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedUnknownPeerNoteType(this, unknownPeerNoteType);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “UnknownNodeIdentifier” message was
-        * received.
-        * 
-        * @see FcpListener#receivedUnknownNodeIdentifier(FcpConnection,
-        *      UnknownNodeIdentifier)
-        * @param unknownNodeIdentifier
-        *            The “UnknownNodeIdentifier” message
-        */
-       private void fireReceivedUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedUnknownNodeIdentifier(this, unknownNodeIdentifier);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “ConfigData” message was received.
-        * 
-        * @see FcpListener#receivedConfigData(FcpConnection, ConfigData)
-        * @param configData
-        *            The “ConfigData” message
-        */
-       private void fireReceivedConfigData(ConfigData configData) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedConfigData(this, configData);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “GetFailed” message was received.
-        * 
-        * @see FcpListener#receivedGetFailed(FcpConnection, GetFailed)
-        * @param getFailed
-        *            The “GetFailed” message
-        */
-       private void fireReceivedGetFailed(GetFailed getFailed) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedGetFailed(this, getFailed);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PutFailed” message was received.
-        * 
-        * @see FcpListener#receivedPutFailed(FcpConnection, PutFailed)
-        * @param putFailed
-        *            The “PutFailed” message
-        */
-       private void fireReceivedPutFailed(PutFailed putFailed) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPutFailed(this, putFailed);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “IdentifierCollision” message was
-        * received.
-        * 
-        * @see FcpListener#receivedIdentifierCollision(FcpConnection,
-        *      IdentifierCollision)
-        * @param identifierCollision
-        *            The “IdentifierCollision” message
-        */
-       private void fireReceivedIdentifierCollision(IdentifierCollision identifierCollision) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedIdentifierCollision(this, identifierCollision);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “PersistentPutDir” message was received.
-        * 
-        * @see FcpListener#receivedPersistentPutDir(FcpConnection,
-        *      PersistentPutDir)
-        * @param persistentPutDir
-        *            The “PersistentPutDir” message
-        */
-       private void fireReceivedPersistentPutDir(PersistentPutDir persistentPutDir) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPersistentPutDir(this, persistentPutDir);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PersistentRequestRemoved” message was
-        * received.
-        * 
-        * @see FcpListener#receivedPersistentRequestRemoved(FcpConnection,
-        *      PersistentRequestRemoved)
-        * @param persistentRequestRemoved
-        *            The “PersistentRequestRemoved” message
-        */
-       private void fireReceivedPersistentRequestRemoved(PersistentRequestRemoved persistentRequestRemoved) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPersistentRequestRemoved(this, persistentRequestRemoved);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
-        * 
-        * @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
-        *      SubscribedUSKUpdate)
-        * @param subscribedUSKUpdate
-        *            The “SubscribedUSKUpdate” message
-        */
-       private void fireReceivedSubscribedUSKUpdate(SubscribedUSKUpdate subscribedUSKUpdate) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedSubscribedUSKUpdate(this, subscribedUSKUpdate);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PluginInfo” message was received.
-        * 
-        * @see FcpListener#receivedPluginInfo(FcpConnection, PluginInfo)
-        * @param pluginInfo
-        *            The “PluginInfo” message
-        */
-       private void fireReceivedPluginInfo(PluginInfo pluginInfo) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPluginInfo(this, pluginInfo);
-               }
-       }
-
-       /**
-        * Notifies all listeners that an “FCPPluginReply” message was received.
-        * 
-        * @see FcpListener#receivedFCPPluginReply(FcpConnection, FCPPluginReply)
-        * @param fcpPluginReply
-        *            The “FCPPluginReply” message
-        */
-       private void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedFCPPluginReply(this, fcpPluginReply);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PersistentRequestModified” message was
-        * received.
-        * 
-        * @see FcpListener#receivedPersistentRequestModified(FcpConnection,
-        *      PersistentRequestModified)
-        * @param persistentRequestModified
-        *            The “PersistentRequestModified” message
-        */
-       private void fireReceivedPersistentRequestModified(PersistentRequestModified persistentRequestModified) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPersistentRequestModified(this, persistentRequestModified);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PutSuccessful” message was received.
-        * 
-        * @see FcpListener#receivedPutSuccessful(FcpConnection, PutSuccessful)
-        * @param putSuccessful
-        *            The “PutSuccessful” message
-        */
-       private void fireReceivedPutSuccessful(PutSuccessful putSuccessful) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPutSuccessful(this, putSuccessful);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “PutFetchable” message was received.
-        * 
-        * @see FcpListener#receivedPutFetchable(FcpConnection, PutFetchable)
-        * @param putFetchable
-        *            The “PutFetchable” message
-        */
-       private void fireReceivedPutFetchable(PutFetchable putFetchable) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedPutFetchable(this, putFetchable);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a “ProtocolError” message was received.
-        * 
-        * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError)
-        * @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)
-        * @param fcpMessage
-        *            The message that was received
-        */
-       private void fireMessageReceived(FcpMessage fcpMessage) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.receivedMessage(this, fcpMessage);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the connection to the node was closed.
-        * 
-        * @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(Throwable throwable) {
-               for (FcpListener fcpListener : fcpListeners) {
-                       fcpListener.connectionClosed(this, throwable);
-               }
+               fcpListenerManager.removeListener(fcpListener);
        }
 
        //
@@ -665,7 +163,7 @@ public class FcpConnection implements Closeable {
 
        /**
         * Connects to the node.
-        * 
+        *
         * @throws IOException
         *             if an I/O error occurs
         * @throws IllegalStateException
@@ -685,7 +183,7 @@ public class FcpConnection implements Closeable {
        /**
         * Disconnects from the node. If there is no connection to the node, this
         * method does nothing.
-        * 
+        *
         * @deprecated Use {@link #close()} instead
         */
        @Deprecated
@@ -703,7 +201,7 @@ public class FcpConnection implements Closeable {
 
        /**
         * Sends the given FCP message.
-        * 
+        *
         * @param fcpMessage
         *            The FCP message to send
         * @throws IOException
@@ -721,7 +219,7 @@ public class FcpConnection implements Closeable {
        /**
         * Handles the given message, notifying listeners. This message should only
         * be called by {@link FcpConnectionHandler}.
-        * 
+        *
         * @param fcpMessage
         *            The received message
         */
@@ -730,95 +228,95 @@ public class FcpConnection implements Closeable {
                String messageName = fcpMessage.getName();
                countMessage(messageName);
                if ("SimpleProgress".equals(messageName)) {
-                       fireReceivedSimpleProgress(new SimpleProgress(fcpMessage));
+                       fcpListenerManager.fireReceivedSimpleProgress(new SimpleProgress(fcpMessage));
                } else if ("ProtocolError".equals(messageName)) {
-                       fireReceivedProtocolError(new ProtocolError(fcpMessage));
+                       fcpListenerManager.fireReceivedProtocolError(new ProtocolError(fcpMessage));
                } else if ("PersistentGet".equals(messageName)) {
-                       fireReceivedPersistentGet(new PersistentGet(fcpMessage));
+                       fcpListenerManager.fireReceivedPersistentGet(new PersistentGet(fcpMessage));
                } else if ("PersistentPut".equals(messageName)) {
-                       fireReceivedPersistentPut(new PersistentPut(fcpMessage));
+                       fcpListenerManager.fireReceivedPersistentPut(new PersistentPut(fcpMessage));
                } else if ("PersistentPutDir".equals(messageName)) {
-                       fireReceivedPersistentPutDir(new PersistentPutDir(fcpMessage));
+                       fcpListenerManager.fireReceivedPersistentPutDir(new PersistentPutDir(fcpMessage));
                } else if ("URIGenerated".equals(messageName)) {
-                       fireReceivedURIGenerated(new URIGenerated(fcpMessage));
+                       fcpListenerManager.fireReceivedURIGenerated(new URIGenerated(fcpMessage));
                } else if ("EndListPersistentRequests".equals(messageName)) {
-                       fireReceivedEndListPersistentRequests(new EndListPersistentRequests(fcpMessage));
+                       fcpListenerManager.fireReceivedEndListPersistentRequests(new EndListPersistentRequests(fcpMessage));
                } else if ("Peer".equals(messageName)) {
-                       fireReceivedPeer(new Peer(fcpMessage));
+                       fcpListenerManager.fireReceivedPeer(new Peer(fcpMessage));
                } else if ("PeerNote".equals(messageName)) {
-                       fireReceivedPeerNote(new PeerNote(fcpMessage));
+                       fcpListenerManager.fireReceivedPeerNote(new PeerNote(fcpMessage));
                } else if ("StartedCompression".equals(messageName)) {
-                       fireReceivedStartedCompression(new StartedCompression(fcpMessage));
+                       fcpListenerManager.fireReceivedStartedCompression(new StartedCompression(fcpMessage));
                } else if ("FinishedCompression".equals(messageName)) {
-                       fireReceivedFinishedCompression(new FinishedCompression(fcpMessage));
+                       fcpListenerManager.fireReceivedFinishedCompression(new FinishedCompression(fcpMessage));
                } else if ("GetFailed".equals(messageName)) {
-                       fireReceivedGetFailed(new GetFailed(fcpMessage));
+                       fcpListenerManager.fireReceivedGetFailed(new GetFailed(fcpMessage));
                } else if ("PutFetchable".equals(messageName)) {
-                       fireReceivedPutFetchable(new PutFetchable(fcpMessage));
+                       fcpListenerManager.fireReceivedPutFetchable(new PutFetchable(fcpMessage));
                } else if ("PutSuccessful".equals(messageName)) {
-                       fireReceivedPutSuccessful(new PutSuccessful(fcpMessage));
+                       fcpListenerManager.fireReceivedPutSuccessful(new PutSuccessful(fcpMessage));
                } else if ("PutFailed".equals(messageName)) {
-                       fireReceivedPutFailed(new PutFailed(fcpMessage));
+                       fcpListenerManager.fireReceivedPutFailed(new PutFailed(fcpMessage));
                } else if ("DataFound".equals(messageName)) {
-                       fireReceivedDataFound(new DataFound(fcpMessage));
+                       fcpListenerManager.fireReceivedDataFound(new DataFound(fcpMessage));
                } else if ("SubscribedUSKUpdate".equals(messageName)) {
-                       fireReceivedSubscribedUSKUpdate(new SubscribedUSKUpdate(fcpMessage));
+                       fcpListenerManager.fireReceivedSubscribedUSKUpdate(new SubscribedUSKUpdate(fcpMessage));
                } else if ("IdentifierCollision".equals(messageName)) {
-                       fireReceivedIdentifierCollision(new IdentifierCollision(fcpMessage));
+                       fcpListenerManager.fireReceivedIdentifierCollision(new IdentifierCollision(fcpMessage));
                } else if ("AllData".equals(messageName)) {
                        LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
-                       fireReceivedAllData(new AllData(fcpMessage, payloadInputStream));
+                       fcpListenerManager.fireReceivedAllData(new AllData(fcpMessage, payloadInputStream));
                        try {
                                payloadInputStream.consume();
                        } catch (IOException ioe1) {
                                /* well, ignore. when the connection handler fails, all fails. */
                        }
                } else if ("EndListPeerNotes".equals(messageName)) {
-                       fireReceivedEndListPeerNotes(new EndListPeerNotes(fcpMessage));
+                       fcpListenerManager.fireReceivedEndListPeerNotes(new EndListPeerNotes(fcpMessage));
                } else if ("EndListPeers".equals(messageName)) {
-                       fireReceivedEndListPeers(new EndListPeers(fcpMessage));
+                       fcpListenerManager.fireReceivedEndListPeers(new EndListPeers(fcpMessage));
                } else if ("SSKKeypair".equals(messageName)) {
-                       fireReceivedSSKKeypair(new SSKKeypair(fcpMessage));
+                       fcpListenerManager.fireReceivedSSKKeypair(new SSKKeypair(fcpMessage));
                } else if ("PeerRemoved".equals(messageName)) {
-                       fireReceivedPeerRemoved(new PeerRemoved(fcpMessage));
+                       fcpListenerManager.fireReceivedPeerRemoved(new PeerRemoved(fcpMessage));
                } else if ("PersistentRequestModified".equals(messageName)) {
-                       fireReceivedPersistentRequestModified(new PersistentRequestModified(fcpMessage));
+                       fcpListenerManager.fireReceivedPersistentRequestModified(new PersistentRequestModified(fcpMessage));
                } else if ("PersistentRequestRemoved".equals(messageName)) {
-                       fireReceivedPersistentRequestRemoved(new PersistentRequestRemoved(fcpMessage));
+                       fcpListenerManager.fireReceivedPersistentRequestRemoved(new PersistentRequestRemoved(fcpMessage));
                } else if ("UnknownPeerNoteType".equals(messageName)) {
-                       fireReceivedUnknownPeerNoteType(new UnknownPeerNoteType(fcpMessage));
+                       fcpListenerManager.fireReceivedUnknownPeerNoteType(new UnknownPeerNoteType(fcpMessage));
                } else if ("UnknownNodeIdentifier".equals(messageName)) {
-                       fireReceivedUnknownNodeIdentifier(new UnknownNodeIdentifier(fcpMessage));
+                       fcpListenerManager.fireReceivedUnknownNodeIdentifier(new UnknownNodeIdentifier(fcpMessage));
                } else if ("FCPPluginReply".equals(messageName)) {
                        LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
-                       fireReceivedFCPPluginReply(new FCPPluginReply(fcpMessage, payloadInputStream));
+                       fcpListenerManager.fireReceivedFCPPluginReply(new FCPPluginReply(fcpMessage, payloadInputStream));
                        try {
                                payloadInputStream.consume();
                        } catch (IOException ioe1) {
                                /* ignore. */
                        }
                } else if ("PluginInfo".equals(messageName)) {
-                       fireReceivedPluginInfo(new PluginInfo(fcpMessage));
+                       fcpListenerManager.fireReceivedPluginInfo(new PluginInfo(fcpMessage));
                } else if ("NodeData".equals(messageName)) {
-                       fireReceivedNodeData(new NodeData(fcpMessage));
+                       fcpListenerManager.fireReceivedNodeData(new NodeData(fcpMessage));
                } else if ("TestDDAReply".equals(messageName)) {
-                       fireReceivedTestDDAReply(new TestDDAReply(fcpMessage));
+                       fcpListenerManager.fireReceivedTestDDAReply(new TestDDAReply(fcpMessage));
                } else if ("TestDDAComplete".equals(messageName)) {
-                       fireReceivedTestDDAComplete(new TestDDAComplete(fcpMessage));
+                       fcpListenerManager.fireReceivedTestDDAComplete(new TestDDAComplete(fcpMessage));
                } else if ("ConfigData".equals(messageName)) {
-                       fireReceivedConfigData(new ConfigData(fcpMessage));
+                       fcpListenerManager.fireReceivedConfigData(new ConfigData(fcpMessage));
                } else if ("NodeHello".equals(messageName)) {
-                       fireReceivedNodeHello(new NodeHello(fcpMessage));
+                       fcpListenerManager.fireReceivedNodeHello(new NodeHello(fcpMessage));
                } else if ("CloseConnectionDuplicateClientName".equals(messageName)) {
-                       fireReceivedCloseConnectionDuplicateClientName(new CloseConnectionDuplicateClientName(fcpMessage));
+                       fcpListenerManager.fireReceivedCloseConnectionDuplicateClientName(new CloseConnectionDuplicateClientName(fcpMessage));
                } else {
-                       fireMessageReceived(fcpMessage);
+                       fcpListenerManager.fireMessageReceived(fcpMessage);
                }
        }
 
        /**
         * Handles a disconnect from the node.
-        * 
+        *
         * @param throwable
         *            The exception that caused the disconnect, or <code>null</code>
         *            if there was no exception
@@ -830,7 +328,7 @@ public class FcpConnection implements Closeable {
                if (connectionHandler != null) {
                        connectionHandler.stop();
                        connectionHandler = null;
-                       fireConnectionClosed(throwable);
+                       fcpListenerManager.fireConnectionClosed(throwable);
                }
        }
 
@@ -841,7 +339,7 @@ public class FcpConnection implements Closeable {
        /**
         * Incremets the counter in {@link #incomingMessageStatistics} by <cod>1</code>
         * for the given message name.
-        * 
+        *
         * @param name
         *            The name of the message to count
         */
@@ -856,7 +354,7 @@ public class FcpConnection implements Closeable {
 
        /**
         * Returns a limited input stream from the node’s input stream.
-        * 
+        *
         * @param dataLength
         *            The length of the stream
         * @return The limited input stream
@@ -871,7 +369,7 @@ public class FcpConnection implements Closeable {
        /**
         * A wrapper around an {@link InputStream} that only supplies a limit number
         * of bytes from the underlying input stream.
-        * 
+        *
         * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
         */
        private static class LimitedInputStream extends FilterInputStream {
@@ -882,7 +380,7 @@ public class FcpConnection implements Closeable {
                /**
                 * Creates a new LimitedInputStream that supplies at most
                 * <code>length</code> bytes from the given input stream.
-                * 
+                *
                 * @param inputStream
                 *            The input stream
                 * @param length
@@ -947,7 +445,7 @@ public class FcpConnection implements Closeable {
                /**
                 * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
                 * {@link #reset()} are not supported.
-                * 
+                *
                 * @see java.io.FilterInputStream#mark(int)
                 */
                @Override
@@ -957,7 +455,7 @@ public class FcpConnection implements Closeable {
 
                /**
                 * {@inheritDoc}
-                * 
+                *
                 * @see java.io.FilterInputStream#markSupported()
                 * @return <code>false</code>
                 */
@@ -969,7 +467,7 @@ public class FcpConnection implements Closeable {
                /**
                 * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
                 * {@link #reset()} are not supported.
-                * 
+                *
                 * @see java.io.FilterInputStream#reset()
                 */
                @Override
@@ -980,7 +478,7 @@ public class FcpConnection implements Closeable {
                /**
                 * Consumes the input stream, i.e. read all bytes until the limit is
                 * reached.
-                * 
+                *
                 * @throws IOException
                 *             if an I/O error occurs
                 */