}
public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
debug("connect(" + remote + "," + data + "," + timeout + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (socket != null)
throw new ECFException("Already connected"); //$NON-NLS-1$
if (remote == null)
throw new ECFException("remote cannot be null"); //$NON-NLS-1$
// parse remote ID to URI
URI anURI = parseRemoteID(remote);
// Create socket by calling createSocket
final Socket s = createConnectSocket(anURI, timeout);
ConnectResultMessage res = null;
try {
// Set socket options
setSocketOptions(s);
// Now we've got a connection so set our socket
setSocket(s);
outputStream = new ObjectOutputStream(s.getOutputStream());
outputStream.flush();
inputStream = new ObjectInputStream(s.getInputStream());
debug("connect;" + anURI); //$NON-NLS-1$
// send connect data and get synchronous response
send(new ConnectRequestMessage(anURI, (Serializable) data));
res = (ConnectResultMessage) readObject();
} catch (final IOException e) {
throw new ECFException("Exception during connection to " + remote.getName(), e); //$NON-NLS-1$
}
debug("connect;rcv:" + res); //$NON-NLS-1$
if (res == null)
throw new ECFException("Result cannot be null"); //$NON-NLS-1$
// Setup threads
setupThreads();
// Return results.
final Object ret = res.getData();
debug("connect;returning:" + ret); //$NON-NLS-1$