public void connect() throws Exception { this.next.connect().await(); }
public void disconnect() throws Exception { this.next.disconnect().await(); }
public void publish(final UTF8Buffer topic, final Buffer payload, final QoS qos, final boolean retain) throws Exception { this.next.publish(topic, payload, qos, retain).await(); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (connection != null) { try { connection.disconnect().await(); connection.kill().await(); } catch (ShutdownException e) { LOGGER.info("Dispatcher has already been shut down."); } catch (Exception e) { LOGGER.error("Error shutting down MQTT device event receiver.", e); } } super.stop(monitor); }
public Message receive() throws Exception { return this.next.receive().await(); }
public void kill() throws Exception { this.next.kill().await(); }
public byte[] subscribe(final Topic[] topics) throws Exception { return this.next.subscribe(topics).await(); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (executor != null) { executor.shutdownNow(); } if (connection != null) { try { connection.disconnect().await(); connection.kill().await(); } catch (ShutdownException e) { LOGGER.info("Dispatcher has already been shut down."); } catch (Exception e) { LOGGER.error("Error shutting down MQTT device event receiver.", e); } } super.stop(monitor); }
/** * @return null if the receive times out. */ public Message receive(long amount, TimeUnit unit) throws Exception { Future<Message> receive = this.next.receive(); try { Message message = receive.await(amount, unit); if( message!=null ) { message.blocking = true; } return message; } catch (TimeoutException e) { // Put it back on the queue.. receive.then(new Callback<Message>() { public void onSuccess(final Message value) { next.putBackMessage(value); } public void onFailure(Throwable value) { } }); return null; } }
public void kill() throws Exception { this.next.kill().await(); }
public byte[] subscribe(final Topic[] topics) throws Exception { return this.next.subscribe(topics).await(); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { // Stop multicaster if configured. if (multicaster != null) { multicaster.lifecycleStop(monitor); } // Stop route builder if configured. if (routeBuilder != null) { routeBuilder.lifecycleStop(monitor); } if (connection != null) { try { connection.disconnect(); connection.kill(); } catch (Exception e) { LOGGER.error("Error shutting down MQTT device event receiver.", e); } } if (queue != null) { queue.suspend(); } super.stop(monitor); }
public Future<Void> publish(final String topic, final byte[] payload, final QoS qos, final boolean retain) { return publish(utf8(topic), new Buffer(payload), qos, retain); }
public FutureConnection connect() throws Exception { this.connection = mqtt.futureConnection(); Future<Void> connect = connection.connect(); return connection; }
public Message receive() throws Exception { return this.next.receive().await(); }
public void disconnect() throws Exception { this.next.disconnect().await(); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); this.executor = Executors.newSingleThreadExecutor(new SubscribersThreadFactory()); LOGGER.info("Receiver connecting to MQTT broker at '" + getBrokerInfo() + "'..."); connection = getConnection(); LOGGER.info("Receiver connected to MQTT broker."); // Subscribe to chosen topic. Topic[] topics = { new Topic(getTopic(), QoS.AT_LEAST_ONCE) }; try { Future<byte[]> future = connection.subscribe(topics); future.await(); LOGGER.info("Subscribed to events on MQTT topic: " + getTopic()); } catch (Exception e) { throw new SiteWhereException("Exception while attempting to subscribe to MQTT topic: " + getTopic(), e); } // Handle message processing in separate thread. executor.execute(new MqttSubscriptionProcessor()); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (processorsExecutor != null) { processorsExecutor.shutdownNow(); } if (subscriptionExecutor != null) { subscriptionExecutor.shutdownNow(); } if (connection != null) { try { connection.disconnect().await(); connection.kill().await(); } catch (ShutdownException e) { getLogger().info("Dispatcher has already been shut down."); } catch (Exception e) { getLogger().error("Error shutting down MQTT device event receiver.", e); } } super.stop(monitor); }
/** * Publish an event to an MQTT topic. * * @param event * @throws SiteWhereException */ protected void publish(IDeviceEvent event, String topic) throws SiteWhereException { connection.publish(topic, MarshalUtils.marshalJson(event), QoS.AT_LEAST_ONCE, false); }
public void connect() throws Exception { this.next.connect().await(); }