Search in sources :

Example 1 with HazelcastClient

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);
        }
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastAPIDelegatingClassloader(com.hazelcast.test.starter.HazelcastAPIDelegatingClassloader) HazelcastClient(com.hazelcast.client.HazelcastClient)

Aggregations

HazelcastClient (com.hazelcast.client.HazelcastClient)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastAPIDelegatingClassloader (com.hazelcast.test.starter.HazelcastAPIDelegatingClassloader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1