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;
}
Aggregations