本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED属性的典型用法代码示例。如果您正苦于以下问题:Java MqttConnectReturnCode.CONNECTION_ACCEPTED属性的具体用法?Java MqttConnectReturnCode.CONNECTION_ACCEPTED怎么用?Java MqttConnectReturnCode.CONNECTION_ACCEPTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.netty.handler.codec.mqtt.MqttConnectReturnCode
的用法示例。
在下文中一共展示了MqttConnectReturnCode.CONNECTION_ACCEPTED属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleConnack
/**
* Used for calling the connect handler when the server replies to the request
*
* @param msg connection response message
*/
void handleConnack(MqttConnAckMessage msg) {
synchronized (this.connection) {
this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED;
if (this.connectHandler != null) {
if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
this.connectHandler.handle(Future.succeededFuture(msg));
} else {
MqttConnectionException exception = new MqttConnectionException(msg.code());
log.error(String.format("Connection refused by the server - code: %s", msg.code()));
this.connectHandler.handle(Future.failedFuture(exception));
}
}
}
}
示例2: connectionAlreadyAccepted
@Test
public void connectionAlreadyAccepted(TestContext context) throws Exception {
this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
client.connect();
try {
// try to accept a connection already accepted
this.endpoint.accept(false);
context.fail();
} catch (IllegalStateException e) {
// Ok
}
}
示例3: reject
public MqttEndpointImpl reject(MqttConnectReturnCode returnCode) {
if (returnCode == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
throw new IllegalArgumentException("Need to use the 'accept' method for accepting connection");
}
// sessionPresent flag has no meaning in this case, the network connection will be closed
return this.connack(returnCode, false);
}
示例4: accepted
@Test
public void accepted(TestContext context) {
this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;
try {
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
client.connect();
} catch (MqttException e) {
context.fail(e);
}
}
示例5: acceptedClientIdAutoGenerated
@Test
public void acceptedClientIdAutoGenerated(TestContext context) {
this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED;
try {
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "", persistence);
client.connect();
} catch (MqttException e) {
context.fail(e);
}
}
示例6: endpointHandler
@Override
protected void endpointHandler(MqttEndpoint endpoint) {
MqttConnectReturnCode returnCode = this.expectedReturnCode;
switch (this.expectedReturnCode) {
case CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD:
returnCode =
(endpoint.auth().userName().equals(MQTT_USERNAME) &&
endpoint.auth().password().equals(MQTT_PASSWORD)) ?
MqttConnectReturnCode.CONNECTION_ACCEPTED :
MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD;
break;
case CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION:
returnCode = endpoint.protocolVersion() == MqttConnectOptions.MQTT_VERSION_3_1_1 ?
MqttConnectReturnCode.CONNECTION_ACCEPTED :
MqttConnectReturnCode.CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION;
break;
}
log.info("return code = " + returnCode);
if (returnCode == MqttConnectReturnCode.CONNECTION_ACCEPTED) {
log.info("client id = " + endpoint.clientIdentifier());
endpoint.accept(false);
} else {
endpoint.reject(returnCode);
}
this.endpoint = endpoint;
}