use of org.eclipse.equinox.concurrent.future.TimeoutException in project ecf by eclipse.
the class IRCChannelContainer method connect.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID,
* org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(ID connectID, IConnectContext connectContext) throws ContainerConnectException {
// Actually do join here
if (connectID == null)
throw new ContainerConnectException(Messages.IRCChannelContainer_Exception_TargetID_Null);
if (connectWaiting)
throw new ContainerConnectException(Messages.IRCChannelContainer_Exception_Connecting);
// Get channel name
String channelName = connectID.getName();
fireContainerEvent(new ContainerConnectingEvent(this.getID(), connectID, connectContext));
// Get password via callback in connectContext
String pw = getPasswordFromConnectContext(connectContext);
synchronized (connectLock) {
connectWaiting = true;
try {
rootContainer.doJoinChannel(channelName, pw);
long timeout = CONNECT_TIMEOUT + System.currentTimeMillis();
while (connectWaiting && timeout > System.currentTimeMillis()) {
connectLock.wait(2000);
}
if (connectWaiting)
throw new TimeoutException(NLS.bind(Messages.IRCChannelContainer_Exception_Connect_Timeout, connectID.getName()), CONNECT_TIMEOUT);
this.targetID = connectID;
fireContainerEvent(new ContainerConnectedEvent(this.getID(), this.targetID));
} catch (Exception e) {
this.targetID = null;
throw new ContainerConnectException(NLS.bind(Messages.IRCChannelContainer_Exception_Connect_Failed, connectID.getName()), e);
} finally {
connectWaiting = false;
}
}
}
use of org.eclipse.equinox.concurrent.future.TimeoutException in project ecf by eclipse.
the class IRCRootContainer method connect.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID,
* org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(ID connectID, IConnectContext connectContext) throws ContainerConnectException {
if (connection != null)
throw new ContainerConnectException(Messages.IRCRootContainer_Exception_Already_Connected);
if (connectID == null)
throw new ContainerConnectException(Messages.IRCRootContainer_Exception_TargetID_Null);
if (!(connectID instanceof IRCID))
throw new ContainerConnectException(NLS.bind(Messages.IRCRootContainer_Exception_TargetID_Wrong_Type, new Object[] { targetID, IRCID.class.getName() }));
if (connectWaiting)
throw new ContainerConnectException(Messages.IRCRootContainer_Connecting);
fireContainerEvent(new ContainerConnectingEvent(this.getID(), connectID, connectContext));
// Get password via callback in connectContext
String pw = getPasswordFromConnectContext(connectContext);
IRCID tID = (IRCID) connectID;
String host = tID.getHost();
int port = tID.getPort();
String pass = pw;
String nick = tID.getUser();
String user = nick;
this.username = user;
String name = null;
boolean ssl = false;
if (!ssl) {
connection = new IRCConnection(host, new int[] { port }, pass, nick, user, name);
} else {
connection = new SSLIRCConnection(host, new int[] { port }, pass, nick, user, name);
}
// connection setup
connection.addIRCEventListener(getIRCEventListener());
connection.setPong(true);
connection.setDaemon(false);
connection.setColors(true);
if (encoding != null)
connection.setEncoding(encoding);
trace(Messages.IRCRootContainer_Connecting_To + targetID);
synchronized (connectLock) {
connectWaiting = true;
connectException = null;
try {
connection.connect();
long timeout = CONNECT_TIMEOUT + System.currentTimeMillis();
while (connectWaiting && (timeout > System.currentTimeMillis())) {
connectLock.wait(2000);
}
if (connectWaiting)
throw new TimeoutException(NLS.bind(Messages.IRCRootContainer_Connect_Timeout, tID.getName()), CONNECT_TIMEOUT);
if (connectException != null)
throw connectException;
this.targetID = tID;
fireContainerEvent(new ContainerConnectedEvent(getID(), this.targetID));
if (datashareContainer != null) {
// now that we've connected successfully, we send a USERHOST
// message to the server so that we can attempt to retrieve
// our current IP
retrieveUserhost = true;
connection.doUserhost(nick);
}
} catch (Exception e) {
this.targetID = null;
throw new ContainerConnectException(NLS.bind(Messages.IRCRootContainer_Exception_Connect_Failed, connectID.getName()), e);
} finally {
connectWaiting = false;
connectException = null;
}
}
}
Aggregations