@Override protected Result check() throws Exception { final Set<String> threads = vm.deadlockedThreads(); if (threads.isEmpty()) { return Result.healthy(); } final StringBuilder builder = new StringBuilder("Deadlocked threads detected:\n"); for (String thread : threads) { builder.append(thread).append('\n'); } return Result.unhealthy(builder.toString()); } }
/** * Returns an unhealthy {@link Result} with a formatted message. * * Message formatting follows the same rules as * {@link String#format(String, Object...)}. * * @param message a message format * @param args the arguments apply to the message format * @return an unhealthy {@link Result} with an additional message * @see String#format(String, Object...) */ public static Result unhealthy(String message, Object... args) { return unhealthy(String.format(message, args)); }
@Override public Result check() { Handle handle = null; try { handle = dbi.open(); final int test = handle.createQuery("select 1 as test").map(IntegerMapper.FIRST).first(); if (test == 1) { return Result.healthy(); } else { return Result.unhealthy(String.format("%s != 1", test)); } } catch (Throwable t) { return Result.unhealthy(t.toString()); } finally { if (handle != null) { handle.close(); } } }
/** * Executes the health check, catching and handling any exceptions raised by {@link #check()}. * * @return if the component is healthy, a healthy {@link Result}; otherwise, an unhealthy * {@link Result} with a descriptive error message or exception */ public Result execute() { try { return check(); } catch (Error e) { throw e; } catch (Throwable e) { return Result.unhealthy(e); } } }
@Override protected Result check() throws Exception { try { gitHubApi.getOrg(organization); return Result.healthy(); } catch (Exception e) { return Result.unhealthy(e); } } }