Java 类org.eclipse.paho.client.mqttv3.IMqttToken 实例源码

项目:MQTTKafkaBridge    文件:Bridge.java   
private void connect(String serverURI, String clientId, String zkConnect) throws MqttException {

    mqtt = new MqttAsyncClient(serverURI, clientId);
    mqtt.setCallback(this);
    IMqttToken token = mqtt.connect();
    Properties props = new Properties();

    //Updated based on Kafka v0.8.1.1
    props.put("metadata.broker.list", "localhost:9092");
       props.put("serializer.class", "kafka.serializer.StringEncoder");
       props.put("partitioner.class", "example.producer.SimplePartitioner");
       props.put("request.required.acks", "1");

    ProducerConfig config = new ProducerConfig(props);
    kafkaProducer = new Producer<String, String>(config);
    token.waitForCompletion();
    logger.info("Connected to MQTT and Kafka");
}
项目:artikcloud-java    文件:MqttSession.java   
@Override
        public void onSuccess(final IMqttToken arg0) {
//            System.out.println("-------- Thread: " + Thread.currentThread().getName()+ "; MqttSession.OperationListener onSuccess: ");
             if (userCallback == null) {
                 return;
             }

            Thread t = new Thread(new Runnable() {
                 @Override
                 public void run() {
                     OperationMode opMode = getOperationModeFromContext((String)arg0.getUserContext());
                     userCallback.onSuccess(opMode, arg0);
                 }
             });
            t.start();
        }
项目:rxmqtt    文件:CompletableEmitterMqttActionListenerTest.java   
@Test
public void whenTheConstructorIsCalledWithAValidEmitterThenGetOnErrorReturnsTheEmitter() {

    //Given
    CompletableEmitter emitter = Mockito.mock(CompletableEmitter.class);
    Throwable ex = Mockito.mock(Throwable.class);
    CompletableEmitterMqttActionListener listener = new CompletableEmitterMqttActionListener(emitter) {

        @Override
        public void onSuccess(IMqttToken asyncActionToken) {
            // Not invoked
        }
    };

    // When
    OnError onError = listener.getOnError();
    onError.onError(ex);

    // Then
    Mockito.verify(emitter).onError(ex);
}
项目:rxmqtt    文件:FlowableEmitterMqttActionListenerTest.java   
@Test
public void whenTheConstructorIsCalledWithAValidEmitterThenGetOnErrorReturnsTheEmitter() {

    //Given
    @SuppressWarnings("unchecked")
    FlowableEmitter<Object> emitter = Mockito.mock(FlowableEmitter.class);
    Throwable ex = Mockito.mock(Throwable.class);
    FlowableEmitterMqttActionListener<Object> listener = new FlowableEmitterMqttActionListener<Object>(emitter) {

        @Override
        public void onSuccess(IMqttToken asyncActionToken) {
            // Not invoked
        }
    };

    // When
    OnError onError = listener.getOnError();
    onError.onError(ex);

    // Then
    Mockito.verify(emitter).onError(ex);
}
项目:aws-iot-device-sdk-java    文件:AwsIotMqttConnectionListener.java   
@Override
public void onSuccess(IMqttToken arg0) {
    client.scheduleTask(new Runnable() {
        @Override
        public void run() {
            if (isConnect) {
                client.getConnection().onConnectionSuccess();
            } else {
                client.getConnection().onConnectionClosed();
            }
            if (userCallback != null) {
                userCallback.onSuccess();
            }
        }
    });
}
项目:aws-iot-device-sdk-java    文件:AwsIotMqttConnectionListener.java   
@Override
public void onFailure(IMqttToken arg0, Throwable arg1) {
    LOGGER.log(Level.WARNING, (isConnect ? "Connect" : "Disconnect") + " request failure", arg1);

    client.scheduleTask(new Runnable() {
        @Override
        public void run() {
            if (isConnect) {
                client.getConnection().onConnectionFailure();
            } else {
                client.getConnection().onConnectionClosed();
            }
            if (userCallback != null) {
                userCallback.onFailure();
            }
        }
    });
}
项目:aws-iot-device-sdk-java    文件:AwsIotMqttMessageListener.java   
@Override
public void onFailure(IMqttToken token, Throwable cause) {
    final AWSIotMessage message = (AWSIotMessage) token.getUserContext();
    if (message == null) {
        LOGGER.warning("Request failed: " + token.getException());
        return;
    }

    LOGGER.warning("Request failed for topic " + message.getTopic() + ": " + token.getException());
    client.scheduleTask(new Runnable() {
        @Override
        public void run() {
            message.onFailure();
        }
    });
}
项目:Sparkplug    文件:ActionListener.java   
/**
 * The action associated with this listener has been successful.
 *
 * @param asyncActionToken This argument is not used
 */
