Search in sources :

Example 1 with MultiStore

use of org.spf4j.perf.impl.ms.MultiStore in project spf4j by zolyfarkas.

the class RecorderFactory method buildStoreFromConfig.

/**
 * Configuration is a coma separated list of stores:
 * TSDB@/path/to/file.tsdb,TSDB_TXT@/path/to/file.tsdbtxt,GRAPHITE_UDP@1.1.1.1:8080,GRAPHITE_TCP@1.1.1.1:8080
 *
 * @param configuration
 * @return a measurement store.
 */
@Nonnull
// the config is not supplied by a user.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
private static MeasurementStore buildStoreFromConfig(@Nullable final String configuration) throws IOException, ObjectCreationException {
    if (configuration == null || configuration.trim().isEmpty()) {
        return new TSDBMeasurementStore(new File(System.getProperty("spf4j.perf.ms.defaultTsdbFolderPath", System.getProperty("java.io.tmpdir")) + File.separator + CharSequences.validatedFileName(System.getProperty("spf4j.perf.ms.defaultTsdbFileNamePrefix", ManagementFactory.getRuntimeMXBean().getName() + ".tsdb2"))));
    }
    List<String> stores;
    try {
        stores = Csv.readRow(new StringReader(configuration));
    } catch (CsvParseException ex) {
        throw new IllegalArgumentException("Invalid configuration " + configuration, ex);
    }
    final int size = stores.size();
    if (size == 1) {
        return fromString(stores.get(0));
    } else {
        MeasurementStore[] mstores = new MeasurementStore[size];
        int i = 0;
        for (String config : stores) {
            mstores[i] = fromString(config);
            i++;
        }
        return new MultiStore(mstores);
    }
}
Also used : CsvParseException(org.spf4j.io.csv.CsvParseException) StringReader(java.io.StringReader) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) MeasurementStore(org.spf4j.perf.MeasurementStore) MultiStore(org.spf4j.perf.impl.ms.MultiStore) File(java.io.File) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 StringReader (java.io.StringReader)1 Nonnull (javax.annotation.Nonnull)1 CsvParseException (org.spf4j.io.csv.CsvParseException)1 MeasurementStore (org.spf4j.perf.MeasurementStore)1 MultiStore (org.spf4j.perf.impl.ms.MultiStore)1 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)1