protected void ensureInstanceIsUp() throws Exception { if (isInstanceNotActive(hz)) { hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); } if (serverXml1 != null) { if (server1 == null) { serverPort1 = availablePort(); server1 = getServletContainer(serverPort1, sourceDir, serverXml1); } else if (!server1.isRunning()) { server1.start(); } } if (serverXml2 != null) { if (server2 == null) { serverPort2 = availablePort(); server2 = getServletContainer(serverPort2, sourceDir, serverXml2); } else if (!server2.isRunning()) { server2.start(); } } }
@Test public void whenClusterIsDown_enabledDeferredWrite() throws Exception { CookieStore cookieStore = new BasicCookieStore(); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); hz.shutdown(); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); assertEquals("true", executeRequest("remove", serverPort1, cookieStore)); assertEquals("null", executeRequest("read", serverPort1, cookieStore)); hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); assertClusterSizeEventually(1, hz); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); }
@Test public void whenClusterIsDownAtBeginning_enabledDeferredWrite() throws Exception { hz.shutdown(); CookieStore cookieStore = new BasicCookieStore(); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); assertEquals("true", executeRequest("remove", serverPort1, cookieStore)); assertEquals("null", executeRequest("read", serverPort1, cookieStore)); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); assertClusterSizeEventually(1, hz); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); assertEquals("true", executeRequest("remove", serverPort1, cookieStore)); assertEquals("null", executeRequest("read", serverPort1, cookieStore)); }
@Test public void testWhenClusterIsDownAtBeginningInNonDeferredMode() throws Exception { if (!testName.equals("client - not deferred")) { return; } hz.shutdown(); CookieStore cookieStore = new BasicCookieStore(); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); assertClusterSizeEventually(1, hz); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME); assertEquals(1, map.size()); }
@Test public void testWhenClusterIsDownAtBeginningInDeferedMode() throws Exception { if (!testName.equals("client - not deferred")) { return; } hz.shutdown(); CookieStore cookieStore = new BasicCookieStore(); assertEquals("true", executeRequest("write", serverPort1, cookieStore)); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); assertClusterSizeEventually(1, hz); assertEquals("value", executeRequest("read", serverPort1, cookieStore)); IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME); assertEquals(0, map.size()); }
@Override protected void ensureInstanceIsUp() throws Exception { if (isInstanceNotActive(hz)) { hz = Hazelcast.newHazelcastInstance( new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml"))); } if (serverXml1 != null) { if (server1 == null) { serverPort1 = availablePort(); server1 = getServletContainer(serverPort1, sourceDir, serverXml1); } else if (!server1.isRunning()) { server1.start(); } } if (serverXml2 != null) { if (server2 == null) { serverPort2 = availablePort(); server2 = getServletContainer(serverPort2, sourceDir, serverXml2); } else if (!server2.isRunning()) { server2.start(); } } }
public void start() { try { logger.info("HazelcastServer starting"); File configurationFile = new File(CONFIGURATION_DIRECTORY, CONFIGURATION_FILENAME); if (!configurationFile.exists()) { try (FileOutputStream fos = new FileOutputStream(configurationFile)) { fos.write(HybridbpmCoreUtil.getDefaultHazelcastConfig().getBytes()); } } configurationFile = new File(CONFIGURATION_DIRECTORY, CONFIGURATION_FILENAME); hazelcastInstance = Hazelcast.newHazelcastInstance(new FileSystemXmlConfig(configurationFile)); logger.info("HazelcastServer started"); } catch (Exception ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); } }
@Activate public void activate() { try { File hazelcastFile = new File(HAZELCAST_XML_FILE); if (!hazelcastFile.exists()) { createDefaultHazelcastFile(hazelcastFile); } Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE); instance = Hazelcast.newHazelcastInstance(config); log.info("Started"); } catch (FileNotFoundException e) { log.error("Unable to configure Hazelcast", e); } }
private void configureHazelcast(final Properties properties) { if (null == hazelcast || !Hazelcast.getAllHazelcastInstances().contains(hazelcast)) { String configFile = properties.getProperty(CACHE_CONFIG_FILE); if (null == configFile) { LOGGER.warn("Config file not set using system property: " + CACHE_CONFIG_FILE + ". Using default settings"); hazelcast = Hazelcast.newHazelcastInstance(); } else { try { final Config config = new FileSystemXmlConfig(configFile); hazelcast = Hazelcast.newHazelcastInstance(config); } catch (final Exception e) { throw new IllegalArgumentException("Could not create cache using config path: " + configFile, e); } } } }
private void configureCluster(IConfig config) throws FileNotFoundException { LOG.info("Configuring embedded Hazelcast instance"); String interceptHandlerClassname = config.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME); if (interceptHandlerClassname == null || !HZ_INTERCEPT_HANDLER.equals(interceptHandlerClassname)) { LOG.info("There are no Hazelcast intercept handlers. The server won't start a Hazelcast instance."); return; } String hzConfigPath = config.getProperty(BrokerConstants.HAZELCAST_CONFIGURATION); if (hzConfigPath != null) { boolean isHzConfigOnClasspath = this.getClass().getClassLoader().getResource(hzConfigPath) != null; Config hzconfig = isHzConfigOnClasspath ? new ClasspathXmlConfig(hzConfigPath) : new FileSystemXmlConfig(hzConfigPath); LOG.info("Starting Hazelcast instance. ConfigurationFile={}", hzconfig); hazelcastInstance = Hazelcast.newHazelcastInstance(hzconfig); } else { LOG.info("Starting Hazelcast instance with default configuration"); hazelcastInstance = Hazelcast.newHazelcastInstance(); } listenOnHazelCastMsg(); }
/** * * @param configFile * @param entityBasePkg * @throws FileNotFoundException */ public HazelcastInstanceProxy(File configFile, String entityBasePkg) throws FileNotFoundException { this(new FileSystemXmlConfig(configFile), entityBasePkg); }