/** * Create hazelcast full instance. * * @param configLocation the config location * @return the hazelcast instance */ public static HazelcastInstance createHazelcastFullInstance(String configLocation) { Config config; try { if (configLocation == null) { config = new XmlConfigBuilder().build(); } else { config = ConfigLoader.load(configLocation); } } catch (IOException e) { throw new RuntimeException("failed to load config", e); } checkNotNull(config, "failed to find configLocation: " + configLocation); config.setInstanceName(DEFAULT_INSTANCE_NAME); return Hazelcast.getOrCreateHazelcastInstance(config); }
@Override public void configure(final Properties props) { String instanceName = CacheEnvironment.getInstanceName(props); if (!StringUtil.isNullOrEmptyAfterTrim(instanceName)) { LOGGER.info("Using existing HazelcastInstance [" + instanceName + "]."); this.existingInstanceName = instanceName; } else { String configResourcePath = CacheEnvironment.getConfigFilePath(props); if (!StringUtil.isNullOrEmptyAfterTrim(configResourcePath)) { try { this.config = ConfigLoader.load(configResourcePath); } catch (IOException e) { LOGGER.warning("IOException: " + e.getMessage()); } if (config == null) { throw new CacheException("Could not find configuration file: " + configResourcePath); } } else { this.config = new XmlConfigBuilder().build(); } } this.shutDown = CacheEnvironment.shutdownOnStop(props, (instanceName == null)); }
@Override public void configure(Properties props) { String instanceName = CacheEnvironment.getInstanceName(props); if (!StringUtil.isNullOrEmptyAfterTrim(instanceName)) { LOGGER.info("Using existing HazelcastInstance [" + instanceName + "]."); this.existingInstanceName = instanceName; } else { String configResourcePath = CacheEnvironment.getConfigFilePath(props); if (!StringUtil.isNullOrEmptyAfterTrim(configResourcePath)) { try { this.config = ConfigLoader.load(configResourcePath); } catch (IOException e) { LOGGER.warning("IOException: " + e.getMessage()); } if (config == null) { throw new CacheException("Could not find configuration file: " + configResourcePath); } } else { this.config = new XmlConfigBuilder().build(); } } this.shutDown = CacheEnvironment.shutdownOnStop(props, (instanceName == null)); }
private static URL getConfigUrl(final ServletContext ctx, final String configLocation) { URL configUrl = null; try { configUrl = ctx.getResource(configLocation); } catch (MalformedURLException ignore) { LOGGER.info("Ignored MalformedURLException"); } if (configUrl == null) { configUrl = ConfigLoader.locateConfig(configLocation); } if (configUrl == null) { throw new InvalidConfigurationException("Could not load configuration '" + configLocation + "'"); } return configUrl; }
@Override public void lifecycleEvent(LifecycleEvent event) { String shutdown = System.getProperty("hazelcast.tomcat.shutdown_hazelcast_instance"); if (getConfigLocation() == null) { setConfigLocation("hazelcast-default.xml"); } if ("start".equals(event.getType())) { try { config = ConfigLoader.load(getConfigLocation()); } catch (IOException e) { throw new RuntimeException("failed to load Config:", e); } if (config == null) { throw new RuntimeException("failed to find configLocation:" + getConfigLocation()); } if (config.getInstanceName() == null) { config.setInstanceName(SessionManager.DEFAULT_INSTANCE_NAME); } Hazelcast.getOrCreateHazelcastInstance(config); } else if ("stop".equals(event.getType()) && !"false".equals(shutdown)) { HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(SessionManager.DEFAULT_INSTANCE_NAME); if (instance != null) { instance.shutdown(); } } }
private static URL getConfigURL(final FilterConfig filterConfig, final String configLocation) throws ServletException { URL configUrl = null; try { configUrl = filterConfig.getServletContext().getResource(configLocation); } catch (MalformedURLException e) { } if (configUrl == null) { configUrl = ConfigLoader.locateConfig(configLocation); } if (configUrl == null) { throw new ServletException("Could not load configuration '" + configLocation + "'"); } return configUrl; }
public ClientConfigBuilder(String resource) throws IOException { super(); URL url = ConfigLoader.locateConfig(resource); if (url == null) { throw new IllegalArgumentException("Could not load " + resource); } this.resource = resource; props.load(url.openStream()); }
public HazelcastInstance loadInstance() throws CacheException { if (instance != null && instance.getLifecycleService().isRunning()) { logger.log(Level.WARNING, "Current HazelcastInstance is already loaded and running! " + "Returning current instance..."); return instance; } String configResourcePath = null; if (props != null) { instanceName = CacheEnvironment.getInstanceName(props); useLiteMember = CacheEnvironment.isLiteMember(props); if (!useLiteMember && props.contains(CacheEnvironment.USE_SUPER_CLIENT)) { useLiteMember = CacheEnvironment.isSuperClient(props); logger.log(Level.WARNING, "'" + CacheEnvironment.USE_SUPER_CLIENT + "' property is deprecated!" + " Please use '" + CacheEnvironment.USE_LITE_MEMBER + "' instead..."); } configResourcePath = CacheEnvironment.getConfigFilePath(props); } if (useLiteMember) { logger.log(Level.WARNING, "Creating Hazelcast node as Lite-Member. " + "Make sure this node has access to an already running cluster..."); } if (isEmpty(configResourcePath)) { // If both useLiteMember and instanceName is not set // then just use default instance. if (!useLiteMember && instanceName == null) { staticInstance = true; } } else { try { config = ConfigLoader.load(configResourcePath); } catch (IOException e) { logger.log(Level.WARNING, "IOException: " + e.getMessage()); } if (config == null) { throw new CacheException("Could not find configuration file: " + configResourcePath); } } if (instanceName != null) { instance = Hazelcast.getHazelcastInstanceByName(instanceName); if (instance == null) { try { createOrGetInstance(); } catch (DuplicateInstanceNameException ignored) { instance = Hazelcast.getHazelcastInstanceByName(instanceName); } } } else { createOrGetInstance(); } return instance; }