use of java.io.FilenameFilter in project druid by druid-io.
the class AppenderatorImpl method bootstrapSinksFromDisk.
/**
* Populate "sinks" and "sinkTimeline" with committed segments, and announce them with the segmentAnnouncer.
*
* @return persisted commit metadata
*/
private Object bootstrapSinksFromDisk() {
Preconditions.checkState(sinks.isEmpty(), "Already bootstrapped?!");
final File baseDir = tuningConfig.getBasePersistDirectory();
if (!baseDir.exists()) {
return null;
}
final File[] files = baseDir.listFiles();
if (files == null) {
return null;
}
final File commitFile = computeCommitFile();
final Committed committed;
try {
if (commitFile.exists()) {
committed = objectMapper.readValue(commitFile, Committed.class);
} else {
committed = Committed.nil();
}
} catch (Exception e) {
throw new ISE(e, "Failed to read commitFile: %s", commitFile);
}
log.info("Loading sinks from[%s]: %s", baseDir, committed.getHydrants().keySet());
for (File sinkDir : files) {
final File identifierFile = new File(sinkDir, IDENTIFIER_FILE_NAME);
if (!identifierFile.isFile()) {
// No identifier in this sinkDir; it must not actually be a sink directory. Skip it.
continue;
}
try {
final SegmentIdentifier identifier = objectMapper.readValue(new File(sinkDir, "identifier.json"), SegmentIdentifier.class);
final int committedHydrants = committed.getCommittedHydrants(identifier.getIdentifierAsString());
if (committedHydrants <= 0) {
log.info("Removing uncommitted sink at [%s]", sinkDir);
FileUtils.deleteDirectory(sinkDir);
continue;
}
// To avoid reading and listing of "merged" dir and other special files
final File[] sinkFiles = sinkDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String fileName) {
return !(Ints.tryParse(fileName) == null);
}
});
Arrays.sort(sinkFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return Ints.compare(Integer.parseInt(o1.getName()), Integer.parseInt(o2.getName()));
}
});
List<FireHydrant> hydrants = Lists.newArrayList();
for (File hydrantDir : sinkFiles) {
final int hydrantNumber = Integer.parseInt(hydrantDir.getName());
if (hydrantNumber >= committedHydrants) {
log.info("Removing uncommitted segment at [%s]", hydrantDir);
FileUtils.deleteDirectory(hydrantDir);
} else {
log.info("Loading previously persisted segment at [%s]", hydrantDir);
if (hydrantNumber != hydrants.size()) {
throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
}
hydrants.add(new FireHydrant(new QueryableIndexSegment(identifier.getIdentifierAsString(), indexIO.loadIndex(hydrantDir)), hydrantNumber));
}
}
// Make sure we loaded enough hydrants.
if (committedHydrants != hydrants.size()) {
throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
}
Sink currSink = new Sink(identifier.getInterval(), schema, identifier.getShardSpec(), identifier.getVersion(), tuningConfig.getMaxRowsInMemory(), tuningConfig.isReportParseExceptions(), hydrants);
sinks.put(identifier, currSink);
sinkTimeline.add(currSink.getInterval(), currSink.getVersion(), identifier.getShardSpec().createChunk(currSink));
segmentAnnouncer.announceSegment(currSink.getSegment());
} catch (IOException e) {
log.makeAlert(e, "Problem loading sink[%s] from disk.", schema.getDataSource()).addData("sinkDir", sinkDir).emit();
}
}
// Make sure we loaded all committed sinks.
final Set<String> loadedSinks = Sets.newHashSet(Iterables.transform(sinks.keySet(), new Function<SegmentIdentifier, String>() {
@Override
public String apply(SegmentIdentifier input) {
return input.getIdentifierAsString();
}
}));
final Set<String> missingSinks = Sets.difference(committed.getHydrants().keySet(), loadedSinks);
if (!missingSinks.isEmpty()) {
throw new ISE("Missing committed sinks [%s]", Joiner.on(", ").join(missingSinks));
}
return committed.getMetadata();
}
use of java.io.FilenameFilter in project intellij-leiningen-plugin by derkork.
the class LeiningenRunnerSettings method getRealLeiningenJar.
/**
* Returns the real leiningen jar.
* @return the real leiningen jar
*/
@NotNull
public String getRealLeiningenJar() {
if (overrideLeiningenJar) {
return leiningenJar;
}
// first check LEIN_JAR env variable
String env = System.getenv("LEIN_JAR");
if (!StringUtil.isEmpty(env)) {
return env;
}
// ok it's not set, look for a file below the lein home
File leinHome = new File(getRealLeiningenHome());
if (leinHome.exists() && leinHome.isDirectory()) {
File selfInstalls = new File(leinHome, "self-installs");
if (selfInstalls.exists() && selfInstalls.isDirectory()) {
File[] files = selfInstalls.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("leiningen-") && name.endsWith("-standalone.jar");
}
});
if (files.length > 0) {
return files[0].getPath();
}
}
}
// fallback
return "leiningen-standalone.jar";
}
use of java.io.FilenameFilter in project che by eclipse.
the class InstallExtension method main.
public static void main(String[] args) throws IOException {
for (String arg : args) {
if (arg.startsWith(EXT_DIR_PARAMETER)) {
extDirPath = Paths.get(arg.substring(EXT_DIR_PARAMETER.length()));
} else if (arg.startsWith(EXT_RESOURCES_DIR_PARAMETER)) {
final Path extResourcesDirPath = Paths.get(arg.substring(EXT_RESOURCES_DIR_PARAMETER.length()));
final String tempDirName = "temp";
extResourcesWorkDirPath = extResourcesDirPath.resolve(tempDirName);
// delete working directory from previous build if it exist
IoUtil.deleteRecursive(extResourcesWorkDirPath.toFile());
Files.createDirectory(extResourcesWorkDirPath);
IoUtil.copy(extResourcesDirPath.toFile(), extResourcesWorkDirPath.toFile(), new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !(tempDirName.equals(name));
}
});
} else {
System.err.println("Unknown flag: " + arg);
System.exit(1);
}
}
List<Extension> extensions = findExtensionsByPath(extDirPath);
for (Extension extension : extensions) {
final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile();
final Model model = Model.readFrom(pom);
model.dependencies().add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion));
model.writeTo(pom);
// Add GWT module if there is one
if (extension.gwtModuleName != null) {
final Path ideGwtXmlPath = IoUtil.findFile(IDE_GWT_XML_FILE_NAME, extResourcesWorkDirPath.toFile()).toPath();
GwtXmlUtils.inheritGwtModule(ideGwtXmlPath, extension.gwtModuleName);
}
}
}
use of java.io.FilenameFilter in project jetty.project by eclipse.
the class HpackPerfTest method runStories.
private void runStories(int maxDynamicTableSize) throws Exception {
// Find files
File data = MavenTestingUtils.getTestResourceDir("data");
String[] files = data.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("story_");
}
});
// Parse JSON
Map<String, Object>[] stories = new Map[files.length];
int i = 0;
for (String story : files) stories[i++] = (Map<String, Object>) JSON.parse(new FileReader(new File(data, story)));
ByteBuffer buffer = BufferUtil.allocate(256 * 1024);
// Encode all the requests
encodeStories(buffer, stories, "request");
// clear table
BufferUtil.clearToFill(buffer);
BufferUtil.flipToFlush(buffer, 0);
// Encode all the responses
encodeStories(buffer, stories, "response");
}
use of java.io.FilenameFilter in project jetty.project by eclipse.
the class FileSessionDataStore method doGetExpired.
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(final Set<String> candidates) {
final long now = System.currentTimeMillis();
HashSet<String> expired = new HashSet<String>();
File[] files = _storeDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (dir != _storeDir)
return false;
//dir may contain files that don't match our naming pattern
int index = name.indexOf('_');
if (index < 0)
return false;
try {
long expiry = Long.parseLong(name.substring(0, index));
return expiry > 0 && expiry < now;
} catch (NumberFormatException e) {
return false;
}
}
});
if (files != null) {
for (File f : files) {
expired.add(getIdFromFile(f));
}
}
//longer exist and they should be expired
for (String c : candidates) {
if (!expired.contains(c)) {
//check if the file exists
File f = getFile(_storeDir, c);
if (f == null || !f.exists())
expired.add(c);
}
}
return expired;
}
Aggregations