本文整理汇总了Java中net.openhft.chronicle.ExcerptTailer.nextIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ExcerptTailer.nextIndex方法的具体用法?Java ExcerptTailer.nextIndex怎么用?Java ExcerptTailer.nextIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.openhft.chronicle.ExcerptTailer
的用法示例。
在下文中一共展示了ExcerptTailer.nextIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAvailableValues
import net.openhft.chronicle.ExcerptTailer; //导入方法依赖的package包/类
private static Set<String> readAvailableValues(final ExcerptTailer tailer) {
final Set<String> values = new TreeSet<String>();
while (tailer.nextIndex()) {
values.add(tailer.readUTF());
}
return values;
}
示例2: testAppender
import net.openhft.chronicle.ExcerptTailer; //导入方法依赖的package包/类
@Test
public void testAppender() throws Exception {
String dataDir = "build/chronicle";
FileUtil.removeIfExist(dataDir, true);
System.out.println("data dir: " + dataDir);
IndexedChronicle chronicle = new IndexedChronicle(dataDir + "/data", ChronicleConfig.SMALL);
ExcerptAppender appender = chronicle.createAppender();
appender.startExcerpt(8);
appender.writeLong(10l);
appender.finish();
for(int i = 0; i < 10; i++) {
String string = "test " + i ;
byte[] data = string.getBytes() ;
appender.startExcerpt(data.length);
appender.write(data);
appender.finish();
}
ExcerptTailer reader = chronicle.createTailer();
reader.index(1) ;
while (reader.nextIndex()) {
System.out.println("Read string by reader: " + reader.readLine());
}
Excerpt excerpt = chronicle.createExcerpt() ;
excerpt.index(1);
while(excerpt.nextIndex()) {
System.out.println("Read string by exerpt: " + excerpt.readLine());
}
appender.close();
reader.close();
excerpt.close();
excerpt = chronicle.createExcerpt() ;
long longNumber = excerpt.readLong() ;
System.out.println("Long number = " + longNumber);
}
示例3: testTailerPerf
import net.openhft.chronicle.ExcerptTailer; //导入方法依赖的package包/类
@Test
public void testTailerPerf() throws IOException {
final int WARMUP = 50000;
final int RUNS = 5000000;
final String baseDir = getTestPath();
assertNotNull(baseDir);
final VanillaChronicle chronicle = new VanillaChronicle(baseDir);
chronicle.clear();
try {
final ExcerptAppender appender = chronicle.createAppender();
final ExcerptTailer tailer = chronicle.createTailer();
long start = 0;
assertEquals(-1L, tailer.index());
for (int i = -WARMUP; i < RUNS; i++) {
if (i == 0)
start = System.nanoTime();
boolean condition0 = tailer.nextIndex();
if (condition0)
assertFalse("i: " + i, condition0);
appender.startExcerpt();
int value = 1000000000 + i;
appender.append(value).append(' ');
appender.finish();
boolean condition = tailer.nextIndex();
long actual = tailer.parseLong();
if (i < 0) {
assertTrue("i: " + i, condition);
assertEquals("i: " + i, value, actual);
}
tailer.finish();
}
long time = System.nanoTime() - start;
System.out.printf("Average write/read times was %.3f us%n", time / RUNS / 1e3);
appender.close();
tailer.close();
chronicle.checkCounts(1, 1);
} finally {
chronicle.close();
chronicle.clear();
assertFalse(new File(baseDir).exists());
}
}
示例4: testMultipleCycles2
import net.openhft.chronicle.ExcerptTailer; //导入方法依赖的package包/类
@Test
public void testMultipleCycles2() throws Exception {
final String baseDir = "build/vanilla";
assertNotNull(baseDir);
FileUtil.removeIfExist(baseDir, false);
// Create with small data and index sizes so that the test frequently
// generates new files
VanillaChronicleConfig config = new VanillaChronicleConfig();
config.cycleFormat("yyyy-MM-dd-HH:mm:ss");
config.cycleLength(60 * 1000, false);
config.entriesPerCycle(512 * 1024);
config.dataBlockSize(4 * 1024 * 1024);
config.indexBlockSize(1 * 1024 * 1024);
final VanillaChronicle chronicle = new VanillaChronicle(baseDir, config);
chronicle.clear();
try {
ExcerptAppender appender = chronicle.createAppender();
long start = System.currentTimeMillis() ;
for(int j = 0; j < 4500000; j++) {
appender.startExcerpt();
appender.writeInt(j + 1);
appender.finish();
}
long exec = System.currentTimeMillis() - start ;
System.out.println("Append in " + exec + "ms");
for(int i = 0; i < 5; i++) {
long sum = 0 ;
AtomicInteger count = new AtomicInteger() ;
ExcerptTailer tailer = chronicle.createTailer();
int lastValue = 0 ;
while(tailer.nextIndex()) {
count.incrementAndGet() ;
lastValue = tailer.readInt();
sum += lastValue;
tailer.finish();
}
//tailer.flush() ;
tailer.close();
System.out.println("files = " +tailer.file()) ;
System.out.println(
"count = " + count.get() + ", sum = " + sum + ", last value = " + lastValue + ", last index = " + chronicle.lastIndex() +
", was padding = " + tailer.wasPadding() + ", nextIndex = " + tailer.nextIndex() +
", finished = " + tailer.isFinished());
}
appender.close();
chronicle.checkCounts(1, 1);
} finally {
chronicle.close();
}
}