From: David ‘Bombe’ Roden Date: Sun, 14 Apr 2013 10:15:02 +0000 (+0200) Subject: Expose whether the connection is established. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=aca69685f3104359aca1474d96d632b9ef09f2be;p=xudocci.git Expose whether the connection is established. --- 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);