Search in sources :

Example 1 with DuplicateInstanceNameException

use of com.hazelcast.core.DuplicateInstanceNameException in project hazelcast by hazelcast.

the class HazelcastClientManager method newHazelcastClient.

@SuppressWarnings("unchecked")
public static HazelcastInstance newHazelcastClient(ClientConfig config, HazelcastClientFactory hazelcastClientFactory) {
    if (config == null) {
        config = new XmlClientConfigBuilder().build();
    }
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    HazelcastClientProxy proxy;
    try {
        Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
        ClientConnectionManagerFactory clientConnectionManagerFactory = new DefaultClientConnectionManagerFactory();
        final HazelcastClientInstanceImpl client = hazelcastClientFactory.createHazelcastInstanceClient(config, clientConnectionManagerFactory);
        client.start();
        OutOfMemoryErrorDispatcher.registerClient(client);
        proxy = hazelcastClientFactory.createProxy(client);
        if (INSTANCE.clients.putIfAbsent(client.getName(), proxy) != null) {
            throw new DuplicateInstanceNameException("HazelcastClientInstance with name '" + client.getName() + "' already exists!");
        }
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
    return proxy;
}
Also used : DuplicateInstanceNameException(com.hazelcast.core.DuplicateInstanceNameException) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConnectionManagerFactory(com.hazelcast.client.impl.ClientConnectionManagerFactory) DefaultClientConnectionManagerFactory(com.hazelcast.client.impl.DefaultClientConnectionManagerFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) DefaultClientConnectionManagerFactory(com.hazelcast.client.impl.DefaultClientConnectionManagerFactory) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Aggregations

XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)1 ClientConnectionManagerFactory (com.hazelcast.client.impl.ClientConnectionManagerFactory)1 DefaultClientConnectionManagerFactory (com.hazelcast.client.impl.DefaultClientConnectionManagerFactory)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)1 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)1 DuplicateInstanceNameException (com.hazelcast.core.DuplicateInstanceNameException)1