/** * Ensures that the file described by the supplied parameter does not exist * after the method returns. If the file didn't exist, returns silently. * If the file could not be deleted, returns silently. * If the file is a directory, its children are recursively deleted. */ public static void deleteQuietly(File f) { try { delete(f); } catch (Exception e) { ignore(e); } }
/** * Ensures that the file described by the supplied parameter does not exist * after the method returns. If the file didn't exist, returns silently. * If the file could not be deleted, returns silently. * If the file is a directory, its children are recursively deleted. */ public static void deleteQuietly(File f) { try { delete(f); } catch (Exception e) { ignore(e); } }
/** * Ensures that the file described by the supplied parameter does not exist * after the method returns. If the file didn't exist, returns silently. * If the file could not be deleted, fails with an exception. * If the file is a directory, its children are recursively deleted. */ public static void delete(File f) { if (!f.exists()) { return; } File[] subFiles = f.listFiles(); if (subFiles != null) { for (File sf : subFiles) { delete(sf); } } if (!f.delete()) { throw new HazelcastException("Failed to delete " + f); } }
/** * Ensures that the file described by the supplied parameter does not exist * after the method returns. If the file didn't exist, returns silently. * If the file could not be deleted, fails with an exception. * If the file is a directory, its children are recursively deleted. */ public static void delete(File f) { if (!f.exists()) { return; } File[] subFiles = f.listFiles(); if (subFiles != null) { for (File sf : subFiles) { delete(sf); } } if (!f.delete()) { throw new HazelcastException("Failed to delete " + f); } }
public static void main(String[] args) throws Exception { System.setProperty("hazelcast.logging.type", "log4j"); Path tempDir = Files.createTempDirectory(AccessLogStreamAnalyzer.class.getSimpleName()); Pipeline p = buildPipeline(tempDir); JetInstance instance = Jet.newJetInstance(); try { instance.newJob(p); // job is running in its own threads. Let's generate some random traffic in this thread. startGenerator(tempDir); // wait for all writes to be picked up LockSupport.parkNanos(SECONDS.toNanos(1)); } finally { Jet.shutdownAll(); IOUtil.delete(tempDir.toFile()); } }
public static void main(String[] args) throws InterruptedException { IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5701")); IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5702")); HazelcastInstance instance1 = newHazelcastInstance(5701); HazelcastInstance instance2 = newHazelcastInstance(5702); Cache<Integer, String> cache = createCache(instance2); for (int i = 0; i < 50; i++) { cache.put(i, "value" + i); } instance2.getCluster().changeClusterState(ClusterState.PASSIVE); instance1.shutdown(); Thread.sleep(5000L); instance1 = newHazelcastInstance(5701); instance1.getCluster().changeClusterState(ClusterState.ACTIVE); for (int i = 0; i < 50; i++) { System.out.println("cache.get(" + i + ") = " + cache.get(i)); } Hazelcast.shutdownAll(); }
public static void main(String[] args) { IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5701")); IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5702")); HazelcastInstance instance1 = newHazelcastInstance(5701); HazelcastInstance instance2 = newHazelcastInstance(5702); Cache<Integer, String> cache = createCache(instance1); for (int i = 0; i < 50; i++) { cache.put(i, "value" + i); } instance2.getCluster().shutdown(); // Offloading to a thread. // Because all instances should start in parallel // to be able to do hot-restart cluster verification new Thread() { public void run() { newHazelcastInstance(5701); } }.start(); instance2 = newHazelcastInstance(5702); instance2.getCluster().changeClusterState(ClusterState.ACTIVE); cache = createCache(instance2); for (int i = 0; i < 50; i++) { System.out.println("cache.get(" + i + ") = " + cache.get(i)); } Hazelcast.shutdownAll(); }
public static void main(String[] args) { IOUtil.delete(new File(HOT_RESTART_ROOT_DIR)); Config config = new Config(); config.setLicenseKey(ENTERPRISE_LICENSE_KEY); config.getNetworkConfig().setPort(5701).setPortAutoIncrement(false); JoinConfig join = config.getNetworkConfig().getJoin(); join.getMulticastConfig().setEnabled(false); join.getTcpIpConfig().setEnabled(true).clear().addMember("127.0.0.1"); HotRestartPersistenceConfig hotRestartConfig = config.getHotRestartPersistenceConfig(); hotRestartConfig.setEnabled(true).setBaseDir(new File(HOT_RESTART_ROOT_DIR)); HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); Cache<Integer, String> cache = createCache(instance); for (int i = 0; i < 10; i++) { cache.put(i, "value" + i); } instance.shutdown(); instance = Hazelcast.newHazelcastInstance(config); cache = createCache(instance); for (int i = 0; i < 10; i++) { System.out.println("cache.get(" + i + ") = " + cache.get(i)); } Hazelcast.shutdownAll(); }