@Override
public void run() {
ClientEndpointConfig config;
Endpoint endpoint;
final ErrorCollector collector = new ErrorCollector();
TyrusEndpointWrapper clientEndpoint;
final CountDownLatch responseLatch = new CountDownLatch(1);
ClientManagerHandshakeListener listener;
TyrusClientEngine clientEngine;
try {
if (o instanceof Endpoint) {
endpoint = (Endpoint) o;
config = configuration == null ? ClientEndpointConfig.Builder.create().build() : configuration;
} else if (o instanceof Class) {
if (Endpoint.class.isAssignableFrom((Class<?>) o)) {
//noinspection unchecked
endpoint = ReflectionHelper.getInstance(((Class<Endpoint>) o), collector);
config = configuration == null ? ClientEndpointConfig.Builder.create().build() : configuration;
} else if ((((Class<?>) o).getAnnotation(ClientEndpoint.class) != null)) {
endpoint = AnnotatedEndpoint.fromClass((Class) o, componentProvider, false, collector);
config = (ClientEndpointConfig) ((AnnotatedEndpoint) endpoint).getEndpointConfig();
} else {
collector.addException(new DeploymentException(String.format("Class %s in not Endpoint descendant and does not have @ClientEndpoint", ((Class<?>) o).getName())));
endpoint = null;
config = null;
}
} else {
endpoint = AnnotatedEndpoint.fromInstance(o, componentProvider, false, collector);
config = (ClientEndpointConfig) ((AnnotatedEndpoint) endpoint).getEndpointConfig();
}
clientEndpoint = new TyrusEndpointWrapper(endpoint, config, componentProvider,
webSocketContainer == null ? ClientManager.this : webSocketContainer, url, null);
// fail fast when there is some issue with client endpoint.
if (!collector.isEmpty()) {
future.setFailure(collector.composeComprehensiveException());
return;
}
listener = new ClientManagerHandshakeListener() {
private volatile Session session;
private volatile Throwable throwable;
@Override
public void onSessionCreated(Session session) {
this.session = session;
responseLatch.countDown();
}
@Override
public void onError(Throwable exception) {
throwable = exception;
responseLatch.countDown();
}
@Override
public Session getSession() {
return session;
}
@Override
public Throwable getThrowable() {
return throwable;
}
};
clientEngine = new TyrusClientEngine(clientEndpoint, listener, copiedProperties);
container.openClientSocket(url, config, copiedProperties, clientEngine);
} catch (IOException e) {
future.setFailure(e);
return;
} catch (DeploymentException e) {
future.setFailure(e);
return;
}
if (!collector.isEmpty()) {
future.setFailure(collector.composeComprehensiveException());
return;
}
try {
final boolean countedDown = responseLatch.await(handshakeTimeout, TimeUnit.MILLISECONDS);