protected boolean isConnected(){ return (mqttClient != null && mqttClient.isConnected()); }
@After public void tearDown() throws Exception { if (m_client != null && m_client.isConnected()) { m_client.disconnect(); } if (m_publisher != null && m_publisher.isConnected()) { m_publisher.disconnect(); } stopServer(); }
@After public void tearDown() throws Exception { if (m_client != null && m_client.isConnected()) { m_client.disconnect(); } if (m_publisher != null && m_publisher.isConnected()) { m_publisher.disconnect(); } stopServer(); IntegrationUtils.clearTestStorage(); }
@After public void tearDown() throws Exception { if (m_client != null && m_client.isConnected()) { m_client.disconnect(); } if (m_publisher != null && m_publisher.isConnected()) { m_publisher.disconnect(); } stopServer(); IntegrationUtils.clearTestStorage(); }
@After public void tearDown() throws Exception { if (m_publisher.isConnected()) { m_publisher.disconnect(); } if (m_subscriber.isConnected()) { m_subscriber.disconnect(); } m_server.stopServer(); IntegrationUtils.clearTestStorage(); }
@After public void tearDown() throws Exception { if (m_subscriber != null && m_subscriber.isConnected()) { m_subscriber.disconnect(); } if (m_publisher != null && m_publisher.isConnected()) { m_publisher.disconnect(); } m_server.stopServer(); IntegrationUtils.clearTestStorage(); }
private void initializeClient(ProcessContext context) { // NOTE: This method is called when isConnected returns false which can happen when the client is null, or when it is // non-null but not connected, so we need to handle each case and only create a new client when it is null try { if (mqttClient == null) { logger.debug("Creating client"); mqttClient = createMqttClient(broker, clientID, persistence); mqttClient.setCallback(this); } if (!mqttClient.isConnected()) { logger.debug("Connecting client"); mqttClient.connect(connOpts); } } catch (MqttException e) { logger.error("Connection to {} lost (or was never connected) and connection failed. Yielding processor", new Object[]{broker}, e); context.yield(); } }
@After public void tearDown() throws Exception { if (m_client != null && m_client.isConnected()) { m_client.disconnect(); } if (m_server != null) { m_server.stopServer(); } IntegrationUtils.clearTestStorage(); }
@After public void tearDown() throws Exception { if (m_client != null && m_client.isConnected()) { m_client.disconnect(); } if (m_server != null) { m_server.stopServer(); } IntegrationUtils.clearTestStorage(); }
private void initializeClient(ProcessContext context) { // NOTE: This method is called when isConnected returns false which can happen when the client is null, or when it is // non-null but not connected, so we need to handle each case and only create a new client when it is null try { if (mqttClient == null) { logger.debug("Creating client"); mqttClient = createMqttClient(broker, clientID, persistence); mqttClient.setCallback(this); } if (!mqttClient.isConnected()) { logger.debug("Connecting client"); mqttClient.connect(connOpts); mqttClient.subscribe(topicFilter, qos); } } catch (MqttException e) { logger.error("Connection to {} lost (or was never connected) and connection failed. Yielding processor", new Object[]{broker}, e); context.yield(); } }
@Override public void removeTopic(String... topic) { this.topicLock.lock(); try { if (this.client != null && this.client.isConnected()) { this.client.unsubscribe(topic); } super.removeTopic(topic); } catch (MqttException e) { throw new MessagingException("Failed to unsubscribe from topic " + Arrays.asList(topic), e); } finally { this.topicLock.unlock(); } }
@Override public void addTopic(String topic, int qos) { this.topicLock.lock(); try { super.addTopic(topic, qos); if (this.client != null && this.client.isConnected()) { this.client.subscribe(topic, qos); } } catch (MqttException e) { super.removeTopic(topic); throw new MessagingException("Failed to subscribe to topic " + topic, e); } finally { this.topicLock.unlock(); } }
this.topicLock.unlock(); if (this.client.isConnected()) { this.connected = true; String message = "Connected and subscribed to " + Arrays.toString(topics);
@Override public boolean isConnected() { return this.mqttClient.isConnected(); }
public Boolean isConnected() { if (mqttClient == null) { _logger.error("This client was not initialized correctly!"); return null; } else { return mqttClient.isConnected(); } }
public Boolean isConnected() { if (mqttClient == null) { _logger.error("This client was not initialized correctly!"); return null; } else { return mqttClient.isConnected(); } }
}).given(client).setCallback(any(MqttCallback.class)); given(client.isConnected()).willReturn(true);
private MqttPahoMessageDrivenChannelAdapter buildAdapterIn(final IMqttClient client, Boolean cleanSession, ConsumerStopAction action) throws MqttException { DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory() { @Override public IMqttClient getClientInstance(String uri, String clientId) throws MqttException { return client; } }; MqttConnectOptions connectOptions = new MqttConnectOptions(); connectOptions.setServerURIs(new String[] { "tcp://localhost:1883" }); if (cleanSession != null) { connectOptions.setCleanSession(cleanSession); } if (action != null) { factory.setConsumerStopAction(action); } factory.setConnectionOptions(connectOptions); given(client.isConnected()).willReturn(true); MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("client", factory, "foo"); adapter.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); adapter.setOutputChannel(new NullChannel()); adapter.setTaskScheduler(mock(TaskScheduler.class)); adapter.afterPropertiesSet(); return adapter; }
public void disconnect() { try { if (_listener != null) { _listener.stopReconnect(); } if (_client != null) { if (_client.isConnected()) { _client.disconnect(DISCONNECT_TIME_OUT); } _client.close(); } _config.setStatus(STATE.DOWN, "Stopped."); } catch (Exception ex) { _logger.error("Exception,", ex); } }
public void disconnect() { try { if (_listener != null) { _listener.stopReconnect(); } if (_client != null) { if (_client.isConnected()) { _client.disconnect(DISCONNECT_TIME_OUT); } _client.close(); } _config.setStatus(STATE.DOWN, "Stopped."); } catch (Exception ex) { _logger.error("Exception,", ex); } }