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(); }
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()); } }
@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 } } }
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(); }
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()); } }
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); } }
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); } }
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); }
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); } }
public void subscribe(AWSIotTopic topic, long timeout, boolean blocking) throws AWSIotException, AWSIotTimeoutException { _subscribe(topic, timeout, !blocking); }
public void subscribe(AWSIotTopic topic) throws AWSIotException { subscribe(topic, 0); }
public void unsubscribe(AWSIotTopic topic) throws AWSIotException { unsubscribe(topic, 0); }