当前位置: 首页>>代码示例>>Java>>正文


Java AWSIotMessage类代码示例

本文整理汇总了Java中com.amazonaws.services.iot.client.AWSIotMessage的典型用法代码示例。如果您正苦于以下问题:Java AWSIotMessage类的具体用法?Java AWSIotMessage怎么用?Java AWSIotMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AWSIotMessage类属于com.amazonaws.services.iot.client包,在下文中一共展示了AWSIotMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runCommand

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public String runCommand(Command command, AWSIotMessage request, long commandTimeout, boolean isAsync)
        throws AWSIotException, AWSIotTimeoutException {
    String commandId = newCommandId();
    appendCommandId(request, commandId);

    request.setTopic(getTopic(command, null));
    AwsIotDeviceCommand deviceCommand = new AwsIotDeviceCommand(this, command, commandId, request, commandTimeout,
            isAsync);

    pendingCommands.put(commandId, deviceCommand);
    LOGGER.fine("Number of pending commands: " + pendingCommands.size());

    try {
        deviceCommand.put(device);
    } catch (AWSIotException e) {
        // if exception happens during publish, we remove the command
        // from the pending list as we'll never get ack for it.
        pendingCommands.remove(commandId);
        throw e;
    }

    return deviceCommand.get(device);
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:24,代码来源:AwsIotDeviceCommandManager.java

示例2: onCommandAck

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public void onCommandAck(AWSIotMessage response) {
    if (response == null || response.getTopic() == null) {
        return;
    }

    AwsIotDeviceCommand command = getPendingCommand(response);
    if (command == null) {
        LOGGER.warning("Unknown command received from topic " + response.getTopic());
        return;
    }

    boolean success = response.getTopic().endsWith(COMMAND_ACK_PATHS.get(CommandAck.ACCEPTED));
    if (!success
            && (Command.DELETE.equals(command.getCommand()) && AWSIotDeviceErrorCode.NOT_FOUND.equals(command
                    .getErrorCode()))) {
        // Ignore empty document error (NOT_FOUND) for delete command
        success = true;
    }

    if (success) {
        command.setResponse(response);
        command.onSuccess();
    } else {
        command.onFailure();
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:27,代码来源:AwsIotDeviceCommandManager.java

示例3: appendCommandId

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
private void appendCommandId(AWSIotMessage message, String commandId) throws AWSIotException {
    String payload = message.getStringPayload();
    if (payload == null) {
        payload = "{}";
    }

    try {
        JsonNode jsonNode = objectMapper.readTree(payload);
        if (!jsonNode.isObject()) {
            throw new AWSIotException("Invalid Json string in payload");
        }
        ((ObjectNode) jsonNode).put(COMMAND_ID_FIELD, commandId);

        message.setStringPayload(jsonNode.toString());
    } catch (IOException e) {
        throw new AWSIotException(e);
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:19,代码来源:AwsIotDeviceCommandManager.java

示例4: onFailure

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void onFailure(IMqttToken token, Throwable cause) {
    final AWSIotMessage message = (AWSIotMessage) token.getUserContext();
    if (message == null) {
        LOGGER.warning("Request failed: " + token.getException());
        return;
    }

    LOGGER.warning("Request failed for topic " + message.getTopic() + ": " + token.getException());
    client.scheduleTask(new Runnable() {
        @Override
        public void run() {
            message.onFailure();
        }
    });
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:17,代码来源:AwsIotMqttMessageListener.java

示例5: publishMessage

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void publishMessage(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException {
    String topic = message.getTopic();
    MqttMessage mqttMessage = new MqttMessage(message.getPayload());
    mqttMessage.setQos(message.getQos().getValue());

    try {
        mqttClient.publish(topic, mqttMessage, message, messageListener);
    } catch (MqttException e) {
        if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) {
            throw new AwsIotRetryableException(e);
        } else {
            throw new AWSIotException(e);
        }
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:17,代码来源:AwsIotMqttConnection.java

示例6: buildMqttConnectOptions

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
private MqttConnectOptions buildMqttConnectOptions(AbstractAwsIotClient client, SocketFactory socketFactory) {
    MqttConnectOptions options = new MqttConnectOptions();

    options.setSocketFactory(socketFactory);
    options.setCleanSession(true);
    options.setConnectionTimeout(client.getConnectionTimeout() / 1000);
    options.setKeepAliveInterval(client.getKeepAliveInterval() / 1000);

    Set<String> serverUris = getServerUris();
    if (serverUris != null && !serverUris.isEmpty()) {
        String[] uriArray = new String[serverUris.size()];
        serverUris.toArray(uriArray);
        options.setServerURIs(uriArray);
    }

    if (client.getWillMessage() != null) {
        AWSIotMessage message = client.getWillMessage();

        options.setWill(message.getTopic(), message.getPayload(), message.getQos().getValue(), false);
    }

    return options;
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:24,代码来源:AwsIotMqttConnection.java

示例7: dispatch

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public void dispatch(final AWSIotMessage message) {
    boolean matches = false;

    for (String topicFilter : subscriptions.keySet()) {
        if (topicFilterMatch(topicFilter, message.getTopic())) {
            final AWSIotTopic topic = subscriptions.get(topicFilter);
            scheduleTask(new Runnable() {
                @Override
                public void run() {
                    topic.onMessage(message);
                }
            });
            matches = true;
        }
    }

    if (!matches) {
        LOGGER.warning("Unexpected message received from topic " + message.getTopic());
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:21,代码来源:AbstractAwsIotClient.java

示例8: main

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, AWSIotException {
    CommandArguments arguments = CommandArguments.parse(args);
    initClient(arguments);

    awsIotClient.setWillMessage(new AWSIotMessage("client/disconnect", AWSIotQos.QOS0, awsIotClient.getClientId()));

    String thingName = arguments.getNotNull("thingName", SampleUtil.getConfig("thingName"));
    ConnectedWindow connectedWindow = new ConnectedWindow(thingName);

    awsIotClient.attach(connectedWindow);
    awsIotClient.connect();

    // Delete existing document if any
    connectedWindow.delete();

    AWSIotConnectionStatus status = AWSIotConnectionStatus.DISCONNECTED;
    while (true) {
        AWSIotConnectionStatus newStatus = awsIotClient.getConnectionStatus();
        if (!status.equals(newStatus)) {
            System.out.println(System.currentTimeMillis() + " Connection status changed to " + newStatus);
            status = newStatus;
        }

        Thread.sleep(1000);
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:27,代码来源:ShadowSample.java

示例9: onMessage

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void onMessage(AWSIotMessage message) {
	String messageId = UUID.randomUUID().toString();
	
	MessageNode node = new MessageNode(messagesNode, messageId, message.getPayload());
	messagesNode.addChildren(node);
}
 
开发者ID:awslabs,项目名称:aws-iot-fuse,代码行数:8,代码来源:MessageListener.java

示例10: AwsIotDeviceCommand

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public AwsIotDeviceCommand(AwsIotDeviceCommandManager commandManager, Command command, String commandId,
        AWSIotMessage request, long commandTimeout, boolean isAsync) {
    super(request, commandTimeout, isAsync);
    this.commandManager = commandManager;
    this.command = command;
    this.commandId = commandId;
    this.requestSent = false;
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:9,代码来源:AwsIotDeviceCommand.java

示例11: runCommandSync

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
public String runCommandSync(Command command, AWSIotMessage request) throws AWSIotException {
    try {
        return runCommand(command, request, 0, false);
    } catch (AWSIotTimeoutException e) {
        // We shouldn't get timeout exception because timeout is 0
        throw new AwsIotRuntimeException(e);
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:9,代码来源:AwsIotDeviceCommandManager.java

示例12: getPendingCommand

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
private AwsIotDeviceCommand getPendingCommand(AWSIotMessage message) {
    String payload = message.getStringPayload();
    if (payload == null) {
        return null;
    }

    try {
        JsonNode jsonNode = objectMapper.readTree(payload);
        if (!jsonNode.isObject()) {
            return null;
        }

        JsonNode node = jsonNode.get(COMMAND_ID_FIELD);
        if (node == null) {
            return null;
        }

        String commandId = node.textValue();
        AwsIotDeviceCommand command = pendingCommands.remove(commandId);
        if (command == null) {
            return null;
        }

        node = jsonNode.get(ERROR_CODE_FIELD);
        if (node != null) {
            command.setErrorCode(AWSIotDeviceErrorCode.valueOf(node.longValue()));
        }

        node = jsonNode.get(ERROR_MESSAGE_FIELD);
        if (node != null) {
            command.setErrorMessage(node.textValue());
        }

        return command;
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:39,代码来源:AwsIotDeviceCommandManager.java

示例13: onSuccess

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void onSuccess(IMqttToken token) {
    final AWSIotMessage message = (AWSIotMessage) token.getUserContext();
    if (message == null) {
        return;
    }

    boolean forceFailure = false;
    if (token.getResponse() instanceof MqttSuback) {
        MqttSuback subAck = (MqttSuback) token.getResponse();
        int qos[] = subAck.getGrantedQos();
        for (int i = 0; i < qos.length; i++) {
            if (qos[i] == SUB_ACK_RETURN_CODE_FAILURE) {
                LOGGER.warning("Request failed: likely due to too many subscriptions or policy violations");
                forceFailure = true;
                break;
            }
        }
    }

    final boolean isSuccess = !forceFailure;
    client.scheduleTask(new Runnable() {
        @Override
        public void run() {
            if (isSuccess) {
                message.onSuccess();
            } else {
                message.onFailure();
            }
        }
    });
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:33,代码来源:AwsIotMqttMessageListener.java

示例14: subscribeTopic

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void subscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException {
    try {
        mqttClient.subscribe(message.getTopic(), message.getQos().getValue(), message, messageListener);
    } catch (MqttException e) {
        if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) {
            throw new AwsIotRetryableException(e);
        } else {
            throw new AWSIotException(e);
        }
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:13,代码来源:AwsIotMqttConnection.java

示例15: unsubscribeTopic

import com.amazonaws.services.iot.client.AWSIotMessage; //导入依赖的package包/类
@Override
public void unsubscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException {
    try {
        mqttClient.unsubscribe(message.getTopic(), message, messageListener);
    } catch (MqttException e) {
        if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) {
            throw new AwsIotRetryableException(e);
        } else {
            throw new AWSIotException(e);
        }
    }
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:13,代码来源:AwsIotMqttConnection.java


注:本文中的com.amazonaws.services.iot.client.AWSIotMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。