import net.pterodactylus.fcp.FcpListener;
import net.pterodactylus.fcp.GenerateSSK;
import net.pterodactylus.fcp.GetFailed;
+import net.pterodactylus.fcp.GetNode;
import net.pterodactylus.fcp.ListPeerNotes;
import net.pterodactylus.fcp.ListPeers;
import net.pterodactylus.fcp.ListPersistentRequests;
import net.pterodactylus.fcp.ModifyPeer;
import net.pterodactylus.fcp.ModifyPeerNote;
+import net.pterodactylus.fcp.NodeData;
import net.pterodactylus.fcp.NodeHello;
import net.pterodactylus.fcp.NodeRef;
import net.pterodactylus.fcp.Peer;
/** Object used for synchronization. */
private final Object syncObject = new Object();
+ /** Listener management. */
+ private final FcpClientListenerManager fcpClientListenerManager = new FcpClientListenerManager(this);
+
/** The name of this client. */
private final String name;
public FcpClient(String name, InetAddress host, int port) {
this.name = name;
fcpConnection = new FcpConnection(host, port);
+ fcpConnection.addFcpListener(new FcpAdapter() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
+ fcpClientListenerManager.fireFcpClientDisconnected();
+ }
+ });
+ }
+
+ //
+ // LISTENER MANAGEMENT
+ //
+
+ /**
+ * Adds an FCP client listener to the list of registered listeners.
+ *
+ * @param fcpClientListener
+ * The FCP client listener to add
+ */
+ public void addFcpClientListener(FcpClientListener fcpClientListener) {
+ fcpClientListenerManager.addListener(fcpClientListener);
+ }
+
+ /**
+ * Removes an FCP client listener from the list of registered listeners.
+ *
+ * @param fcpClientListener
+ * The FCP client listener to remove
+ */
+ public void removeFcpClientListener(FcpClientListener fcpClientListener) {
+ fcpClientListenerManager.removeListener(fcpClientListener);
}
//
}
//
+ // NODE INFORMATION
+ //
+
+ /**
+ * Returns information about the node.
+ *
+ * @param giveOpennetRef
+ * Whether to return the OpenNet reference
+ * @param withPrivate
+ * Whether to return private node data
+ * @param withVolatile
+ * Whether to return volatile node data
+ * @return Node information
+ * @throws FcpException
+ * if an FCP error occurs
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public NodeData getNodeInformation(final Boolean giveOpennetRef, final Boolean withPrivate, final Boolean withVolatile) throws IOException, FcpException {
+ final ObjectWrapper<NodeData> nodeDataWrapper = new ObjectWrapper<NodeData>();
+ new ExtendedFcpAdapter() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() throws IOException {
+ GetNode getNodeMessage = new GetNode(giveOpennetRef, withPrivate, withVolatile);
+ fcpConnection.sendMessage(getNodeMessage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
+ nodeDataWrapper.set(nodeData);
+ completionLatch.countDown();
+ }
+ }.execute();
+ return nodeDataWrapper.get();
+ }
+
+ //
// PRIVATE METHODS
//