@Test public void testFindNextDataCount() throws Exception { final String baseDir = getTestPath(); assertNotNull(baseDir); try { final DateCache dateCache = new DateCache("yyyyMMddHHmmss", 1000); final VanillaDataCache cache = new VanillaDataCache(baseDir, 10 + 6, dateCache); int cycle = (int) (System.currentTimeMillis() / 1000); final int threadId = AffinitySupport.getThreadId(); assertEquals(0, cache.findNextDataCount(cycle, threadId)); VanillaMappedBytes vanillaBuffer1 = cache.dataFor(cycle, threadId, 1, true); vanillaBuffer1.release(); VanillaMappedBytes vanillaBuffer2 = cache.dataFor(cycle, threadId, 2, true); vanillaBuffer2.release(); VanillaMappedBytes vanillaBuffer4 = cache.dataFor(cycle, threadId, 4, true); vanillaBuffer4.release(); cache.checkCounts(1, 1); cache.close(); final VanillaDataCache cache2 = new VanillaDataCache(baseDir, 10 + 6, dateCache); assertEquals(5, cache2.findNextDataCount(cycle, threadId)); cache.checkCounts(1, 1); cache2.close(); } finally { IOTools.deleteDir(baseDir); assertFalse(new File(baseDir).exists()); } }
public int findNextDataCount(int cycle, int threadId) throws IOException { final String cycleStr = dateCache.formatFor(cycle); final String cyclePath = basePath + "/" + cycleStr; final String dataPrefix = FILE_NAME_PREFIX + threadId + "-"; int maxCount = -1; final File[] files = new File(cyclePath).listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(dataPrefix)) { final int count = Integer.parseInt(file.getName().substring(dataPrefix.length())); if (maxCount < count) maxCount = count; } } } return maxCount + 1; }
VanillaDataCache implements Closeable { public int findNextDataCount(int cycle, int threadId) throws IOException { final String cycleStr = dateCache.formatFor(cycle); final String cyclePath = basePath + "/" + cycleStr; final String dataPrefix = FILE_NAME_PREFIX + threadId + "-"; int maxCount = -1; final File[] files = new File(cyclePath).listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(dataPrefix)) { final int count = Integer.parseInt(file.getName().substring(dataPrefix.length())); if (maxCount < count) maxCount = count; } } } return maxCount + 1; } }
VanillaDataCache implements Closeable { public int findNextDataCount(int cycle, int threadId) throws IOException { final String cycleStr = dateCache.formatFor(cycle); final String cyclePath = basePath + "/" + cycleStr; final String dataPrefix = FILE_NAME_PREFIX + threadId + "-"; int maxCount = -1; final File[] files = new File(cyclePath).listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(dataPrefix)) { final int count = Integer.parseInt(file.getName().substring(dataPrefix.length())); if (maxCount < count) maxCount = count; } } } return maxCount + 1; } VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, @NotNull VanillaChronicleConfig config);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity, boolean cleanupOnClose); }
VanillaDataCache implements Closeable { public int findNextDataCount(int cycle, int threadId) throws IOException { final String cycleStr = dateCache.formatFor(cycle); final String cyclePath = basePath + "/" + cycleStr; final String dataPrefix = FILE_NAME_PREFIX + threadId + "-"; int maxCount = -1; final File[] files = new File(cyclePath).listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(dataPrefix)) { final int count = Integer.parseInt(file.getName().substring(dataPrefix.length())); if (maxCount < count) maxCount = count; } } } return maxCount + 1; } VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, @NotNull VanillaChronicleConfig config);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity, boolean cleanupOnClose); File fileFor(int cycle, int threadId, int dataCount, boolean forWrite); File fileFor(int cycle, int threadId); synchronized VanillaMappedBytes dataFor(int cycle, int threadId, int dataCount, boolean forWrite); @Override synchronized void close(); int findNextDataCount(int cycle, int threadId); void checkCounts(int min, int max); }
VanillaDataCache implements Closeable { public int findNextDataCount(int cycle, int threadId) throws IOException { final String cycleStr = dateCache.formatFor(cycle); final String cyclePath = basePath + "/" + cycleStr; final String dataPrefix = FILE_NAME_PREFIX + threadId + "-"; int maxCount = -1; final File[] files = new File(cyclePath).listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(dataPrefix)) { final int count = Integer.parseInt(file.getName().substring(dataPrefix.length())); if (maxCount < count) maxCount = count; } } } return maxCount + 1; } VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, @NotNull VanillaChronicleConfig config);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity);  VanillaDataCache(@NotNull String basePath, int blockBits, @NotNull DateCache dateCache, int capacity, boolean cleanupOnClose); File fileFor(int cycle, int threadId, int dataCount, boolean forWrite); File fileFor(int cycle, int threadId); synchronized VanillaMappedBytes dataFor(int cycle, int threadId, int dataCount, boolean forWrite); @Override synchronized void close(); int findNextDataCount(int cycle, int threadId); void checkCounts(int min, int max);  }