本文整理汇总了Java中org.eclipse.paho.client.mqttv3.IMqttToken类的典型用法代码示例。如果您正苦于以下问题:Java IMqttToken类的具体用法?Java IMqttToken怎么用?Java IMqttToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMqttToken类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了IMqttToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
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");
}
示例2: onSuccess
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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();
}
示例3: whenTheConstructorIsCalledWithAValidEmitterThenGetOnErrorReturnsTheEmitter
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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);
}
示例4: whenTheConstructorIsCalledWithAValidEmitterThenGetOnErrorReturnsTheEmitter
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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);
}
示例5: onSuccess
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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();
}
}
});
}
示例6: onFailure
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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();
}
}
});
}
示例7: onFailure
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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();
}
});
}
示例8: onSuccess
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
/**
* 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;
}
}
示例9: onFailure
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
/**
* 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;
}
}
示例10: simpleAction
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
/**
* 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");
}
}
示例11: onReceive
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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;
}
}
示例12: onSuccess
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
/**
* 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;
}
}
示例13: onFailure
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
/**
* 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;
}
}
示例14: waitForMqttOperation
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
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;
}
示例15: onFailure
import org.eclipse.paho.client.mqttv3.IMqttToken; //导入依赖的package包/类
@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();
}