public void run() { next.disconnect(future); } });
private void connectMqtt() throws Exception { String clientId = this.topologyName + "-" + this.context.getThisComponentId() + "-" + this.context.getThisTaskId(); MQTT client = MqttUtils.configureClient(this.options, clientId, this.keyStoreLoader); this.connection = client.callbackConnection(); this.connection.listener(this); this.connection.connect(new ConnectCallback()); while (!this.mqttConnected && !this.mqttConnectFailed) { LOG.info("Waiting for connection..."); Thread.sleep(500); } if (this.mqttConnected) { List<String> topicList = this.options.getTopics(); Topic[] topics = new Topic[topicList.size()]; QoS qos = MqttUtils.qosFromInt(this.options.getQos()); for (int i = 0; i < topicList.size(); i++) { topics[i] = new Topic(topicList.get(i), qos); } connection.subscribe(topics, new SubscribeCallback()); } }
public void run() { next.subscribe(topics, future); } });
this.connectionArray[0] = createConnection(host, clientId + jmcx.getThreadNum(), durable); this.connectionArray[0].listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topic, connectionArray[0], cbs, qos,1); this.connectionArray[0].connect(cbc); + jmcx.getThreadNum() + j, durable); this.connectionArray[j] .listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topic, connectionArray[j], cbs, qos,size); this.connectionArray[j].connect(cbc); this.connectionArray[r] = createConnection(host, clientId + jmcx.getThreadNum() + r, durable); this.connectionArray[r].listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topicArray[r], connectionArray[r], cbs, qos,1); this.connectionArray[r].connect(cbc);
public void run() { next.connect(future); } });
public FutureConnection(CallbackConnection next) { this.next = next; this.next.listener(new ExtendedListener() {
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (connection != null) { try { connection.disconnect(new Callback<Void>() { @Override public void onFailure(Throwable e) { LOGGER.info("MQTT disconnect failed."); } @Override public void onSuccess(Void arg0) { } }); connection.transport().stop(new Runnable() { @Override public void run() { LOGGER.info("MQTT connection transport stopped."); } }); } catch (Exception e) { LOGGER.error("Error shutting down MQTT device event receiver.", e); } } }
public void run() { next.publish(topic, payload, qos, retain, future); } });
for (int p = 0; p < this.connectionArray.length; p++) { if (this.connectionArray[p] != null) { this.connectionArray[p].unsubscribe(Topics, new CallbackforUnsubscribe()); this.connectionArray[p].disconnect(new CallbackforDisconnect());
public DispatchQueue getDispatchQueue() { return this.next.getDispatchQueue(); }
public void run() { next.unsubscribe(topics, future); } });
public void onSuccess(Void value) { final Topic[] ta = topics.toArray(new Topic[topics.size()]); connection.subscribe(ta, new Callback<byte[]>() { public void onSuccess(byte[] value) { if(debug) { for (int i = 0; i < value.length; i++) { stderr("Subscribed to Topic: " + ta[i].name() + " with QoS: " + QoS.values()[value[i]]); } } } public void onFailure(Throwable value) { stderr("Subscribe failed: " + value); if(debug) { value.printStackTrace(); } System.exit(2); } }); } });
this.connectionArray[0] = createConnection(host, clientId + jmcx.getThreadNum(), durable, user, password); this.connectionArray[0].listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topic, connectionArray[0], cbs, qos,1); this.connectionArray[0].connect(cbc); + jmcx.getThreadNum() + j, durable, user, password); this.connectionArray[j] .listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topic, connectionArray[j], cbs, qos,size); this.connectionArray[j].connect(cbc); + jmcx.getThreadNum() + r, durable, user, password); this.connectionArray[r] .listener(new ListenerforSubscribe()); CallbackforSubscribe cbs = new CallbackforSubscribe(); CallbackforConnect cbc = new CallbackforConnect(topicArray[r], connectionArray[r], cbs, qos,1); this.connectionArray[r].connect(cbc);
public void run() { next.connect(future); } });
private FuseChannel(final String clientId, final MqttNamespace namespace, final BinaryPayloadCodec codec, final CallbackConnection connection) { super(codec, namespace, clientId); this.connection = connection; this.connection.listener(listener); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (connection != null) { try { connection.disconnect(new Callback<Void>() { @Override public void onFailure(Throwable e) { getLogger().info("MQTT disconnect failed."); } @Override public void onSuccess(Void arg0) { } }); connection.transport().stop(new Runnable() { @Override public void run() { getLogger().info("MQTT connection transport stopped."); } }); } catch (Exception e) { getLogger().error("Error shutting down MQTT device event receiver.", e); } } }
public void publish(String topic, byte[] payload, QoS qos, boolean retain, Callback<Void> cb) { publish(utf8(topic), new Buffer(payload), qos, retain, cb); }
/** * Storm has determined that the tuple emitted by this spout with the msgId identifier * has been fully processed. Typically, an implementation of this method will take that * message off the queue and prevent it from being replayed. * * @param msgId */ public void ack(Object msgId) { AckableMessage msg = this.pending.remove(msgId); this.connection.getDispatchQueue().execute(msg.ack()); }
public void run() { next.unsubscribe(topics, future); } });