public static <T> T handleException(Throwable t, RpcExceptionHandler<T> visitor) { Objects.requireNonNull(t); Objects.requireNonNull(visitor); // Attempt to handle the exception directly Optional<T> val = handleExceptionInternal(t, visitor); if (val != null) { return val.orElse(null); } // No match was made, attempt to handle the cause if present final Throwable cause = t.getCause(); if (cause != null) { val = handleExceptionInternal(cause, visitor); if (val != null) { return val.orElse(null); } } // No match for parent or cause return visitor.onUnknown(t); }
@Override public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) { Long ttlInMs = ParameterMap.getKeyedLong(parameters, "ttl", DEFAULT_TTL_IN_MS); if (ttlInMs < 1) { // Use the global default ttlInMs = null; } int messageSize = ParameterMap.getKeyedInteger(parameters, "message-size", DEFAULT_MESSAGE_SIZE); if (messageSize < 0) { messageSize = 0; } // Create the client final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.get().getClient(EchoRpcModule.INSTANCE); // Build the request final OnmsNode node = nodeDao.get().get(svc.getNodeId()); final EchoRequest request = new EchoRequest(); request.setId(System.currentTimeMillis()); request.setMessage(Strings.repeat("*", messageSize)); request.setLocation(node.getLocation().getLocationName()); request.setSystemId(node.getForeignId()); request.setTimeToLiveMs(ttlInMs); try { final EchoResponse response = client.execute(request).get(); final Long responseTime = System.currentTimeMillis() - response.getId(); return PollStatus.available(responseTime.doubleValue()); } catch (InterruptedException|ExecutionException t) { return RpcExceptionUtils.handleException(t, this); } }
return result; } catch (Throwable e) { return RpcExceptionUtils.handleException(e, new RpcExceptionHandler<PollStatus>() { @Override public PollStatus onInterrupted(Throwable cause) {
m_status = CollectionStatus.SUCCEEDED; } catch (InterruptedException|ExecutionException e) { throw RpcExceptionUtils.handleException(e, new RpcExceptionHandler<CollectionException>() { @Override public CollectionException onInterrupted(Throwable t) {
final CollectionException ce = RpcExceptionUtils.handleException(e, new RpcExceptionHandler<CollectionException>() { @Override public CollectionException onInterrupted(Throwable t) {
final CollectionException ce = RpcExceptionUtils.handleException(e, new RpcExceptionHandler<CollectionException>() { @Override public CollectionException onInterrupted(Throwable t) {