use of com.hazelcast.client.HazelcastClient in project hazelcast by hazelcast.
the class HazelcastClientStarter method newHazelcastClient.
@SuppressWarnings("unchecked")
public static HazelcastInstance newHazelcastClient(String version, ClientConfig clientConfig, boolean enterprise, List<URL> additionalJars) {
ClassLoader classLoader = clientConfig == null ? null : clientConfig.getClassLoader();
HazelcastAPIDelegatingClassloader classloader = getTargetVersionClassloader(version, enterprise, classLoader, additionalJars);
ClassLoader contextClassLoader = currentThread().getContextClassLoader();
currentThread().setContextClassLoader(null);
try {
Class<HazelcastClient> hazelcastClass = (Class<HazelcastClient>) classloader.loadClass("com.hazelcast.client.HazelcastClient");
System.out.println(hazelcastClass + " loaded by " + hazelcastClass.getClassLoader());
Class<?> configClass = classloader.loadClass("com.hazelcast.client.config.ClientConfig");
Object config = getConfig(classloader, configClass, clientConfig);
Method newHazelcastInstanceMethod = hazelcastClass.getMethod("newHazelcastClient", configClass);
Object delegate = newHazelcastInstanceMethod.invoke(null, config);
return (HazelcastInstance) proxyObjectForStarter(HazelcastStarter.class.getClassLoader(), delegate);
} catch (ClassNotFoundException e) {
throw rethrowGuardianException(e);
} catch (NoSuchMethodException e) {
throw rethrowGuardianException(e);
} catch (IllegalAccessException e) {
throw rethrowGuardianException(e);
} catch (InvocationTargetException e) {
throw rethrowGuardianException(e);
} catch (InstantiationException e) {
throw rethrowGuardianException(e);
} finally {
if (contextClassLoader != null) {
currentThread().setContextClassLoader(contextClassLoader);
}
}
}
Aggregations