2 * jFCPlib - FcpListenerManager.java -
3 * Copyright © 2009 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.fcp;
22 import java.util.List;
23 import java.util.concurrent.CopyOnWriteArrayList;
26 * Manages FCP listeners and event firing.
28 * @author David ‘Bombe’ Roden <bombe@pterodactylus.net>
30 public class FcpListenerManager {
32 /** The source FCP connection. */
33 private final FcpConnection fcpConnection;
35 /** The registered listeners. */
36 private final List<FcpListener> fcpListeners = new CopyOnWriteArrayList<FcpListener>();
39 * Creates a new listener manager.
41 * @param fcpConnection
42 * The source FCP connection
44 public FcpListenerManager(FcpConnection fcpConnection) {
45 this.fcpConnection = fcpConnection;
49 * Adds the given FCP listener to the list of registered listeners.
52 * The FCP listener to add
54 public void addListener(FcpListener fcpListener) {
55 fcpListeners.add(fcpListener);
59 * Removes the given FCP listener from the list of registered listeners.
62 * The FCP listener to remove
64 public void removeListener(FcpListener fcpListener) {
65 fcpListeners.remove(fcpListener);
69 * Notifies listeners that a “NodeHello” message was received.
71 * @see FcpListener#receivedNodeHello(FcpConnection, NodeHello)
73 * The “NodeHello” message
75 public void fireReceivedNodeHello(NodeHello nodeHello) {
76 for (FcpListener fcpListener : fcpListeners) {
77 fcpListener.receivedNodeHello(fcpConnection, nodeHello);
82 * Notifies listeners that a “CloseConnectionDuplicateClientName” message
85 * @see FcpListener#receivedCloseConnectionDuplicateClientName(FcpConnection,
86 * CloseConnectionDuplicateClientName)
87 * @param closeConnectionDuplicateClientName
88 * The “CloseConnectionDuplicateClientName” message
90 public void fireReceivedCloseConnectionDuplicateClientName(CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
91 for (FcpListener fcpListener : fcpListeners) {
92 fcpListener.receivedCloseConnectionDuplicateClientName(fcpConnection, closeConnectionDuplicateClientName);
97 * Notifies listeners that a “SSKKeypair” message was received.
99 * @see FcpListener#receivedSSKKeypair(FcpConnection, SSKKeypair)
101 * The “SSKKeypair” message
103 public void fireReceivedSSKKeypair(SSKKeypair sskKeypair) {
104 for (FcpListener fcpListener : fcpListeners) {
105 fcpListener.receivedSSKKeypair(fcpConnection, sskKeypair);
110 * Notifies listeners that a “Peer” message was received.
112 * @see FcpListener#receivedPeer(FcpConnection, Peer)
116 public void fireReceivedPeer(Peer peer) {
117 for (FcpListener fcpListener : fcpListeners) {
118 fcpListener.receivedPeer(fcpConnection, peer);
123 * Notifies all listeners that an “EndListPeers” message was received.
125 * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers)
126 * @param endListPeers
127 * The “EndListPeers” message
129 public void fireReceivedEndListPeers(EndListPeers endListPeers) {
130 for (FcpListener fcpListener : fcpListeners) {
131 fcpListener.receivedEndListPeers(fcpConnection, endListPeers);
136 * Notifies all listeners that a “PeerNote” message was received.
138 * @see FcpListener#receivedPeerNote(FcpConnection, PeerNote)
141 public void fireReceivedPeerNote(PeerNote peerNote) {
142 for (FcpListener fcpListener : fcpListeners) {
143 fcpListener.receivedPeerNote(fcpConnection, peerNote);
148 * Notifies all listeners that an “EndListPeerNotes” message was received.
150 * @see FcpListener#receivedEndListPeerNotes(FcpConnection,
152 * @param endListPeerNotes
153 * The “EndListPeerNotes” message
155 public void fireReceivedEndListPeerNotes(EndListPeerNotes endListPeerNotes) {
156 for (FcpListener fcpListener : fcpListeners) {
157 fcpListener.receivedEndListPeerNotes(fcpConnection, endListPeerNotes);
162 * Notifies all listeners that a “PeerRemoved” message was received.
164 * @see FcpListener#receivedPeerRemoved(FcpConnection, PeerRemoved)
166 * The “PeerRemoved” message
168 public void fireReceivedPeerRemoved(PeerRemoved peerRemoved) {
169 for (FcpListener fcpListener : fcpListeners) {
170 fcpListener.receivedPeerRemoved(fcpConnection, peerRemoved);
175 * Notifies all listeners that a “NodeData” message was received.
177 * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
179 * The “NodeData” message
181 public void fireReceivedNodeData(NodeData nodeData) {
182 for (FcpListener fcpListener : fcpListeners) {
183 fcpListener.receivedNodeData(fcpConnection, nodeData);
188 * Notifies all listeners that a “TestDDAReply” message was received.
190 * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
191 * @param testDDAReply
192 * The “TestDDAReply” message
194 public void fireReceivedTestDDAReply(TestDDAReply testDDAReply) {
195 for (FcpListener fcpListener : fcpListeners) {
196 fcpListener.receivedTestDDAReply(fcpConnection, testDDAReply);
201 * Notifies all listeners that a “TestDDAComplete” message was received.
203 * @see FcpListener#receivedTestDDAComplete(FcpConnection, TestDDAComplete)
204 * @param testDDAComplete
205 * The “TestDDAComplete” message
207 public void fireReceivedTestDDAComplete(TestDDAComplete testDDAComplete) {
208 for (FcpListener fcpListener : fcpListeners) {
209 fcpListener.receivedTestDDAComplete(fcpConnection, testDDAComplete);
214 * Notifies all listeners that a “PersistentGet” message was received.
216 * @see FcpListener#receivedPersistentGet(FcpConnection, PersistentGet)
217 * @param persistentGet
218 * The “PersistentGet” message
220 public void fireReceivedPersistentGet(PersistentGet persistentGet) {
221 for (FcpListener fcpListener : fcpListeners) {
222 fcpListener.receivedPersistentGet(fcpConnection, persistentGet);
227 * Notifies all listeners that a “PersistentPut” message was received.
229 * @see FcpListener#receivedPersistentPut(FcpConnection, PersistentPut)
230 * @param persistentPut
231 * The “PersistentPut” message
233 public void fireReceivedPersistentPut(PersistentPut persistentPut) {
234 for (FcpListener fcpListener : fcpListeners) {
235 fcpListener.receivedPersistentPut(fcpConnection, persistentPut);
240 * Notifies all listeners that a “EndListPersistentRequests” message was
243 * @see FcpListener#receivedEndListPersistentRequests(FcpConnection,
244 * EndListPersistentRequests)
245 * @param endListPersistentRequests
246 * The “EndListPersistentRequests” message
248 public void fireReceivedEndListPersistentRequests(EndListPersistentRequests endListPersistentRequests) {
249 for (FcpListener fcpListener : fcpListeners) {
250 fcpListener.receivedEndListPersistentRequests(fcpConnection, endListPersistentRequests);
255 * Notifies all listeners that a “URIGenerated” message was received.
257 * @see FcpListener#receivedURIGenerated(FcpConnection, URIGenerated)
258 * @param uriGenerated
259 * The “URIGenerated” message
261 public void fireReceivedURIGenerated(URIGenerated uriGenerated) {
262 for (FcpListener fcpListener : fcpListeners) {
263 fcpListener.receivedURIGenerated(fcpConnection, uriGenerated);
268 * Notifies all listeners that a “DataFound” message was received.
270 * @see FcpListener#receivedDataFound(FcpConnection, DataFound)
272 * The “DataFound” message
274 public void fireReceivedDataFound(DataFound dataFound) {
275 for (FcpListener fcpListener : fcpListeners) {
276 fcpListener.receivedDataFound(fcpConnection, dataFound);
281 * Notifies all listeners that an “AllData” message was received.
283 * @see FcpListener#receivedAllData(FcpConnection, AllData)
285 * The “AllData” message
287 public void fireReceivedAllData(AllData allData) {
288 for (FcpListener fcpListener : fcpListeners) {
289 fcpListener.receivedAllData(fcpConnection, allData);
294 * Notifies all listeners that a “SimpleProgress” message was received.
296 * @see FcpListener#receivedSimpleProgress(FcpConnection, SimpleProgress)
297 * @param simpleProgress
298 * The “SimpleProgress” message
300 public void fireReceivedSimpleProgress(SimpleProgress simpleProgress) {
301 for (FcpListener fcpListener : fcpListeners) {
302 fcpListener.receivedSimpleProgress(fcpConnection, simpleProgress);
307 * Notifies all listeners that a “StartedCompression” message was received.
309 * @see FcpListener#receivedStartedCompression(FcpConnection,
310 * StartedCompression)
311 * @param startedCompression
312 * The “StartedCompression” message
314 public void fireReceivedStartedCompression(StartedCompression startedCompression) {
315 for (FcpListener fcpListener : fcpListeners) {
316 fcpListener.receivedStartedCompression(fcpConnection, startedCompression);
321 * Notifies all listeners that a “FinishedCompression” message was received.
323 * @see FcpListener#receviedFinishedCompression(FcpConnection,
324 * FinishedCompression)
325 * @param finishedCompression
326 * The “FinishedCompression” message
328 public void fireReceivedFinishedCompression(FinishedCompression finishedCompression) {
329 for (FcpListener fcpListener : fcpListeners) {
330 fcpListener.receviedFinishedCompression(fcpConnection, finishedCompression);
335 * Notifies all listeners that an “UnknownPeerNoteType” message was
338 * @see FcpListener#receivedUnknownPeerNoteType(FcpConnection,
339 * UnknownPeerNoteType)
340 * @param unknownPeerNoteType
341 * The “UnknownPeerNoteType” message
343 public void fireReceivedUnknownPeerNoteType(UnknownPeerNoteType unknownPeerNoteType) {
344 for (FcpListener fcpListener : fcpListeners) {
345 fcpListener.receivedUnknownPeerNoteType(fcpConnection, unknownPeerNoteType);
350 * Notifies all listeners that an “UnknownNodeIdentifier” message was
353 * @see FcpListener#receivedUnknownNodeIdentifier(FcpConnection,
354 * UnknownNodeIdentifier)
355 * @param unknownNodeIdentifier
356 * The “UnknownNodeIdentifier” message
358 public void fireReceivedUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
359 for (FcpListener fcpListener : fcpListeners) {
360 fcpListener.receivedUnknownNodeIdentifier(fcpConnection, unknownNodeIdentifier);
365 * Notifies all listeners that a “ConfigData” message was received.
367 * @see FcpListener#receivedConfigData(FcpConnection, ConfigData)
369 * The “ConfigData” message
371 public void fireReceivedConfigData(ConfigData configData) {
372 for (FcpListener fcpListener : fcpListeners) {
373 fcpListener.receivedConfigData(fcpConnection, configData);
378 * Notifies all listeners that a “GetFailed” message was received.
380 * @see FcpListener#receivedGetFailed(FcpConnection, GetFailed)
382 * The “GetFailed” message
384 public void fireReceivedGetFailed(GetFailed getFailed) {
385 for (FcpListener fcpListener : fcpListeners) {
386 fcpListener.receivedGetFailed(fcpConnection, getFailed);
391 * Notifies all listeners that a “PutFailed” message was received.
393 * @see FcpListener#receivedPutFailed(FcpConnection, PutFailed)
395 * The “PutFailed” message
397 public void fireReceivedPutFailed(PutFailed putFailed) {
398 for (FcpListener fcpListener : fcpListeners) {
399 fcpListener.receivedPutFailed(fcpConnection, putFailed);
404 * Notifies all listeners that an “IdentifierCollision” message was
407 * @see FcpListener#receivedIdentifierCollision(FcpConnection,
408 * IdentifierCollision)
409 * @param identifierCollision
410 * The “IdentifierCollision” message
412 public void fireReceivedIdentifierCollision(IdentifierCollision identifierCollision) {
413 for (FcpListener fcpListener : fcpListeners) {
414 fcpListener.receivedIdentifierCollision(fcpConnection, identifierCollision);
419 * Notifies all listeners that an “PersistentPutDir” message was received.
421 * @see FcpListener#receivedPersistentPutDir(FcpConnection,
423 * @param persistentPutDir
424 * The “PersistentPutDir” message
426 public void fireReceivedPersistentPutDir(PersistentPutDir persistentPutDir) {
427 for (FcpListener fcpListener : fcpListeners) {
428 fcpListener.receivedPersistentPutDir(fcpConnection, persistentPutDir);
433 * Notifies all listeners that a “PersistentRequestRemoved” message was
436 * @see FcpListener#receivedPersistentRequestRemoved(FcpConnection,
437 * PersistentRequestRemoved)
438 * @param persistentRequestRemoved
439 * The “PersistentRequestRemoved” message
441 public void fireReceivedPersistentRequestRemoved(PersistentRequestRemoved persistentRequestRemoved) {
442 for (FcpListener fcpListener : fcpListeners) {
443 fcpListener.receivedPersistentRequestRemoved(fcpConnection, persistentRequestRemoved);
448 * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
450 * @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
451 * SubscribedUSKUpdate)
452 * @param subscribedUSKUpdate
453 * The “SubscribedUSKUpdate” message
455 public void fireReceivedSubscribedUSKUpdate(SubscribedUSKUpdate subscribedUSKUpdate) {
456 for (FcpListener fcpListener : fcpListeners) {
457 fcpListener.receivedSubscribedUSKUpdate(fcpConnection, subscribedUSKUpdate);
462 * Notifies all listeners that a “PluginInfo” message was received.
464 * @see FcpListener#receivedPluginInfo(FcpConnection, PluginInfo)
466 * The “PluginInfo” message
468 public void fireReceivedPluginInfo(PluginInfo pluginInfo) {
469 for (FcpListener fcpListener : fcpListeners) {
470 fcpListener.receivedPluginInfo(fcpConnection, pluginInfo);
475 * Notifies all listeners that an “FCPPluginReply” message was received.
477 * @see FcpListener#receivedFCPPluginReply(FcpConnection, FCPPluginReply)
478 * @param fcpPluginReply
479 * The “FCPPluginReply” message
481 public void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
482 for (FcpListener fcpListener : fcpListeners) {
483 fcpListener.receivedFCPPluginReply(fcpConnection, fcpPluginReply);
488 * Notifies all listeners that a “PersistentRequestModified” message was
491 * @see FcpListener#receivedPersistentRequestModified(FcpConnection,
492 * PersistentRequestModified)
493 * @param persistentRequestModified
494 * The “PersistentRequestModified” message
496 public void fireReceivedPersistentRequestModified(PersistentRequestModified persistentRequestModified) {
497 for (FcpListener fcpListener : fcpListeners) {
498 fcpListener.receivedPersistentRequestModified(fcpConnection, persistentRequestModified);
503 * Notifies all listeners that a “PutSuccessful” message was received.
505 * @see FcpListener#receivedPutSuccessful(FcpConnection, PutSuccessful)
506 * @param putSuccessful
507 * The “PutSuccessful” message
509 public void fireReceivedPutSuccessful(PutSuccessful putSuccessful) {
510 for (FcpListener fcpListener : fcpListeners) {
511 fcpListener.receivedPutSuccessful(fcpConnection, putSuccessful);
516 * Notifies all listeners that a “PutFetchable” message was received.
518 * @see FcpListener#receivedPutFetchable(FcpConnection, PutFetchable)
519 * @param putFetchable
520 * The “PutFetchable” message
522 public void fireReceivedPutFetchable(PutFetchable putFetchable) {
523 for (FcpListener fcpListener : fcpListeners) {
524 fcpListener.receivedPutFetchable(fcpConnection, putFetchable);
529 * Notifies all listeners that a “ProtocolError” message was received.
531 * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError)
532 * @param protocolError
533 * The “ProtocolError” message
535 public void fireReceivedProtocolError(ProtocolError protocolError) {
536 for (FcpListener fcpListener : fcpListeners) {
537 fcpListener.receivedProtocolError(fcpConnection, protocolError);
542 * Notifies all registered listeners that a message has been received.
544 * @see FcpListener#receivedMessage(FcpConnection, FcpMessage)
546 * The message that was received
548 public void fireMessageReceived(FcpMessage fcpMessage) {
549 for (FcpListener fcpListener : fcpListeners) {
550 fcpListener.receivedMessage(fcpConnection, fcpMessage);
555 * Notifies all listeners that the connection to the node was closed.
558 * The exception that caused the disconnect, or <code>null</code>
559 * if there was no exception
560 * @see FcpListener#connectionClosed(FcpConnection, Throwable)
562 public void fireConnectionClosed(Throwable throwable) {
563 for (FcpListener fcpListener : fcpListeners) {
564 fcpListener.connectionClosed(fcpConnection, throwable);