use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class Sampler method dumpToFile.
/**
* Dumps the sampled stacks to file. the collected samples are reset
*
* @param id - id will be added to file name returns the name of the file.
* @return - the file name where the data was persisted or null if there was no data to persist.
* @throws IOException - io issues while persisting data.
*/
@JmxExport(value = "dumpToSpecificFile", description = "save stack samples to file")
@Nullable
// not possible the provided ID is validated for path separators.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public synchronized File dumpToFile(@JmxExport(value = "fileID", description = "the ID that will be part of the file name") @Nullable final String id) throws IOException {
String fileName = filePrefix + CharSequences.validatedFileName(((id == null) ? "" : '_' + id) + '_' + DateTimeFormats.TS_FORMAT.format(Timing.getCurrentTiming().fromNanoTimeToInstant(lastDumpTimeNanos)) + '_' + DateTimeFormats.TS_FORMAT.format(Instant.now()));
File file = new File(fileName);
return dumpToFile(file);
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class JdbcHeartBeat method getLastRunDB.
@JmxExport(description = "The last run time recorded in the DB by this process")
public long getLastRunDB() throws SQLException, InterruptedException {
return jdbc.transactOnConnection((final Connection conn, final long deadlineNanos) -> {
try (PreparedStatement stmt = conn.prepareStatement(selectLastRunSql)) {
stmt.setQueryTimeout(JdbcTemplate.getTimeoutToDeadlineSeconds(deadlineNanos));
stmt.setNString(1, org.spf4j.base.Runtime.PROCESS_ID);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
long result = rs.getLong(1);
if (rs.next()) {
throw new IllegalStateException("Multible beats for same owner " + org.spf4j.base.Runtime.PROCESS_ID);
}
return result;
} else {
return 0L;
}
}
}
}, jdbcTimeoutSeconds, TimeUnit.SECONDS);
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class JdbcSemaphore method releaseDeadOwnerPermits.
/**
* Attempts to release permits for this semaphore owned by dead owners.
*
* @param wishPermits - How many permits we would like to get released.
* @return - the number of permits we actually released.
* @throws SQLException - something went wrong with the db.
* @throws InterruptedException - thrown if thread is interrupted.
*/
@JmxExport(description = "release dead owner permits")
@CheckReturnValue
public int releaseDeadOwnerPermits(@JmxExport(value = "wishPermits", description = "how many we whish to release") final int wishPermits) throws InterruptedException, SQLException {
return jdbc.transactOnConnection((final Connection conn, final long deadlineNanos) -> {
List<OwnerPermits> deadOwnerPermits = getDeadOwnerPermits(conn, deadlineNanos, wishPermits);
int released = 0;
for (OwnerPermits permit : deadOwnerPermits) {
try (PreparedStatement stmt = conn.prepareStatement(deleteDeadOwerRecordSql)) {
String owner = permit.getOwner();
stmt.setNString(1, owner);
stmt.setNString(2, semName);
int nrPermits = permit.getNrPermits();
stmt.setInt(3, nrPermits);
stmt.setQueryTimeout(JdbcTemplate.getTimeoutToDeadlineSeconds(deadlineNanos));
if (stmt.executeUpdate() == 1) {
// I can release! if not somebody else is doing it.
released += nrPermits;
releaseReservations(conn, deadlineNanos, nrPermits);
LOG.warn("Released {} reservations from dead owner {}", nrPermits, owner);
}
}
}
return released;
}, jdbcTimeoutSeconds, TimeUnit.SECONDS);
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class JdbcSemaphore method availablePermits.
@JmxExport(description = "Get the available semaphore permits")
public int availablePermits() throws SQLException, InterruptedException {
return jdbc.transactOnConnection((final Connection conn, final long deadlineNanos) -> {
try (PreparedStatement stmt = conn.prepareStatement(permitsSql)) {
stmt.setNString(1, semName);
stmt.setQueryTimeout(JdbcTemplate.getTimeoutToDeadlineSeconds(deadlineNanos));
try (ResultSet rs = stmt.executeQuery()) {
if (!rs.next()) {
throw new IllegalStateException();
} else {
int result = rs.getInt(1);
if (rs.next()) {
throw new IllegalStateException();
}
return result;
}
}
}
}, jdbcTimeoutSeconds, TimeUnit.SECONDS);
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getMeasurementsAsString.
@JmxExport(description = "measurements as csv")
public String getMeasurementsAsString() {
StringWriter sw = new StringWriter(128);
Map<Object, MeasurementAccumulator> entitiesMeasurements = getEntitiesMeasurements();
MeasurementsInfo info = this.processorTemplate.getInfo();
try {
Csv.writeCsvRow2(sw, "Measured", (Object[]) info.getMeasurementNames());
Csv.writeCsvRow2(sw, "string", (Object[]) info.getMeasurementUnits());
for (Map.Entry<Object, MeasurementAccumulator> entry : entitiesMeasurements.entrySet()) {
Csv.writeCsvElement(entry.getKey().toString(), sw);
sw.write(',');
final long[] measurements = entry.getValue().get();
if (measurements != null) {
Csv.writeCsvRow(sw, measurements);
}
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return sw.toString();
}
Aggregations