Throw exception after failed attempt to connect to IRC server.

fix-message-formatting
Danny van Heumen 12 years ago
parent 5b21c014e4
commit f51718d0a5

@ -95,12 +95,15 @@ public boolean isSecureConnection()
}
public void connect(String host, int port, String password,
boolean autoNickChange)
boolean autoNickChange) throws Exception
{
if (this.irc != null && this.connectionState != null
&& this.connectionState.isConnected())
return;
//A container for storing the exception if connecting fails.
final Exception[] exceptionContainer = new Exception[1];
this.irc = new IRCApiImpl(true);
this.params.setServer(new IRCServer(host, port, password, false));
synchronized (this.irc)
@ -146,6 +149,7 @@ public void onFailure(Exception e)
{
System.out.println("IRC connection FAILED!");
e.printStackTrace();
exceptionContainer[0] = e;
IrcStack.this.connectionState = null;
IrcStack.this.disconnect();
IrcStack.this.irc.notifyAll();
@ -166,36 +170,40 @@ public void onFailure(Exception e)
}
else
{
// TODO Get reason from other thread.
this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
if (exceptionContainer[0] != null) {
// If an exception happens to be available that explains
// the connection problem, throw it.
throw exceptionContainer[0];
}
}
}
catch (InterruptedException e)
{
this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
}
}
}
public void disconnect()
{
if (this.connectionState != null)
if (this.connectionState == null && this.irc == null)
return;
for (String channel : this.joined.keySet())
{
for (String channel : this.joined.keySet())
{
leave(channel);
}
this.joined.clear();
this.irc.disconnect();
this.irc = null;
this.connectionState = null;
this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
leave(channel);
}
this.joined.clear();
this.irc.disconnect();
this.irc = null;
this.connectionState = null;
this.provider
.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
}
public void dispose()

@ -218,10 +218,15 @@ public void register(SecurityAuthority authority)
}
}
this.ircStack.connect( serverAddress,
serverPort,
serverPassword,
autoNickChange);
try
{
this.ircStack.connect(serverAddress, serverPort, serverPassword,
autoNickChange);
}
catch (Exception e)
{
throw new OperationFailedException(e.getMessage(), 0, e);
}
}
/**

Loading…
Cancel
Save