Search in sources :

Example 1 with MeasurementStore

use of org.spf4j.perf.MeasurementStore 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)

Example 2 with MeasurementStore

use of org.spf4j.perf.MeasurementStore in project spf4j by zolyfarkas.

the class MultiStore method alocateMeasurements.

@Override
public long alocateMeasurements(final MeasurementsInfo measurement, final int sampleTimeMillis) throws IOException {
    IOException ex = null;
    synchronized (idToIds) {
        long id = infoToId.get(measurement);
        if (id <= 0) {
            long[] ids = new long[stores.length];
            int i = 0;
            for (MeasurementStore store : stores) {
                try {
                    ids[i++] = store.alocateMeasurements(measurement, sampleTimeMillis);
                } catch (IOException e) {
                    if (ex == null) {
                        ex = e;
                    } else {
                        ex = Throwables.suppress(e, ex);
                    }
                }
            }
            if (ex != null) {
                throw ex;
            }
            id = idSeq++;
            infoToId.put(measurement, id);
            idToIds.put(id, ids);
        }
        return id;
    }
}
Also used : IOException(java.io.IOException) MeasurementStore(org.spf4j.perf.MeasurementStore)

Example 3 with MeasurementStore

use of org.spf4j.perf.MeasurementStore in project spf4j by zolyfarkas.

the class MultiStore method saveMeasurements.

@Override
public void saveMeasurements(final long tableId, final long timeStampMillis, final long... measurements) throws IOException {
    IOException ex = null;
    long[] ids;
    synchronized (idToIds) {
        ids = idToIds.get(tableId);
    }
    if (ids == null) {
        throw new IOException("Table id is invalid " + tableId);
    }
    int i = 0;
    for (MeasurementStore store : stores) {
        try {
            store.saveMeasurements(ids[i++], timeStampMillis, measurements);
        } catch (IOException e) {
            if (ex == null) {
                ex = e;
            } else {
                ex = Throwables.suppress(e, ex);
            }
        }
    }
    if (ex != null) {
        throw ex;
    }
}
Also used : IOException(java.io.IOException) MeasurementStore(org.spf4j.perf.MeasurementStore)

Aggregations

MeasurementStore (org.spf4j.perf.MeasurementStore)3 IOException (java.io.IOException)2 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 MultiStore (org.spf4j.perf.impl.ms.MultiStore)1 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)1