Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-01-15 07:11:56 +0000
committerslewis2007-01-15 07:11:56 +0000
commitd96ad61d94cfe4a0d4555c0563509e05755f9643 (patch)
tree1bbc1843e834e5f55b18810482b12742561d57ed /providers/bundles/org.eclipse.ecf.provider.irc
parent0f7de698b96092f8387c586c1d8f8a9a4bde216c (diff)
downloadorg.eclipse.ecf-d96ad61d94cfe4a0d4555c0563509e05755f9643.tar.gz
org.eclipse.ecf-d96ad61d94cfe4a0d4555c0563509e05755f9643.tar.xz
org.eclipse.ecf-d96ad61d94cfe4a0d4555c0563509e05755f9643.zip
Added code so that IRCRootContainer.connect call is blocking until registration message is received
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.irc')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc/src/org/eclipse/ecf/provider/irc/container/IRCRootContainer.java59
1 files changed, 51 insertions, 8 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc/src/org/eclipse/ecf/provider/irc/container/IRCRootContainer.java b/providers/bundles/org.eclipse.ecf.provider.irc/src/org/eclipse/ecf/provider/irc/container/IRCRootContainer.java
index 6bcfdbec2..92e9e6c4c 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc/src/org/eclipse/ecf/provider/irc/container/IRCRootContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.irc/src/org/eclipse/ecf/provider/irc/container/IRCRootContainer.java
@@ -10,7 +10,6 @@
******************************************************************************/
package org.eclipse.ecf.provider.irc.container;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -28,6 +27,7 @@ import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.core.util.TimeoutException;
import org.eclipse.ecf.internal.provider.irc.Activator;
import org.eclipse.ecf.presence.chatroom.ChatRoomCreateException;
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
@@ -54,6 +54,8 @@ public class IRCRootContainer extends IRCAbstractContainer implements
IContainer, IChatRoomManager, IChatRoomContainer, IRCMessageChannel,
IChatRoomContainerOptionsAdapter {
+ private static final long CONNECT_TIMEOUT = 30000;
+
protected IRCConnection connection = null;
protected ReplyHandler replyHandler = null;
@@ -66,6 +68,10 @@ public class IRCRootContainer extends IRCAbstractContainer implements
private ArrayList invitationListeners;
+ private Object connectLock = new Object();
+ private boolean connectWaiting = false;
+ private Exception connectException = null;
+
public IRCRootContainer(ID localID) throws IDCreateException {
this.localID = localID;
this.unknownID = IDFactory.getDefault().createStringID("host");
@@ -115,12 +121,26 @@ public class IRCRootContainer extends IRCAbstractContainer implements
if (encoding != null)
connection.setEncoding(encoding);
trace("connecting to " + targetID);
- try {
- connection.connect();
- } catch (IOException e) {
- throw new ContainerConnectException("IRC connect exception", e);
- }
this.targetID = tID;
+
+ synchronized (connectLock) {
+ connectWaiting = true;
+ connectException = null;
+ try {
+ connection.connect();
+ while (connectWaiting) {
+ connectLock.wait(CONNECT_TIMEOUT);
+ if (connectWaiting)
+ throw new TimeoutException(CONNECT_TIMEOUT, "Timeout");
+ if (connectException != null)
+ throw connectException;
+ }
+ } catch (Exception e) {
+ this.targetID = null;
+ throw new ContainerConnectException("Connect failed to "
+ + targetID.getName(), e);
+ }
+ }
}
protected void handleDisconnected() {
@@ -132,16 +152,36 @@ public class IRCRootContainer extends IRCAbstractContainer implements
channels.clear();
}
+ protected void handleIfConnectError(String message) {
+ synchronized (connectLock) {
+ if (connectWaiting)
+ this.connectException = new Exception(message);
+ }
+ }
+
protected IRCEventListener getIRCEventListener() {
return new IRCEventListener() {
public void onRegistered() {
trace("handleOnRegistered()");
fireContainerEvent(new ContainerConnectedEvent(
IRCRootContainer.this.getID(), targetID));
+ synchronized (connectLock) {
+ connectWaiting = false;
+ connectLock.notify();
+ }
}
public void onDisconnected() {
trace("handleOnDisconnected()");
+ synchronized (connectLock) {
+ if (connectWaiting) {
+ if (connectException == null)
+ connectException = new Exception(
+ "Unexplained disconnection");
+ connectWaiting = false;
+ connectLock.notify();
+ }
+ }
showMessage(null, "Disconnected");
handleDisconnected();
}
@@ -149,11 +189,14 @@ public class IRCRootContainer extends IRCAbstractContainer implements
public void onError(String arg0) {
trace("handleOnError(" + arg0 + ")");
showMessage(null, "ERROR: " + arg0);
+ handleIfConnectError(arg0);
}
public void onError(int arg0, String arg1) {
- trace("handleOnError(" + arg0 + "," + arg1 + ")");
- showMessage(null, "ERROR: " + arg0 + "," + arg1);
+ String msg = arg0 + "," + arg1;
+ trace("handleOnError(" + msg + ")");
+ showMessage(null, "ERROR: " + msg);
+ handleIfConnectError(arg0 + msg);
}
public void onInvite(String arg0, IRCUser arg1, String arg2) {

Back to the top