當前位置: 首頁>>代碼示例>>Java>>正文


Java IMqttActionListener類代碼示例

本文整理匯總了Java中org.eclipse.paho.client.mqttv3.IMqttActionListener的典型用法代碼示例。如果您正苦於以下問題:Java IMqttActionListener類的具體用法?Java IMqttActionListener怎麽用?Java IMqttActionListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IMqttActionListener類屬於org.eclipse.paho.client.mqttv3包,在下文中一共展示了IMqttActionListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final SubscribeFactory factory = new SubscribeFactory(client);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final int[] qos = new int[]{ 1, 2 };
    final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).subscribe(Mockito.same(topics),
            Mockito.same(qos),
            Mockito.isNull(),
            actionListener.capture(),
            messageListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof SubscribeFactory.SubscribeActionListener);
    Assert.assertTrue(messageListener.getValue() instanceof SubscriberMqttMessageListener[]);
    Assert.assertEquals(2, messageListener.getValue().length);
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:21,代碼來源:SubscribeFactoryTest.java

示例2: whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled() throws Throwable {
    expectedException.expectCause(isA(MqttException.class));
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final int[] qos = new int[]{ 1, 2 };
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.subscribe(Mockito.same(topics),
            Mockito.same(qos),
            Mockito.isNull(),
            actionListener.capture(),
            messageListener.capture()))
            .thenThrow(new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED));
    final SubscribeFactory factory = new SubscribeFactory(client);
    final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
    obs.blockingFirst();
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:19,代碼來源:SubscribeFactoryTest.java

示例3: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final PublishFactory factory = new PublishFactory(client);
    final String topic = "topic1";
    final MqttMessage msg = MqttMessage.create(0, new byte[] { 'a',  'b',  'c' }, 1, true);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Single<PublishToken> obs = factory.create(topic, msg);

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).publish(Mockito.same(topic), 
            Mockito.same(msg.getPayload()), Mockito.anyInt(),
            Mockito.anyBoolean(), Mockito.any(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof PublishFactory.PublishActionListener);
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:22,代碼來源:PublishFactoryTest.java

示例4: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final UnsubscribeFactory factory = new UnsubscribeFactory(client);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Completable obs = factory.create(topics);

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).unsubscribe(Mockito.same(topics), Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof UnsubscribeFactory.UnsubscribeActionListener);
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:19,代碼來源:UnsubscribeFactoryTest.java

示例5: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final DisconnectFactory factory = new DisconnectFactory(client);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Completable obs = factory.create();

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).disconnect(Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof DisconnectFactory.DisconnectActionListener);
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:18,代碼來源:DisconnectFactoryTest.java

示例6: doConnect

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * Actually do the mqtt connect operation
 */
private void doConnect() {
	if (clientHandle == null) {
		clientHandle = mqttService.getClient(serverURI, clientId,myContext.getApplicationInfo().packageName,
				persistence);
	}
	mqttService.setTraceEnabled(traceEnabled);
	mqttService.setTraceCallbackId(clientHandle);
	
	String activityToken = storeToken(connectToken);
	try {
		mqttService.connect(clientHandle, connectOptions, null,
				activityToken);
	}
	catch (MqttException e) {
		IMqttActionListener listener = connectToken.getActionCallback();
		if (listener != null) {
			listener.onFailure(connectToken, e);
		}
	}
}
 
開發者ID:Cirrus-Link,項目名稱:Sparkplug,代碼行數:24,代碼來源:MqttAndroidClient.java

示例7: subscribe

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
public void subscribe(String[] topicFilters, int[] qos, String invocationContext, String activityToken, IMqttMessageListener[] messageListeners) {
	service.traceDebug(TAG, "subscribe({" + Arrays.toString(topicFilters) + "}," + Arrays.toString(qos) + ",{"
			+ invocationContext + "}, {" + activityToken + "}");
	final Bundle resultBundle = new Bundle();
	resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION);
	resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken);
	resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext);
	if((myClient != null) && (myClient.isConnected())){
		IMqttActionListener listener = new MqttConnectionListener(resultBundle);
		try {

			myClient.subscribe(topicFilters, qos,messageListeners);
		} catch (Exception e){
			handleException(resultBundle, e);
		}
	} else {
		resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, NOT_CONNECTED);
		service.traceError("subscribe", NOT_CONNECTED);
		service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
	}
}
 
開發者ID:Cirrus-Link,項目名稱:Sparkplug,代碼行數:22,代碼來源:MqttConnection.java

示例8: doConnect

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * Actually do the mqtt connect operation
 */
private void doConnect() {
    if (clientHandle == null) {
        clientHandle = mqttService.getClient(serverURI, clientId,String.valueOf(myContext.hashCode()),
                persistence);
    }
    mqttService.setTraceEnabled(traceEnabled);
    mqttService.setTraceCallbackId(clientHandle);

    String activityToken = storeToken(connectToken);
    try {
        mqttService.connect(clientHandle, connectOptions, null,
                activityToken);
    }
    catch (MqttException e) {
        IMqttActionListener listener = connectToken.getActionCallback();
        if (listener != null) {
            listener.onFailure(connectToken, e);
        }
    }
}
 
