Search in sources :

Example 11 with FilenameFilter

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();
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) IOException(java.io.IOException) IndexSizeExceededException(io.druid.segment.incremental.IndexSizeExceededException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FilenameFilter(java.io.FilenameFilter) Function(com.google.common.base.Function) Sink(io.druid.segment.realtime.plumber.Sink) ISE(io.druid.java.util.common.ISE) FireHydrant(io.druid.segment.realtime.FireHydrant) File(java.io.File)

Example 12 with FilenameFilter

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";
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with FilenameFilter

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);
        }
    }
}
Also used : Path(java.nio.file.Path) FilenameFilter(java.io.FilenameFilter) Model(org.eclipse.che.ide.maven.tools.Model) Dependency(org.eclipse.che.ide.maven.tools.Dependency) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 14 with FilenameFilter

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");
}
Also used : FilenameFilter(java.io.FilenameFilter) FileReader(java.io.FileReader) File(java.io.File) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 15 with FilenameFilter

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;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

FilenameFilter (java.io.FilenameFilter)354 File (java.io.File)350 IOException (java.io.IOException)87 ArrayList (java.util.ArrayList)61 Test (org.junit.Test)49 URL (java.net.URL)19 RandomAccessFile (java.io.RandomAccessFile)18 List (java.util.List)17 HashSet (java.util.HashSet)15 FileOutputStream (java.io.FileOutputStream)14 MalformedURLException (java.net.MalformedURLException)12 FileFilter (java.io.FileFilter)11 FileNotFoundException (java.io.FileNotFoundException)11 TestClient (org.syncany.tests.util.TestClient)11 FileWriter (java.io.FileWriter)10 HashMap (java.util.HashMap)10 ZipFile (java.util.zip.ZipFile)10 BufferedWriter (java.io.BufferedWriter)9 FileInputStream (java.io.FileInputStream)9 FileReader (java.io.FileReader)9