/** * Creates a new Hazelcast instance. * * @param config the configuration to use; if <code>null</code>, the set of defaults * as specified in the XSD for the configuration XML will be used. * @param instanceName the name of the {@link HazelcastInstance} * @param nodeContext the {@link NodeContext} to use * @return the configured {@link HazelcastInstance} */ public static HazelcastInstance newHazelcastInstance(Config config, String instanceName, NodeContext nodeContext) { if (config == null) { config = new XmlConfigBuilder().build(); } String name = getInstanceName(instanceName, config); InstanceFuture future = new InstanceFuture(); if (INSTANCE_MAP.putIfAbsent(name, future) != null) { throw new DuplicateInstanceNameException("HazelcastInstance with name '" + name + "' already exists!"); } try { return constructHazelcastInstance(config, name, nodeContext, future); } catch (Throwable t) { INSTANCE_MAP.remove(name, future); future.setFailure(t); throw ExceptionUtil.rethrow(t); } }
/** * Creates a new Hazelcast instance. * * @param config the configuration to use; if <code>null</code>, the set of defaults * as specified in the XSD for the configuration XML will be used. * @param instanceName the name of the {@link HazelcastInstance} * @param nodeContext the {@link NodeContext} to use * @return the configured {@link HazelcastInstance} */ public static HazelcastInstance newHazelcastInstance(Config config, String instanceName, NodeContext nodeContext) { if (config == null) { config = new XmlConfigBuilder().build(); } String name = getInstanceName(instanceName, config); InstanceFuture future = new InstanceFuture(); if (INSTANCE_MAP.putIfAbsent(name, future) != null) { throw new DuplicateInstanceNameException("HazelcastInstance with name '" + name + "' already exists!"); } try { return constructHazelcastInstance(config, name, nodeContext, future); } catch (Throwable t) { INSTANCE_MAP.remove(name, future); future.setFailure(t); throw ExceptionUtil.rethrow(t); } }