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);
}
}
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;
}
}
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;
}
}
Aggregations