本文整理匯總了Java中org.apache.flume.channel.file.FileChannel類的典型用法代碼示例。如果您正苦於以下問題:Java FileChannel類的具體用法?Java FileChannel怎麽用?Java FileChannel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileChannel類屬於org.apache.flume.channel.file包,在下文中一共展示了FileChannel類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTestFixInvalidEvents
import org.apache.flume.channel.file.FileChannel; //導入依賴的package包/類
public void doTestFixInvalidEvents(boolean withCheckpoint, String eventHandler) throws Exception {
FileChannelIntegrityTool tool = new FileChannelIntegrityTool();
tool.run(new String[] {"-l", dataDir.toString(), "-e", eventHandler, "-DvalidatorValue=0"});
FileChannel channel = new FileChannel();
channel.setName("channel");
if (withCheckpoint) {
File[] cpFiles = origCheckpointDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.contains("lock") || name.contains("queueset")) {
return false;
}
return true;
}
});
for (File cpFile : cpFiles) {
Serialization.copyFile(cpFile, new File(checkpointDir, cpFile.getName()));
}
} else {
FileUtils.deleteDirectory(checkpointDir);
Assert.assertTrue(checkpointDir.mkdirs());
}
ctx.put(FileChannelConfiguration.CHECKPOINT_DIR, checkpointDir.toString());
ctx.put(FileChannelConfiguration.DATA_DIRS, dataDir.toString());
channel.configure(ctx);
channel.start();
Transaction tx = channel.getTransaction();
tx.begin();
int i = 0;
while (channel.take() != null) {
i++;
}
tx.commit();
tx.close();
channel.stop();
Assert.assertTrue(invalidEvent != 0);
Assert.assertEquals(25 - invalidEvent, i);
}
示例2: createDataFiles
import org.apache.flume.channel.file.FileChannel; //導入依賴的package包/類
private static void createDataFiles() throws Exception {
final byte[] eventData = new byte[2000];
for (int i = 0; i < 2000; i++) {
eventData[i] = 1;
}
WriteOrderOracle.setSeed(System.currentTimeMillis());
event = EventBuilder.withBody(eventData);
baseDir = Files.createTempDir();
if (baseDir.exists()) {
FileUtils.deleteDirectory(baseDir);
}
baseDir = Files.createTempDir();
origCheckpointDir = new File(baseDir, "chkpt");
Assert.assertTrue(origCheckpointDir.mkdirs() || origCheckpointDir.isDirectory());
origDataDir = new File(baseDir, "data");
Assert.assertTrue(origDataDir.mkdirs() || origDataDir.isDirectory());
FileChannel channel = new FileChannel();
channel.setName("channel");
ctx = new Context();
ctx.put(FileChannelConfiguration.CAPACITY, "1000");
ctx.put(FileChannelConfiguration.CHECKPOINT_DIR, origCheckpointDir.toString());
ctx.put(FileChannelConfiguration.DATA_DIRS, origDataDir.toString());
ctx.put(FileChannelConfiguration.MAX_FILE_SIZE, "10000");
ctx.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "100");
channel.configure(ctx);
channel.start();
for (int j = 0; j < 5; j++) {
Transaction tx = channel.getTransaction();
tx.begin();
for (int i = 0; i < 5; i++) {
if (i % 3 == 0) {
event.getBody()[0] = 0;
invalidEvent++;
} else {
event.getBody()[0] = 1;
}
channel.put(event);
}
tx.commit();
tx.close();
}
Log log = field("log").ofType(Log.class)
.in(channel)
.get();
Assert.assertTrue("writeCheckpoint returned false",
method("writeCheckpoint").withReturnType(Boolean.class)
.withParameterTypes(Boolean.class)
.in(log)
.invoke(true));
channel.stop();
}