import java.net.InetAddress;
import java.net.URL;
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.Map.Entry;
import java.util.logging.Logger;
/** The FCP connection to the node. */
private FcpConnection fcpConnection;
+ /** Listeners for high-level client events. */
+ private List<HighLevelClientListener> highLevelClientListeners = Collections.synchronizedList(new ArrayList<HighLevelClientListener>());
+
/** The listener for the connection. */
private HighLevelClientFcpListener highLevelClientFcpListener = new HighLevelClientFcpListener();
}
//
+ // EVENT MANAGEMENT
+ //
+
+ /**
+ * Adds the given high-level client listener to list of listeners.
+ *
+ * @param highLevelClientListener
+ * The listener to add
+ */
+ public void addHighLevelClientListener(HighLevelClientListener highLevelClientListener) {
+ highLevelClientListeners.add(highLevelClientListener);
+ }
+
+ /**
+ * Removes the given high-level client listener from the list of listeners.
+ *
+ * @param highLevelClientListener
+ * The listener to remove
+ */
+ public void removeHighLevelClientListener(HighLevelClientListener highLevelClientListener) {
+ highLevelClientListeners.remove(highLevelClientListener);
+ }
+
+ /**
+ * Notifies all listeners that a client has connected.
+ */
+ private void fireClientConnected() {
+ for (HighLevelClientListener highLevelClientListener: highLevelClientListeners) {
+ highLevelClientListener.clientConnected(this);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a client has disconnected.
+ */
+ private void fireClientDisconnected() {
+ for (HighLevelClientListener highLevelClientListener: highLevelClientListeners) {
+ highLevelClientListener.clientDisconnected(this);
+ }
+ }
+
+ //
// ACCESSORS
//
*/
public void disconnect() {
fcpConnection.close();
+ fireClientDisconnected();
}
/**
connectCallback.setDone();
connectCallback = null;
}
+ fireClientConnected();
}
/**
--- /dev/null
+/*
+ * jFCPlib-high-level-client - HighLevelClientListener.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.fcp.highlevel;
+
+import java.util.EventListener;
+
+/**
+ * Interface for objects that want to be notified on certain high-level client
+ * events.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public interface HighLevelClientListener extends EventListener {
+
+ /**
+ * Notifies a listener that the given high-level client was connected to the
+ * node.
+ *
+ * @param highLevelClient
+ * The client that was connected
+ */
+ public void clientConnected(HighLevelClient highLevelClient);
+
+ /**
+ * Notifies a listener that the given client was disconnected from the node.
+ *
+ * @param highLevelClient
+ * The client that was disconnected
+ */
+ public void clientDisconnected(HighLevelClient highLevelClient);
+
+}