use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class CustomStringDeserializer method deserialize.
@Override
public String deserialize(Response response) {
try (InputStream is = response.body()) {
String csv = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
List<String> fields = SPLITTER.splitToList(csv);
Preconditions.checkState(fields.size() == 2);
Preconditions.checkState("mystring".equals(fields.get(0)));
Preconditions.checkState(!Strings.isNullOrEmpty(fields.get(1)));
return fields.get(1);
} catch (IOException e) {
throw new SafeRuntimeException("Failed to serialize payload", e);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class SimulationServer method execute.
@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
Meter perEndpointRequests = MetricNames.requestMeter(simulation.taggedMetrics(), serverName, endpoint);
activeRequests.inc();
perEndpointRequests.mark();
simulation.metricsReporter().report();
for (ServerHandler handler : handlers) {
long beforeNanos = simulation.clock().read();
Optional<ListenableFuture<Response>> maybeResp = handler.maybeExecute(this, endpoint, request);
if (!maybeResp.isPresent()) {
continue;
}
ListenableFuture<Response> resp = maybeResp.get();
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(_ignored -> globalResponses.inc()));
resp.addListener(() -> {
activeRequests.dec();
globalServerTimeNanos.inc(simulation.clock().read() - beforeNanos);
}, DialogueFutures.safeDirectExecutor());
if (log.isDebugEnabled()) {
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(result -> {
log.debug("time={} server={} status={} id={}", Duration.ofNanos(simulation.clock().read()), serverName, result.code(), request != null ? request.headerParams().get(Benchmark.REQUEST_ID_HEADER) : null);
}));
}
return resp;
}
log.error("No handler available for request {}", request);
activeRequests.dec();
return Futures.immediateFailedFuture(new SafeRuntimeException("No handler"));
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class HikariCPConnectionManager method close.
@Override
public synchronized void close() {
try {
switch(state.type) {
case ZERO:
break;
case NORMAL:
if (log.isDebugEnabled()) {
log.debug("Closing connection pool", UnsafeArg.of("connConfig", connConfig), new SafeRuntimeException("Closing connection pool"));
}
state.dataSourcePool.close();
break;
case CLOSED:
break;
}
} finally {
state = new State(StateType.CLOSED, null, null, new Throwable("Hikari pool closed here"));
exec.shutdownNow();
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class KvTableMappingService method readTableMap.
protected BiMap<TableReference, TableReference> readTableMap() {
// TODO (jkong) Remove after PDS-117310 is resolved.
if (log.isTraceEnabled()) {
log.trace("Attempting to read the table mapping from the namespace table.", new SafeRuntimeException("I exist to show you the stack trace"));
}
BiMap<TableReference, TableReference> ret = HashBiMap.create();
try (ClosableIterator<RowResult<Value>> range = rangeScanNamespaceTable()) {
while (range.hasNext()) {
RowResult<Value> row = range.next();
String shortName = PtBytes.toString(row.getColumns().get(AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES).getContents());
TableReference ref = getTableRefFromBytes(row.getRowName());
ret.put(ref, TableReference.createWithEmptyNamespace(shortName));
}
}
// TODO (jkong) Remove after PDS-117310 is resolved.
if (log.isTraceEnabled()) {
log.trace("Successfully read {} entries from the namespace table, to refresh the table map.", SafeArg.of("entriesRead", ret.size()), new SafeRuntimeException("I exist to show you the stack trace"));
}
return ret;
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class ForkedJsonFormat method printToString.
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public static String printToString(Message message) {
try {
StringBuilder text = new StringBuilder();
print(message, text);
return text.toString();
} catch (IOException e) {
throw new SafeRuntimeException("Writing to a StringBuilder threw an IOException (should never happen).", e);
}
}
Aggregations