@Override
public void connectToExternal() throws ComponentException {
String patternString = "(?<protocol>wss?):\\/\\/(?<host>.*):(?<port>\\d*)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(componentConfig.getExternalConnectionString());
boolean matches = matcher.matches();
if (!matches) {
throw new ComponentException("Invalid external connection string! " + componentConfig.getExternalConnectionString() + " does not match the expected pattern " + patternString);
}
protocol = matcher.group("protocol");
host = matcher.group("host");
port = Integer.parseInt(matcher.group("port"));
ros = new Ros(host, port, WebSocketType.valueOf(protocol));
if (!ros.connect()) {
throw new ComponentException( getName() + " cannot connect to \"" + componentConfig.getExternalConnectionString() + "\"");
}
}