/** * Gets the request identifier of this command. * * @return The identifier. * @throws IllegalStateException if this command is invalid. */ public String getRequestId() { if (isValid()) { return requestId; } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets this command's reply-to-id. * * @return The identifier. * @throws IllegalStateException if this command is invalid. */ public String getReplyToId() { if (isValid()) { return replyToId; } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the ID to use for correlating a response to this command. * * @return The identifier. * @throws IllegalStateException if this command is invalid. */ public String getCorrelationId() { if (isValid()) { return correlationId; } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the tenant that the device belongs to. * * @return The tenant identifier. * @throws IllegalStateException if this command is invalid. */ public String getTenant() { if (isValid()) { return tenantId; } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the device's identifier. * * @return The identifier. * @throws IllegalStateException if this command is invalid. */ public String getDeviceId() { if (isValid()) { return deviceId; } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the name of this command. * * @return The name. * @throws IllegalStateException if this command is invalid. */ public String getName() { if (isValid()) { return message.getSubject(); } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the payload of this command. * * @return The message payload or {@code null} if the command message contains no payload. * @throws IllegalStateException if this command is invalid. */ public Buffer getPayload() { if (isValid()) { return MessageHelper.getPayload(message); } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the type of this command's payload. * * @return The content type or {@code null} if not set. * @throws IllegalStateException if this command is invalid. */ public String getContentType() { if (isValid()) { return message.getContentType(); } else { throw new IllegalStateException("command is invalid"); } }
/** * Gets the application properties of a message if any. * * @return The application properties. * @throws IllegalStateException if this command is invalid. */ public Map<String, Object> getApplicationProperties() { if (isValid()) { if (message.getApplicationProperties() == null) { return null; } return message.getApplicationProperties().getValue(); } else { throw new IllegalStateException("command is invalid"); } } /**
if (command.isValid()) { TracingHelper.TAG_CORRELATION_ID.set(currentSpan, command.getCorrelationId()); items.put("reply-to", command.getCommandMessage().getReplyTo());
if (command.isValid()) { if (responseReady.isComplete()) {
if (command.isValid()) { if (responseReady.isComplete()) {
private Future<MessageConsumer> createCommandConsumer(final MqttEndpoint mqttEndpoint, final CommandSubscription sub, final CommandHandler<T> cmdHandler) { // if a device does not specify a keep alive in its CONNECT packet then // the default value of the CommandConnection will be used final long livenessCheckInterval = mqttEndpoint.keepAliveTimeSeconds() * 1000 / 2; return getCommandConnection().createCommandConsumer( sub.getTenant(), sub.getDeviceId(), commandContext -> { Tags.COMPONENT.set(commandContext.getCurrentSpan(), getTypeName()); final Command command = commandContext.getCommand(); if (command.isValid()) { onCommandReceived(mqttEndpoint, sub, commandContext, cmdHandler); } else { // issue credit so that application(s) can send the next command commandContext.reject(new ErrorCondition(Constants.AMQP_BAD_REQUEST, "malformed command message"), 1); } }, remoteClose -> {}, livenessCheckInterval); }
private Future<MessageConsumer> createCommandConsumer(final MqttEndpoint mqttEndpoint, final CommandSubscription sub) { // if a device does not specify a keep alive in its CONNECT packet then // the default value of the CommandConnection will be used final long livenessCheckInterval = mqttEndpoint.keepAliveTimeSeconds() * 1000 / 2; return getCommandConnection().createCommandConsumer( sub.getTenant(), sub.getDeviceId(), commandContext -> { Tags.COMPONENT.set(commandContext.getCurrentSpan(), getTypeName()); final Command command = commandContext.getCommand(); if (command.isValid()) { onCommandReceived(mqttEndpoint, sub, commandContext); } else { // issue credit so that application(s) can send the next command commandContext.reject(new ErrorCondition(Constants.AMQP_BAD_REQUEST, "malformed command message"), 1); } }, remoteClose -> {}, livenessCheckInterval); }
private Future<MessageConsumer> createCommandConsumer( final ProtonSender sender, final ResourceIdentifier sourceAddress) { return getCommandConnection().createCommandConsumer( sourceAddress.getTenantId(), sourceAddress.getResourceId(), commandContext -> { Tags.COMPONENT.set(commandContext.getCurrentSpan(), getTypeName()); final Command command = commandContext.getCommand(); if (!command.isValid()) { final Exception ex = new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "malformed command message"); commandContext.reject(AmqpContext.getErrorCondition(ex), 1); } else if (!sender.isOpen()) { commandContext.release(1); } else { onCommandReceived(sender, commandContext); } }, closeHandler -> {}, DEFAULT_COMMAND_CONSUMER_CHECK_INTERVAL_MILLIS); }