/** * Check if the endpoint was created and is connected * * @return status of the endpoint (connected or not) */ private boolean checkConnected() { synchronized (this.so) { if ((this.endpoint != null) && (this.endpoint.isConnected())) { return true; } else { so.close(); throw new IllegalStateException("Received an MQTT packet from a not connected client (CONNECT not sent yet)"); } } } }
/** * Check if the endpoint was created and is connected * * @return status of the endpoint (connected or not) */ private boolean checkConnected() { synchronized (this.so) { if ((this.endpoint != null) && (this.endpoint.isConnected())) { return true; } else { so.close(); throw new IllegalStateException("Received an MQTT packet from a not connected client (CONNECT not sent yet)"); } } } }
public void close() { synchronized (this.conn) { checkClosed(); this.conn.close(); this.cleanup(); } }
public void close() { synchronized (this.conn) { checkClosed(); this.conn.close(); this.cleanup(); } }
void sendCancelRequestMessage(int processId, int secretKey, Handler<AsyncResult<Void>> handler) { Buffer buffer = Buffer.buffer(16); buffer.appendInt(16); // cancel request code buffer.appendInt(80877102); buffer.appendInt(processId); buffer.appendInt(secretKey); socket.write(buffer, ar -> { if (ar.succeeded()) { // directly close this connection if (status == Status.CONNECTED) { status = Status.CLOSING; socket.close(); } handler.handle(Future.succeededFuture()); } else { handler.handle(Future.failedFuture(ar.cause())); } }); }
void sendCancelRequestMessage(int processId, int secretKey, Handler<AsyncResult<Void>> handler) { Buffer buffer = Buffer.buffer(16); buffer.appendInt(16); // cancel request code buffer.appendInt(80877102); buffer.appendInt(processId); buffer.appendInt(secretKey); socket.write(buffer, ar -> { if (ar.succeeded()) { // directly close this connection if (status == Status.CONNECTED) { status = Status.CLOSING; socket.close(); } handler.handle(Future.succeededFuture()); } else { handler.handle(Future.failedFuture(ar.cause())); } }); }
/** * See {@link MqttClient#disconnect(Handler)} for more details */ @Override public MqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler) { MqttFixedHeader fixedHeader = new MqttFixedHeader( MqttMessageType.DISCONNECT, false, AT_MOST_ONCE, false, 0 ); io.netty.handler.codec.mqtt.MqttMessage disconnect = MqttMessageFactory.newMessage(fixedHeader, null, null); this.write(disconnect); if (disconnectHandler != null) { disconnectHandler.handle(Future.succeededFuture()); } connection().close(); return this; }
/** * See {@link MqttClient#disconnect(Handler)} for more details */ @Override public MqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler) { MqttFixedHeader fixedHeader = new MqttFixedHeader( MqttMessageType.DISCONNECT, false, AT_MOST_ONCE, false, 0 ); io.netty.handler.codec.mqtt.MqttMessage disconnect = MqttMessageFactory.newMessage(fixedHeader, null, null); this.write(disconnect); if (disconnectHandler != null) { disconnectHandler.handle(Future.succeededFuture()); } connection().close(); return this; }