blob: 0a8919942a133a985370f1b8d01cd07bdb5094e2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.languages.javascript.debug.connect.test;
import java.io.IOException;
import org.eclipse.e4.languages.javascript.debug.connect.Connection;
import org.eclipse.e4.languages.javascript.debug.connect.TransportService;
import org.eclipse.e4.languages.javascript.debug.connect.TransportService.ListenerKey;
public class ConnectionHelper {
private TransportService transportService;
private String address;
public ConnectionHelper(final TransportService transportService, final String address) {
this.transportService = transportService;
this.address = address;
}
public Connection getClientConnection() {
try {
return transportService.attach(address, 5000, 5000);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public Connection getServerConnection() {
ListenerKey key = null;
try {
key = transportService.startListening(address);
return transportService.accept(key, 5000, 5000);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (key != null)
try {
transportService.stopListening(key);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}