throw new IOException("Timeout out waiting for header, status=" + result.toString());
}
InitialHeader header = futureHeader.get();
Versions versions = new Versions(environment);
Set<Byte> supportedVersions = versions.getSupportedVersions(getRequiredCapabilities(serviceURL));
// Find the highest version. - By this point the exceptional handling of version 0x00 will have completed.
byte highest = 0x00;
for (byte current : header.versions) {
// Only accept it if it is one of the supported versions otherwise ignore as noise.
if (supportedVersions.contains(current) && current > highest) {
highest = current;
}
}
if (highest == 0x00) {
throw new IllegalStateException("No matching supported protocol version found.");
}
// getVersionedConnection may also make use of an IoFuture but our previous use of one has ended.
return versions.getVersionedConnection(highest, channel, serviceURL);
}