/** * Settles the command message with the <em>rejected</em> outcome * and flows credit to the peer. * <p> * This method also finishes the OpenTracing span returned by * {@link #getCurrentSpan()}. * * @param errorCondition The error condition to send in the disposition frame (may be {@code null}). * @param credit The number of credits to flow to the peer. * @throws IllegalArgumentException if credit is negative. */ public void reject(final ErrorCondition errorCondition, final int credit) { final Rejected rejected = new Rejected(); final Map<String, Object> items = new HashMap<>(2); items.put(Fields.EVENT, "rejected command for device"); if (errorCondition != null) { rejected.setError(errorCondition); Optional.ofNullable(errorCondition.getDescription()).ifPresent(s -> items.put(Fields.MESSAGE, s)); } TracingHelper.logError(currentSpan, items); delivery.disposition(rejected, true); if (credit > 0) { flow(credit); } currentSpan.finish(); }
/** * Settles the command message with the <em>accepted</em> outcome * and flows credit to the peer. * <p> * This method also finishes the OpenTracing span returned by * {@link #getCurrentSpan()}. * * @param credit The number of credits to flow to the peer. * @throws IllegalArgumentException if credit is negative. */ public void accept(final int credit) { if (credit < 0) { throw new IllegalArgumentException("credit must be >= 0"); } LOG.trace("accepting command message [{}]", getCommand()); ProtonHelper.accepted(delivery, true); currentSpan.log("accepted command for device"); if (credit > 0) { flow(credit); } currentSpan.finish(); }
/** * Settles the command message with the <em>released</em> outcome * and flows credit to the peer. * <p> * This method also finishes the OpenTracing span returned by * {@link #getCurrentSpan()}. * * @param credit The number of credits to flow to the peer. * @throws IllegalArgumentException if credit is negative. */ public void release(final int credit) { if (credit < 0) { throw new IllegalArgumentException("credit must be >= 0"); } ProtonHelper.released(delivery, true); currentSpan.log("released command for device"); currentSpan.log(Tags.ERROR.getKey()); if (credit > 0) { flow(credit); } currentSpan.finish(); }