@Override
public void onSuccess(IMqttToken asyncActionToken) {
    switch (action) {
        case CONNECT:
            connect();
            break;
        case DISCONNECT:
            disconnect();
            break;
        case SUBSCRIBE:
            subscribe();
            break;
        case PUBLISH:
            publish();
            break;
    }

}
项目:Sparkplug    文件:ActionListener.java   
/**
 * The action associated with the object was a failure
 *
 * @param token     This argument is not used
 * @param exception The exception which indicates why the action failed
 */
@Override
public void onFailure(IMqttToken token, Throwable exception) {
    switch (action) {
        case CONNECT:
            connect(exception);
            break;
        case DISCONNECT:
            disconnect(exception);
            break;
        case SUBSCRIBE:
            subscribe(exception);
            break;
        case PUBLISH:
            publish(exception);
            break;
    }

}
项目:Sparkplug    文件:MqttAndroidClient.java   
/**
 * Common processing for many notifications
 * 
 * @param token
 *            the token associated with the action being undertake
 * @param data
 *            the result data
 */
private void simpleAction(IMqttToken token, Bundle data) {
    if (token != null) {
        Status status = (Status) data
                .getSerializable(MqttServiceConstants.CALLBACK_STATUS);
        if (status == Status.OK) {
            ((MqttTokenAndroid) token).notifyComplete();
        }
        else {
            Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION);
            ((MqttTokenAndroid) token).notifyFailure(exceptionThrown);
        }
    } else {
        mqttService.traceError(MqttService.TAG, "simpleAction : token is null");    
    }
}
项目:Domo-Android    文件:MqttPingSender.java   
@Override
public void onReceive(Context context, Intent intent) {
    // According to the docs, "Alarm Manager holds a CPU wake lock as
    // long as the alarm receiver's onReceive() method is executing.
    // This guarantees that the phone will not sleep until you have
    // finished handling the broadcast."

    int count = intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, -1);
    //Log.d(TAG, "Ping " + count + " times.");

    //Log.d(TAG, "Check time :" + System.currentTimeMillis());
    IMqttToken token = comms.checkForActivity();

    // No ping has been sent.
    if (token == null) {
        return;
    }

}
项目:Bluemix-IoT-android-wear    文件:ActionListener.java   
/**
 * Determine the type of callback that completed successfully.
 * @param token The MQTT Token for the completed action.
 */
@Override
public void onSuccess(IMqttToken token) {
    Log.d(TAG, ".onSuccess() entered");
    this.token = token;
    switch (action) {
        case CONNECTING:
            handleConnectSuccess();
            break;

        case SUBSCRIBE:
            handleSubscribeSuccess();
            break;

        case PUBLISH:
            handlePublishSuccess();
            break;

        case DISCONNECTING:
            handleDisconnectSuccess();
            break;

        default:
            break;
    }
}
项目:Bluemix-IoT-android-wear    文件:ActionListener.java   
/**
 * Determine the type of callback that failed.
 * @param token The MQTT Token for the completed action.
 * @param throwable The exception corresponding to the failure.
 */
