From aca69685f3104359aca1474d96d632b9ef09f2be Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Apr 2013 12:15:02 +0200 Subject: [PATCH] Expose whether the connection is established. --- src/main/java/net/pterodactylus/irc/Connection.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 10edc3c..88059ba 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -115,6 +115,9 @@ public class Connection extends AbstractExecutionThreadService implements Servic /** The connection handler. */ private ConnectionHandler connectionHandler; + /** Whether the connection has already been established. */ + private boolean established; + /** * Creates a new connection. * @@ -139,6 +142,16 @@ public class Connection extends AbstractExecutionThreadService implements Servic // /** + * Returns whether this connection has already been established. + * + * @return {@code true} as long as this connection is established, {@code + * false} otherwise + */ + public boolean established() { + return established; + } + + /** * Returns the nickname that is currently in use by this connection. The * nickname is only available once the connection has been {@link #start()}ed. * @@ -447,6 +460,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic if ((connectionStatus == 0x0f) && (connectionStatus != oldConnectionStatus)) { /* connection succeeded! */ + established = true; eventBus.post(new ConnectionEstablished(this)); } oldConnectionStatus = connectionStatus; @@ -456,6 +470,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic logger.log(Level.WARNING, "I/O error", ioe1); eventBus.post(new ConnectionClosed(this, ioe1)); } finally { + established = false; logger.info("Closing Connection."); try { Closeables.close(connectionHandler, true); -- 2.7.4