@Override
public void run() {
try {
final Endpoint endpoint = Remoting.createEndpoint("endpoint", OptionMap.EMPTY);
endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
// open a connection
final IoFuture<Connection> futureConnection = endpoint.connect(new URI(hostUrl), OptionMap.create(Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE), new AnonymousCallbackHandler());
final Connection connection = IoFutureHelper.get(futureConnection, 5L, TimeUnit.SECONDS);
try {
try {
final ClassLoader oldTccl = SecurityActions.getContextClassLoader();
try {
try {
SecurityActions.setContextClassLoader(classLoader);
final EJBClientContext ejbClientContext = EJBClientContext.create();
ejbClientContext.registerConnection(connection);
final ContextSelector<EJBClientContext> previousSelector = EJBClientContext.setConstantContext(ejbClientContext);
applicationClientDeploymentServiceInjectedValue.getValue().getDeploymentCompleteLatch().await();
try {
NamespaceContextSelector.pushCurrentSelector(namespaceContextSelectorInjectedValue);
//do static injection etc
//TODO: this should be better
instance = applicationClientComponent.getValue().createInstance();
mainMethod.invoke(null, new Object[]{parameters});
} finally {
if (previousSelector != null) {
EJBClientContext.setSelector(previousSelector);
}
NamespaceContextSelector.popCurrentSelector();
}
} catch (Exception e) {
ROOT_LOGGER.exceptionRunningAppClient(e, e.getClass().getSimpleName());
} finally {
SecurityActions.setContextClassLoader(oldTccl);
}
} finally {
CurrentServiceContainer.getServiceContainer().shutdown();
}
} finally {
connection.close();
}
} finally {
endpoint.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);