aboutsummaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-08-24 19:57:00 +0200
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-10-28 22:33:31 +0100
commit518995debd939233c8b275d38dc6df735bf2ec40 (patch)
tree7c0913a4bae96587ac67713909bf330598b24186 /src/net
parent2b5dd43aaac91e0d33a60c4b28f5a65bb3b06e38 (diff)
downloadjitsi-518995debd939233c8b275d38dc6df735bf2ec40.zip
jitsi-518995debd939233c8b275d38dc6df735bf2ec40.tar.gz
jitsi-518995debd939233c8b275d38dc6df735bf2ec40.tar.bz2
IRC: some refactoring of connect methods.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java144
1 files changed, 71 insertions, 73 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java
index 95a5e14..4845dd9 100644
--- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java
+++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java
@@ -263,13 +263,41 @@ public class IrcStack
irc.addListener(new DebugListener());
}
- connectSynchronized();
+ try
+ {
+ connectSynchronized();
+
+ // instantiate presence manager for the connection
+ this.presence =
+ new PresenceManager(irc, this.connectionState,
+ this.provider.getPersistentPresence());
+
+ queryIdentity();
- queryIdentity();
+ // if connecting succeeded, set state to registered
+ this.provider
+ .setCurrentRegistrationState(RegistrationState.REGISTERED);
- // TODO Read IRC network capabilities based on RPL_ISUPPORT (005)
- // replies if available. This information should be available in
- // irc-api if possible.
+ // TODO Read IRC network capabilities based on RPL_ISUPPORT
+ // (005)
+ // replies if available. This information should be available in
+ // irc-api if possible.
+ }
+ catch (IOException e)
+ {
+ // Also SSL exceptions will be caught here.
+ this.provider
+ .setCurrentRegistrationState(
+ RegistrationState.CONNECTION_FAILED);
+ throw e;
+ }
+ catch (InterruptedException e)
+ {
+ this.provider
+ .setCurrentRegistrationState(
+ RegistrationState.UNREGISTERED);
+ throw e;
+ }
}
}
@@ -291,88 +319,57 @@ public class IrcStack
synchronized (result)
{
// start connecting to the specified server ...
- try
+ irc.connect(this.params, new Callback<IIRCState>()
{
- irc.connect(this.params, new Callback<IIRCState>()
- {
-
- @Override
- public void onSuccess(final IIRCState state)
- {
- synchronized (result)
- {
- LOGGER.trace("IRC connected successfully!");
- result.setDone(state);
- result.notifyAll();
- }
- }
- @Override
- public void onFailure(final Exception e)
+ @Override
+ public void onSuccess(final IIRCState state)
+ {
+ synchronized (result)
{
- synchronized (result)
- {
- LOGGER.trace("IRC connection FAILED!", e);
- result.setDone(e);
- result.notifyAll();
- }
+ LOGGER.trace("IRC connected successfully!");
+ result.setDone(state);
+ result.notifyAll();
}
- });
-
- this.provider
- .setCurrentRegistrationState(RegistrationState.REGISTERING);
-
- while (!result.isDone())
- {
- LOGGER.trace("Waiting for the connection to be "
- + "established ...");
- result.wait();
}
- this.connectionState = result.getValue();
- // TODO Implement connection timeout and a way to recognize that
- // the timeout occurred.
- if (this.connectionState != null
- && this.connectionState.isConnected())
- {
- // instantiate presence manager for the connection
- this.presence =
- new PresenceManager(irc, this.connectionState,
- this.provider.getPersistentPresence());
-
- // if connecting succeeded, set state to registered
- this.provider.setCurrentRegistrationState(
- RegistrationState.REGISTERED);
- }
- else
+ @Override
+ public void onFailure(final Exception e)
{
- // if connecting failed, set state to unregistered and throw
- // the exception if one exists
- this.provider
- .setCurrentRegistrationState(
- RegistrationState.CONNECTION_FAILED);
- Exception e = result.getException();
- if (e != null)
+ synchronized (result)
{
- throw e;
+ LOGGER.trace("IRC connection FAILED!", e);
+ result.setDone(e);
+ result.notifyAll();
}
}
- }
- catch (IOException e)
+ });
+
+ this.provider
+ .setCurrentRegistrationState(RegistrationState.REGISTERING);
+
+ while (!result.isDone())
{
- // Also SSL exceptions will be caught here.
- this.provider
- .setCurrentRegistrationState(
- RegistrationState.CONNECTION_FAILED);
- throw e;
+ LOGGER.trace("Waiting for the connection to be "
+ + "established ...");
+ result.wait();
}
- catch (InterruptedException e)
+
+ // TODO Implement connection timeout and a way to recognize that
+ // the timeout occurred.
+
+ final Exception e = result.getException();
+ if (e != null)
{
- this.provider
- .setCurrentRegistrationState(
- RegistrationState.UNREGISTERED);
- throw e;
+ throw new IOException(e);
}
+
+ final IIRCState connectionState = result.getValue();
+ if (connectionState == null) {
+ throw new IOException("Failed to connect: no connection state available.");
+ }
+
+ this.connectionState = connectionState;
}
}
@@ -381,6 +378,7 @@ public class IrcStack
*/
private void queryIdentity()
{
+ // TODO Install temporary whois listener that handles the result.
this.session.get().rawMessage(
"WHOIS " + this.connectionState.getNickname());
}