From ccd328332da86e58a98e991c3d4e31e56e906547 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 15 Jan 2010 12:04:55 +0100 Subject: [PATCH] Add possibility to simply wrap a high-level client around an FCP connection. --- .../net/pterodactylus/fcp/highlevel/FcpClient.java | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java index 7399818..b738e26 100644 --- a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -147,7 +147,32 @@ public class FcpClient { * The Freenet node’s FCP port */ public FcpClient(InetAddress host, int port) { - fcpConnection = new FcpConnection(host, port); + this(new FcpConnection(host, port)); + } + + /** + * Creates a new high-level FCP client that will use the given connection. + * This constructor will assume that the FCP connection is already + * connected. + * + * @param fcpConnection + * The FCP connection to use + */ + public FcpClient(FcpConnection fcpConnection) { + this(fcpConnection, true); + } + + /** + * Creates a new high-level FCP client that will use the given connection. + * + * @param fcpConnection + * The FCP connection to use + * @param connected + * The initial status of the FCP connection + */ + public FcpClient(FcpConnection fcpConnection, boolean connected) { + this.fcpConnection = fcpConnection; + this.connected = connected; fcpConnection.addFcpListener(new FcpAdapter() { /** @@ -156,7 +181,7 @@ public class FcpClient { @Override @SuppressWarnings("synthetic-access") public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) { - connected = false; + FcpClient.this.connected = false; fcpClientListenerManager.fireFcpClientDisconnected(); } }); -- 2.7.4