@Override
public void onFailure(IMqttToken token, Throwable throwable) {
    Log.e(TAG, ".onFailure() entered");
    switch (action) {
        case CONNECTING:
            handleConnectFailure(throwable);
            break;

        case SUBSCRIBE:
            handleSubscribeFailure(throwable);
            break;

        case PUBLISH:
            handlePublishFailure(throwable);
            break;

        case DISCONNECTING:
            handleDisconnectFailure(throwable);
            break;

        default:
            break;
    }
}
项目:ready-mqtt-plugin    文件:MqttConnectedTestStep.java   
protected boolean waitForMqttOperation(IMqttToken token, CancellationToken cancellationToken, WsdlTestStepResult testStepResult, long maxTime, String errorText) {
    while (!token.isComplete() && token.getException() == null) {
        boolean stopped = cancellationToken.cancelled();
        if (stopped || (maxTime != Long.MAX_VALUE && System.nanoTime() > maxTime)) {
            if (stopped) {
                testStepResult.setStatus(TestStepResult.TestStepStatus.CANCELED);
            }
            else{
                testStepResult.addMessage(TIMEOUT_EXPIRED_MSG);
                testStepResult.setStatus(TestStepResult.TestStepStatus.FAILED);

            }
            return false;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (token.getException() != null) {
        testStepResult.addMessage(errorText);
        testStepResult.setError(token.getException());
        testStepResult.setStatus(TestStepResult.TestStepStatus.FAILED);
        return false;
    }
    return true;
}
项目:IBMIotForAndriod    文件:ActionListener.java   
/**
 * Determine the type of callback that completed successfully.
 * @param token The MQTT Token for the completed action.
 */
@Override
public void onSuccess(IMqttToken token) {
    Log.d(TAG, ".onSuccess() entered");
    this.token = token;
    switch (action) {
        case CONNECTING:
            handleConnectSuccess();
            break;

        case SUBSCRIBE:
            handleSubscribeSuccess();
            break;

        case PUBLISH:
            handlePublishSuccess();
            break;

        case DISCONNECTING:
            handleDisconnectSuccess();
            break;

        default:
            break;
    }
}
项目:IBMIotForAndriod    文件:ActionListener.java   
/**
 * Determine the type of callback that failed.
 * @param token The MQTT Token for the completed action.
 * @param throwable The exception corresponding to the failure.
 */
@Override
public void onFailure(IMqttToken token, Throwable throwable) {
    Log.e(TAG, ".onFailure() entered");
    switch (action) {
        case CONNECTING:
            handleConnectFailure(throwable);
            break;

        case SUBSCRIBE:
            handleSubscribeFailure(throwable);
            break;

        case PUBLISH:
            handlePublishFailure(throwable);
            break;

        case DISCONNECTING:
            handleDisconnectFailure(throwable);
            break;

        default:
            break;
    }
}
项目:Bluefruit_LE_Connect_Android    文件:MqttManager.java   
@Override
public void onFailure(IMqttToken iMqttToken, Throwable throwable) {
    Log.d(TAG, "Mqtt onFailure. " + throwable);

    // Remove the auto-connect till the failure is solved
    if (mMqqtClientStatus == MqqtConnectionStatus.CONNECTING) {
        MqttSettings.getInstance(mContext).setConnectedEnabled(false);
    }

    // Set as an error
    mMqqtClientStatus = MqqtConnectionStatus.ERROR;
    String errorText = mContext.getString(R.string.mqtt_connection_failed)+". "+throwable.getLocalizedMessage();
    Toast.makeText(mContext, errorText, Toast.LENGTH_LONG).show();

    // Call listener
    if (mListener != null) mListener.onMqttDisconnected();
}
项目:droidblu    文件:MqttAndroidClient.java   
/**
 * Common processing for many notifications
 *
 * @param token
 *            the token associated with the action being undertake
 * @param data
 *            the result data
 */
private void simpleAction(IMqttToken token, Bundle data) {
    if (token != null) {
        Status status = (Status) data
                .getSerializable(MqttServiceConstants.CALLBACK_STATUS);
        if (status == Status.OK) {
            ((MqttTokenAndroid) token).notifyComplete();
        }
        else {
            Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION);
            ((MqttTokenAndroid) token).notifyFailure(exceptionThrown);
        }
    } else {
        mqttService.traceError(MqttService.TAG, "simpleAction : token is null");
    }
}
项目:iot-starter-for-android    文件:MyIoTActionListener.java   
/**
 * Determine the type of callback that completed successfully.
 * @param token The MQTT Token for the completed action.
 */
@Override
public void onSuccess(IMqttToken token) {
    Log.d(TAG, ".onSuccess() entered");
    switch (action) {
        case CONNECTING:
            handleConnectSuccess();
            break;

        case SUBSCRIBE:
            handleSubscribeSuccess();
            break;

        case PUBLISH:
            handlePublishSuccess();
            break;

        case DISCONNECTING:
            handleDisconnectSuccess();
            break;

        default:
            break;
    }
}
项目:iot-starter-for-android    文件:MyIoTActionListener.java   
/**
 * Determine the type of callback that failed.
 * @param token The MQTT Token for the completed action.
 * @param throwable The exception corresponding to the failure.
 */
@Override
public void onFailure(IMqttToken token, Throwable throwable) {
    Log.e(TAG, ".onFailure() entered");
    switch (action) {
        case CONNECTING:
            handleConnectFailure(throwable);
            break;

        case SUBSCRIBE:
            handleSubscribeFailure(throwable);
            break;

        case PUBLISH:
            handlePublishFailure(throwable);
            break;

        case DISCONNECTING:
            handleDisconnectFailure(throwable);
            break;

        default:
            break;
    }
}
项目:ch.bfh.mobicomp    文件:DC.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/DC/#", 1);
    client.subscribe("iot/tf/localhost/4223/DC/#", 1);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();

    client.publish("iot/tf/localhost/4223/DC/e1cw8v/intent/<" + UID + ">/driveMode/value", "0".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/DC/e1cw8v/intent/<" + UID + ">/enabled/value", "true".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/DC/e1cw8v/intent/<" + UID + ">/currentVelocityPeriod/period", "1".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/DC/e1cw8v/intent/<" + UID + ">/acceleration/value", "2000".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/DC/e1cw8v/intent/<" + UID + ">/velocity/value", "7000".getBytes(), 1, false);

} catch (Exception ex) {
    Logger.getLogger(DC.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:IMUV2.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/IMUV2/#", 1);
    client.subscribe("iot/tf/localhost/4223/IMUV2/#", 1);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();

    client.publish("iot/tf/localhost/4223/IMUV2/9xblji/intent/<" + UID + ">/linearAcceleration/period", "10".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(IMUV2.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:SoundIntensity.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/SoundIntensity/#", 0);
    client.subscribe("iot/tf/localhost/4223/SoundIntensity/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();
    client.publish("iot/tf/localhost/4223/SoundIntensity/fnniyg/intent/<" + UID + ">/callbackThreshold/option", "g".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/SoundIntensity/fnniyg/intent/<" + UID + ">/callbackThreshold/min", "2".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/SoundIntensity/fnniyg/intent/<" + UID + ">/callbackThreshold/max", "2".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/SoundIntensity/fnniyg/intent/<" + UID + ">/callbackThreshold/enabled", "true".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(SoundIntensity.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:Barometer.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/Barometer/#", 0);
    client.subscribe("iot/tf/localhost/4223/Barometer/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();
    client.publish("iot/tf/localhost/4223/Barometer/dpm5s8/intent/<" + UID + ">/averaging/averagePressure", "0".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/Barometer/dpm5s8/intent/<" + UID + ">/averaging/movingAveragePressure", "0".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/Barometer/dpm5s8/intent/<" + UID + ">/averaging/averageTemperature", "0".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/Barometer/dpm5s8/intent/<" + UID + ">/averaging/enabled", "true".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/Barometer/dpm5s8/intent/<" + UID + ">/airPressureCallbackPeriod/period", "2".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(Barometer.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:Button.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/LCD20x4/#", 1);
    client.subscribe("iot/tf/localhost/4223/LCD20x4/#", 1);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true);
    Thread.sleep(1000);

} catch (Exception ex) {
    Logger.getLogger(Button.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:Bluefruit_LE_Connect_Android    文件:MqttManager.java   
@Override
public void onSuccess(IMqttToken iMqttToken) {
    if (mMqqtClientStatus == MqqtConnectionStatus.CONNECTING) {
        Log.d(TAG, "Mqtt connect onSuccess");
        mMqqtClientStatus = MqqtConnectionStatus.CONNECTED;
        if (mListener != null) mListener.onMqttConnected();

        MqttSettings settings = MqttSettings.getInstance(mContext);
        String topic = settings.getSubscribeTopic();
        int topicQos = settings.getSubscribeQos();
        if (settings.isSubscribeEnabled() && topic != null) {
            subscribe(topic, topicQos);
        }
    } else if (mMqqtClientStatus == MqqtConnectionStatus.DISCONNECTING) {
        Log.d(TAG, "Mqtt disconnect onSuccess");
        mMqqtClientStatus = MqqtConnectionStatus.DISCONNECTED;
        if (mListener != null) mListener.onMqttDisconnected();
    } else {
        Log.d(TAG, "Mqtt unknown onSuccess");
    }
}
项目:ch.bfh.mobicomp    文件:RotaryPoti.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/RotaryPoti/#", 0);
    client.subscribe("iot/tf/localhost/4223/RotaryPoti/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();
    client.publish("iot/tf/localhost/4223/RotaryPoti/etahff/intent/<" + UID + ">/positionCallbackPeriod/period", "1".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(RotaryPoti.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:DustDetector.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/DustDetector/#", 0);
    client.subscribe("iot/tf/localhost/4223/DustDetector/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();

    client.publish("iot/tf/localhost/4223/DustDetector/dg4p7n/intent/<" + UID + ">/dustDensityCallbackPeriod/period", "1".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(DustDetector.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:LaserRangeFinder.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/LaserRangeFinder/#", 0);
    client.subscribe("iot/tf/localhost/4223/LaserRangeFinder/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();
    client.publish("iot/tf/localhost/4223/LaserRangeFinder/eu1ew0/intent/<" + UID + ">/mode/mode", "1".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/LaserRangeFinder/eu1ew0/intent/<" + UID + ">/distanceCallbackPeriod/period", "1".getBytes(), 1, false);
    client.publish("iot/tf/localhost/4223/LaserRangeFinder/eu1ew0/intent/<" + UID + ">/velocityCallbackPeriod/period", "1".getBytes(), 1, false);

    client.publish("iot/tf/localhost/4223/LaserRangeFinder/eu1ew0/intent/<" + UID + ">/laser/enabled", "true".getBytes(), 1, false);

} catch (Exception ex) {
    Logger.getLogger(LaserRangeFinder.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:SlimChat.Android    文件:MqttAndroidClient.java   
/**
 * Common processing for many notifications
 * 
 * @param token
 *            the token associated with the action being undertake
 * @param data
 *            the result data
 */
private void simpleAction(IMqttToken token, Bundle data) {
    if (token != null) {
        Status status = (Status) data
                .getSerializable(MqttServiceConstants.CALLBACK_STATUS);
        if (status == Status.OK) {
            ((MqttTokenAndroid) token).notifyComplete();
        }
        else {
            Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION);
            ((MqttTokenAndroid) token).notifyFailure(exceptionThrown);
        }
    } else {
        mqttService.traceError(MqttService.TAG, "simpleAction : token is null");    
    }
}
项目:ch.bfh.mobicomp    文件:TemperatureIR.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/TemperatureIR/#", 0);
    client.subscribe("iot/tf/localhost/4223/TemperatureIR/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();

    client.publish("iot/tf/localhost/4223/TemperatureIR/fdjob6/intent/<" + UID + ">/objectTemperatureCallbackPeriod/period", "1".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(TemperatureIR.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:CO2.java   
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
//options.setUserName("user");
//options.setPassword("pass".toCharArray());
options.setWill(UID + "/status", "connection broken".getBytes(), 1, true);
options.setCleanSession(true);
IMqttToken token = client.connect(options, null, new MQTTActionHandler());
token.waitForCompletion();
try {
    client.subscribe("iot/tf/description/CO2/#", 0);
    client.subscribe("iot/tf/localhost/4223/CO2/#", 0);
    client.subscribe("iot/tf/#", 1);
    client.publish("iot/tf/MQTT2TF/0/intent/<" + UID + ">/stackHandler/stackAddress", "{\"hostName\":\"localhost\",\"port\":4223}".getBytes(), 1, true).waitForCompletion();

    client.publish("iot/tf/localhost/4223/CO2/e0542c/intent/<" + UID + ">/CO2ConcentrationCallbackPeriod/period", "1".getBytes(), 1, false);
} catch (Exception ex) {
    Logger.getLogger(CO2.class.getName()).log(Level.SEVERE, null, ex);
}

   }
项目:ch.bfh.mobicomp    文件:Joystick.java   
@Override
   public void position(short s, short s1) {
IMqttToken token = null;

try {
    getEvent(PositionValueEvent.class
    ).update(VALUE_X, s);
    while (token
        == null) {
    token = getEvent(PositionValueEvent.class).update(VALUE_Y, s1);
    }

    token.waitForCompletion(
        10);
} catch (Exception ex) {
    Logger.getLogger(Joystick.class
        .getName()).log(Level.SEVERE, null, ex);
    System.out.println(token.getException());

}

   }
项目:ch.bfh.mobicomp    文件:Joystick.java   
@Override
   public
    void positionReached(short s, short s1) {
try {
    getEvent(PositionValueEvent.class
    ).update(VALUE_X, s);
    IMqttToken token = null;
    while (token == null) {
    getEvent(PositionValueEvent.class
    ).update(VALUE_Y, s1);
    }
    token.waitForCompletion(10);
} catch (Exception ex) {
    Logger.getLogger(Joystick.class.getName()).log(Level.SEVERE, null, ex);
}
   }
项目:MQTT-Essentials-A-Lightweight-IoT-Protocol    文件:ConnectionListener.java   
@Override
    public void onSuccess(IMqttToken asyncActionToken) {
        System.out.println(
            String.format(
                "%s successfully connected",
                name));
//      try {
//          subscribeToken = 
//              client.subscribe(
//                  TOPIC,
//                  QUALITY_OF_SERVICE, 
//                  null, 
//                  this);
//      } catch (MqttException e) {
//          e.printStackTrace();
//      }
    }
项目:summer-mqtt    文件:PahoAsyncMqttClientService.java   
/**
 * Overridden to publish a {@link MqttClientConnectionFailureEvent} message.
 * <p>
 * If a {@link ReconnectService} instance is defined, the
 * {@link ReconnectService#connected(boolean)} method is called with a value of false.
 */
@Override
public void onFailure(IMqttToken token, Throwable throwable)
{
    mqttClientEventPublisher.publishConnectionFailureEvent(getClientId(), isAutoReconnect(),
        throwable, applicationEventPublisher, this);
    if (reconnectService != null)
    {
        reconnectService.connected(false);
    }
}
项目:WebRTC-VideoCall-Anrdoid    文件:LoginActivity.java   
@Override
public void onSuccess(IMqttToken asyncActionToken) {
    isLogin = true;
    tvName.setText("Online");
    edtFriendUsername.setEnabled(true);
    btnLogin.setText("Logout");
    MySharePreference.setUserName(LoginActivity.this, myUser);
    LogUtils.e("subscribeToTopic");
}
项目:oneM2M-Application-AndroidSample    文件:MainActivity.java   
@Override
public void onSuccess(IMqttToken asyncActionToken) {
    Log.d(TAG, "onSuccess");
    String payload = "";
    int mqttQos = 1; /* 0: NO QoS, 1: No Check , 2: Each Check */

    MqttMessage message = new MqttMessage(payload.getBytes());
    try {
        mqttClient.subscribe(MQTT_Req_Topic, mqttQos);
    } catch (MqttException e) {
        e.printStackTrace();
    }
}
项目:artikcloud-java    文件:MqttSession.java   
@Override
public void onFailure(final IMqttToken arg0, final Throwable arg1) {
     if (userCallback == null) {
         return;
     }

     Thread t = new Thread(new Runnable() {
         @Override
         public void run() {
             OperationMode opMode = getOperationModeFromContext((String)arg0.getUserContext());
             userCallback.onFailure(opMode, arg0, arg1);
         }
     });
    t.start();
}
项目:rxmqtt    文件:PublishFactory.java   
@Override
public void onSuccess(final IMqttToken mqttToken) {

    final PublishToken publishToken = new PublishToken() {

        @Override
        public String getClientId() {
            return mqttToken.getClient().getClientId();
        }

        @Override
        public String[] getTopics() {
            return mqttToken.getTopics();
        }

        @Override
        public int getMessageId() {
            return mqttToken.getMessageId();
        }

        @Override
        public boolean getSessionPresent() {
            return mqttToken.getSessionPresent();
        }

    };
    this.emitter.onSuccess(publishToken);
}