Java 类com.amazonaws.services.iot.client.AWSIotTopic 实例源码

项目:aws-iot-device-sdk-java    文件:AbstractAwsIotDevice.java   
public void activate() throws AWSIotException {
    stopSync();

    for (String topic : getDeviceTopics()) {
        AWSIotTopic awsIotTopic;

        if (commandManager.isDeltaTopic(topic)) {
            awsIotTopic = new AwsIotDeviceDeltaListener(topic, shadowUpdateQos, this);
        } else {
            awsIotTopic = new AwsIotDeviceCommandAckListener(topic, methodAckQos, this);
        }

        client.subscribe(awsIotTopic, client.getServerAckTimeout());
    }

    startSync();
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
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());
    }
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
@Override
public void onConnectionSuccess() {
    LOGGER.info("Client connection active: " + clientId);

    try {
        // resubscribe all the subscriptions
        for (AWSIotTopic topic : subscriptions.values()) {
            subscribe(topic, serverAckTimeout);
        }

        // start device sync
        for (AbstractAwsIotDevice device : devices.values()) {
            device.activate();
        }
    } catch (AWSIotException e) {
        // connection couldn't be fully recovered, disconnecting
        LOGGER.warning("Failed to complete subscriptions while client is active, will disconnect");
        try {
            connection.disconnect(null);
        } catch (AWSIotException de) {
            // ignore disconnect errors
        }
    }
}
项目:aws-iot-device-sdk-java    文件:PublishSubscribeSample.java   
public static void main(String args[]) throws InterruptedException, AWSIotException, AWSIotTimeoutException {
    CommandArguments arguments = CommandArguments.parse(args);
    initClient(arguments);

    awsIotClient.connect();

    AWSIotTopic topic = new TestTopicListener(TestTopic, TestTopicQos);
    awsIotClient.subscribe(topic, true);

    Thread blockingPublishThread = new Thread(new BlockingPublisher(awsIotClient));
    Thread nonBlockingPublishThread = new Thread(new NonBlockingPublisher(awsIotClient));

    blockingPublishThread.start();
    nonBlockingPublishThread.start();

    blockingPublishThread.join();
    nonBlockingPublishThread.join();
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotDevice.java   
public void deactivate() throws AWSIotException {
    stopSync();

    commandManager.onDeactivate();

    for (String topic : getDeviceTopics()) {
        deviceSubscriptions.put(topic, false);

        AWSIotTopic awsIotTopic = new AWSIotTopic(topic);
        client.unsubscribe(awsIotTopic, client.getServerAckTimeout());
    }
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void subscribe(AWSIotTopic topic, boolean blocking) throws AWSIotException {
    try {
        _subscribe(topic, 0, !blocking);
    } catch (AWSIotTimeoutException e) {
        // We shouldn't get timeout exception because timeout is 0
        throw new AwsIotRuntimeException(e);
    }
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void subscribe(AWSIotTopic topic, long timeout) throws AWSIotException {
    try {
        _subscribe(topic, timeout, true);
    } catch (AWSIotTimeoutException e) {
        // We shouldn't get timeout exception because it's asynchronous call
        throw new AwsIotRuntimeException(e);
    }
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
private void _subscribe(AWSIotTopic topic, long timeout, boolean async)
        throws AWSIotException, AWSIotTimeoutException {
    AwsIotCompletion completion = new AwsIotCompletion(topic, timeout, async);
    connection.subscribe(completion);
    completion.get(this);

    subscriptions.put(topic.getTopic(), topic);
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void unsubscribe(AWSIotTopic topic, long timeout) throws AWSIotException {
    if (subscriptions.remove(topic.getTopic()) == null) {
        return;
    }

    AwsIotCompletion completion = new AwsIotCompletion(topic, timeout, true);
    connection.unsubscribe(completion);
    try {
        completion.get(this);
    } catch (AWSIotTimeoutException e) {
        // We shouldn't get timeout exception because it's asynchronous call
        throw new AwsIotRuntimeException(e);
    }
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void subscribe(AWSIotTopic topic, long timeout, boolean blocking)
        throws AWSIotException, AWSIotTimeoutException {
    _subscribe(topic, timeout, !blocking);
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void subscribe(AWSIotTopic topic) throws AWSIotException {
    subscribe(topic, 0);
}
项目:aws-iot-device-sdk-java    文件:AbstractAwsIotClient.java   
public void unsubscribe(AWSIotTopic topic) throws AWSIotException {
    unsubscribe(topic, 0);
}