本文整理汇总了Java中com.indeed.util.core.shell.PosixFileOperations类的典型用法代码示例。如果您正苦于以下问题:Java PosixFileOperations类的具体用法?Java PosixFileOperations怎么用?Java PosixFileOperations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PosixFileOperations类属于com.indeed.util.core.shell包,在下文中一共展示了PosixFileOperations类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearTempDir
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
private void clearTempDir(String directory) throws IOException {
File tmpDir = new File(directory);
if (!tmpDir.exists()) {
throw new IOException(directory + " does not exist.");
}
if (!tmpDir.isDirectory()) {
throw new IOException(directory + " is not a directory.");
}
for (File f : tmpDir.listFiles()) {
if (f.isDirectory() && f.getName().endsWith(".optimization_log")) {
/* an optimized index */
PosixFileOperations.rmrf(f);
}
if (!f.isDirectory() && f.getName().startsWith(".tmp")) {
/* an optimization log */
f.delete();
}
}
}
示例2: clearTempDir
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
private void clearTempDir(String directory) throws IOException {
final File tmpDir = new File(directory);
if (!tmpDir.exists()) {
throw new IOException(directory + " does not exist.");
}
if (!tmpDir.isDirectory()) {
throw new IOException(directory + " is not a directory.");
}
for (File f : tmpDir.listFiles()) {
if (f.isDirectory() && f.getName().endsWith(".optimization_log")) {
/* an optimized index */
PosixFileOperations.rmrf(f);
}
if (!f.isDirectory() && f.getName().startsWith(".tmp")) {
/* an optimization log */
f.delete();
}
}
}
示例3: checkpoint
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
public void checkpoint(File checkpointDir) throws IOException {
final SharedReference<GenerationState<K, V>> localState = generationState.getCopy();
try {
if (localState == null) {
throw new IOException("store is closed");
}
checkpointDir.mkdirs();
localState.get().volatileGeneration.checkpoint(checkpointDir);
for (Generation<K, V> generation : localState.get().stableGenerations) {
generation.checkpoint(checkpointDir);
}
PosixFileOperations.cplr(new File(localState.get().path, "state"), checkpointDir);
} finally {
Closeables2.closeQuietly(localState, log);
}
}
示例4: startNewLog
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
private GenerationState<K, V> startNewLog(final GenerationState<K, V> localState) throws IOException {
//create new volatile generation and checkpoint
final File newLog = getNextLogFile();
final VolatileGeneration<K,V> nextVolatileGeneration = new VolatileGeneration<K, V>(newLog, keySerializer, valueSerializer, comparator);
final List<SharedReference<? extends Generation<K,V>>> nextStableGenerations = Lists.newArrayList();
nextStableGenerations.add(localState.volatileGenerationReference.copy());
for (SharedReference<? extends Generation<K, V>> reference : localState.stableGenerationReferences) {
nextStableGenerations.add(reference.copy());
}
final File checkpointDir = getNextCheckpointDir();
checkpointDir.mkdirs();
final GenerationState<K,V> nextState = new GenerationState<K, V>(nextStableGenerations, SharedReference.create(nextVolatileGeneration), checkpointDir);
checkpointGenerationState(nextState, checkpointDir);
//there will be a brief period of time where there is no writable generation, put and delete will block during this time
localState.volatileGeneration.closeWriter();
PosixFileOperations.atomicLink(checkpointDir, new File(root, "latest"));
final SharedReference<GenerationState<K, V>> oldState = Preconditions.checkNotNull(generationState.getAndSet(nextState));
oldState.get().delete();
Closeables2.closeQuietly(oldState, log);
return nextState;
}
示例5: checkpointGenerationState
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
private void checkpointGenerationState(GenerationState<K,V> state, File checkpointDir) throws IOException {
final Map<String, Object> map = new HashMap<String, Object>();
final List<String> stableGenerationNames = new ArrayList<String>();
for (Generation<K,V> generation : state.stableGenerations) {
final File generationPath = generation.getPath();
final String generationName = generationPath.getName();
stableGenerationNames.add(generationName);
PosixFileOperations.link(generationPath, new File(checkpointDir, generationName));
}
map.put("stableGenerations", stableGenerationNames);
final File volatileGenerationPath = state.volatileGeneration.getPath();
final String volatileGenerationName = volatileGenerationPath.getName();
map.put("volatileGeneration", volatileGenerationName);
PosixFileOperations.link(volatileGenerationPath, new File(checkpointDir, volatileGenerationName));
final Yaml yaml = new Yaml();
final String generationStateString = yaml.dump(map);
RandomAccessFile raf = null;
FileChannel channel = null;
try {
raf = new RandomAccessFile(new File(checkpointDir, "state"), "rw");
channel = raf.getChannel();
final byte[] bytes = generationStateString.getBytes(Charsets.UTF_8);
final ByteBuffer buffer = ByteBuffer.wrap(bytes);
while (buffer.remaining() > 0) {
channel.write(buffer);
}
channel.force(true);
} finally {
Closeables2.closeQuietly(channel, log);
Closeables2.closeQuietly(raf, log);
}
}
示例6: finishCompaction
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
private void finishCompaction(final Set<String> compactedGenerations, final List<Generation<K, V>> toCompactGenerations, final Generation<K, V> stableGeneration) throws IOException {
final List<SharedReference<? extends Generation<K,V>>> nextStableGenerations = Lists.newArrayList();
final SharedReference<GenerationState<K, V>> stateReference = Preconditions.checkNotNull(generationState.getCopy());
final GenerationState<K,V> state = stateReference.get();
try {
boolean compactionAdded = false;
for (SharedReference<? extends Generation<K, V>> reference : state.stableGenerationReferences) {
final String name = reference.get().getPath().getName();
if (!compactedGenerations.contains(name)) {
nextStableGenerations.add(reference.copy());
} else {
if (!compactionAdded) {
nextStableGenerations.add(SharedReference.create(stableGeneration));
compactionAdded = true;
}
currentlyCompacting.remove(name);
}
}
final File checkpointDir = getNextCheckpointDir();
checkpointDir.mkdirs();
final GenerationState<K,V> nextState = new GenerationState<K, V>(nextStableGenerations, state.volatileGenerationReference.copy(), checkpointDir);
checkpointGenerationState(nextState, checkpointDir);
PosixFileOperations.atomicLink(checkpointDir, new File(root, "latest"));
final SharedReference<GenerationState<K, V>> oldState = Preconditions.checkNotNull(generationState.getAndSet(nextState));
oldState.get().delete();
Closeables2.closeQuietly(oldState, log);
for (Generation<K, V> generation : toCompactGenerations) {
final long sizeInBytes = generation.sizeInBytes();
generation.delete();
totalGenerationSpace.addAndGet(-sizeInBytes);
}
} finally {
Closeables2.closeQuietly(stateReference, log);
}
}
示例7: tearDown
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
@After
public void tearDown() throws Exception {
PosixFileOperations.rmrf(tmpDir);
}
示例8: checkpoint
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
@Override
public void checkpoint(File checkpointPath) throws IOException {
PosixFileOperations.cplr(indexFile, checkpointPath.toPath());
}
示例9: delete
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
@Override
public void delete() throws IOException {
log.info("deleting " + getPath());
PosixFileOperations.rmrf(getPath());
}
示例10: checkpoint
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
@Override
public void checkpoint(final File checkpointPath) throws IOException {
PosixFileOperations.cplr(file, checkpointPath);
}
示例11: delete
import com.indeed.util.core.shell.PosixFileOperations; //导入依赖的package包/类
public void delete() throws IOException {
log.info("deleting "+path);
PosixFileOperations.rmrf(path);
}