開發者ID:octoblu,項目名稱:droidblu,代碼行數:24,代碼來源:MqttAndroidClient.java

示例9: doConnect

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * Actually do the mqtt connect operation
 */
private void doConnect() {
	if (clientHandle == null) {
		clientHandle = mqttService.getClient(serverURI, clientId,String.valueOf(myContext.hashCode()),
				persistence);
	}
	mqttService.setTraceEnabled(traceEnabled);
	mqttService.setTraceCallbackId(clientHandle);

	String activityToken = storeToken(connectToken);
	try {
		mqttService.connect(clientHandle, connectOptions, null,
				activityToken);
	}
	catch (MqttException e) {
		IMqttActionListener listener = connectToken.getActionCallback();
		if (listener != null) {
			listener.onFailure(connectToken, e);
		}
	}
}
 
開發者ID:slimpp,項目名稱:SlimChat.Android,代碼行數:24,代碼來源:MqttAndroidClient.java

示例10: ConnectActionListener

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * @param persistence
 * @param client 
 * @param comms
 * @param options 
 * @param userToken  
 * @param userContext
 * @param userCallback
 */
public ConnectActionListener(
    MqttAsyncClient client,
    MqttClientPersistence persistence,
    ClientComms comms,
    MqttConnectOptions options,
    MqttToken userToken,
    Object userContext,
    IMqttActionListener userCallback) {
  this.persistence = persistence;
  this.client = client;
  this.comms = comms;
  this.options = options;
  this.userToken = userToken;
  this.userContext = userContext;
  this.userCallback = userCallback;
  this.originalMqttVersion = options.getMqttVersion();
}
 
開發者ID:gulliverrr,項目名稱:hestia-engine-dev,代碼行數:27,代碼來源:ConnectActionListener.java

示例11: fireActionEvent

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * An action has completed - if a completion listener has been set on the
 * token then invoke it with the outcome of the action.
 * 
 * @param token
 */
public void fireActionEvent(MqttToken token) {
	final String methodName = "fireActionEvent";

	if (token != null) {
		IMqttActionListener asyncCB = token.getActionCallback();
		if (asyncCB != null) {
			if (token.getException() == null) {
				// @TRACE 716=call onSuccess key={0}
				log.fine(CLASS_NAME, methodName, "716",
						new Object[] { token.internalTok.getKey() });
				asyncCB.onSuccess(token);
			} else {
				// @TRACE 717=call onFailure key {0}
				log.fine(CLASS_NAME, methodName, "716",
						new Object[] { token.internalTok.getKey() });
				asyncCB.onFailure(token, token.getException());
			}
		}
	}
}
 
開發者ID:gulliverrr,項目名稱:hestia-engine-dev,代碼行數:27,代碼來源:CommsCallback.java

示例12: unsubscribeToTopic

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
public void unsubscribeToTopic(String topic, IMqttActionListener listener) {
    try {
        mqttAndroidClient.unsubscribe(topic, null, listener);
    } catch (MqttException ex) {
        System.err.println("Exception whilst subscribing");
        ex.printStackTrace();
    }
}
 
開發者ID:vuatovuanang,項目名稱:WebRTC-VideoCall-Anrdoid,代碼行數:9,代碼來源:MqttClientHelper.java

示例13: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final MqttConnectOptions options = Mockito.mock(MqttConnectOptions.class);
    final ConnectFactory factory = new ConnectFactory(client, options);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final Completable obs = factory.create();
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).connect(Mockito.same(options), Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof ConnectFactory.ConnectActionListener);
}
 
開發者ID:patrickvankann,項目名稱:rxmqtt,代碼行數:14,代碼來源:ConnectFactoryTest.java

示例14: doConnect

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
public void doConnect(IMqttActionListener listener) {

        try {
            //realiza a conexão com o broker
            MqttConnectOptions options = new MqttConnectOptions();
            options.setConnectionTimeout(5);
            IMqttToken token = mqttAndroidClient.connect();
            token.setActionCallback(listener);

        } catch (MqttException e) {

            e.printStackTrace();
        }

    }
 
開發者ID:lasseufpa,項目名稱:circular,代碼行數:16,代碼來源:MQTTconect.java

示例15: subscribe

import org.eclipse.paho.client.mqttv3.IMqttActionListener; //導入依賴的package包/類
/**
 * Subscribe to topic
 *
 * @param topic    topic to subscribe
 * @param qos      define quality of service (check QosPolicy enum)
 * @param listener completion listener (null allowed)
 * @return
 */
protected void subscribe(String topic, QosPolicy qos, IMqttActionListener listener) {

    if (isConnected()) {
        try {
            mClient.subscribe(topic, qos.getValue(), mContext, listener);
        } catch (MqttException e) {
            e.printStackTrace();
        }
    } else {
        Log.e(TAG, "cant publish message. Not connected");
    }
}
 
開發者ID:bertrandmartel,項目名稱:iotf-android,代碼行數:21,代碼來源:IotHandlerAbstr.java


注:本文中的org.eclipse.paho.client.mqttv3.IMqttActionListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。