public MQTT(MQTT other) { this.host = other.host; this.localAddress = other.localAddress; this.sslContext = other.sslContext; this.dispatchQueue = other.dispatchQueue; this.blockingExecutor = other.blockingExecutor; this.maxReadRate = other.maxReadRate; this.maxWriteRate = other.maxWriteRate; this.trafficClass = other.trafficClass; this.receiveBufferSize = other.receiveBufferSize; this.sendBufferSize = other.sendBufferSize; this.useLocalHost = other.useLocalHost; this.connect = new CONNECT(other.connect); this.reconnectDelay = other.reconnectDelay; this.reconnectDelayMax = other.reconnectDelayMax; this.reconnectBackOffMultiplier = other.reconnectBackOffMultiplier; this.reconnectAttemptsMax = other.reconnectAttemptsMax; this.connectAttemptsMax = other.connectAttemptsMax; this.tracer = other.tracer; }
public UTF8Buffer getClientId() { return connect.clientId(); }
public UTF8Buffer getUserName() { return connect.userName(); }
switch(connect_message.version()) { case 3:case 4: break; default: connack.code(CONNACK.Code.CONNECTION_REFUSED_UNACCEPTED_PROTOCOL_VERSION); die(connack, "Unsupported protocol version: " + connect_message.version()); if( (connect_message.clientId() == null || connect_message.clientId().length==0) && !connect_message.cleanSession() ) { die(connack, "A clean session must be requested when no client id is provided."); UTF8Buffer client_id = connect_message.clientId(); security_context.user_$eq(Scala2Java.toString(connect_message.userName())); security_context.password_$eq(Scala2Java.toString(connect_message.password())); security_context.session_id_$eq(client_id.toString()); final short keep_alive = connect_message.keepAlive(); if (keep_alive > 0) { heart_beat_monitor.setReadInterval(((long) (keep_alive * 1.5)) * 1000);
try { if (event.messageType() == CONNECT.TYPE) { CONNECT connect = new CONNECT().decode(event); ConnectionParameters parameters = new ConnectionParameters(); if (connect.clientId() != null) { parameters.protocolClientId = connect.clientId().toString(); if (connect.userName() != null) { parameters.protocolUser = connect.userName().toString(); connect.userName(new UTF8Buffer(parameters.protocolUser)); append(received, connect.encode()); received.appendBuffer(tail);
public void onTransportError() { if (connect != null) { if (connected.get()) { if (connect.willTopic() != null && connect.willMessage() != null && !willSent) { willSent = true; try { PUBLISH publish = new PUBLISH(); publish.topicName(connect.willTopic()); publish.qos(connect.willQos()); publish.messageId(packetIdGenerator.getNextSequenceId(getClientId())); publish.payload(connect.willMessage()); publish.retain(connect.willRetain()); ActiveMQMessage message = convertMessage(publish); message.setProducerId(producerId); message.onSend(); sendToActiveMQ(message, null); } catch (Exception e) { LOG.warn("Failed to publish Will Message " + connect.willMessage()); } } // remove connection info sendToActiveMQ(connectionInfo.createRemoveCommand(), null); } } }
static private String toString(MQTTFrame frame) { if( frame == null ) return null; try { switch (frame.messageType()) { case PINGREQ.TYPE: return new PINGREQ().decode(frame).toString(); case PINGRESP.TYPE: return new PINGRESP().decode(frame).toString(); case CONNECT.TYPE: return new CONNECT().decode(frame).toString(); case DISCONNECT.TYPE: return new DISCONNECT().decode(frame).toString(); case SUBSCRIBE.TYPE: return new SUBSCRIBE().decode(frame).toString(); case UNSUBSCRIBE.TYPE: return new UNSUBSCRIBE().decode(frame).toString(); case PUBLISH.TYPE: return new PUBLISH().decode(frame).toString(); case PUBACK.TYPE: return new PUBACK().decode(frame).toString(); case PUBREC.TYPE: return new PUBREC().decode(frame).toString(); case PUBREL.TYPE: return new PUBREL().decode(frame).toString(); case PUBCOMP.TYPE: return new PUBCOMP().decode(frame).toString(); case CONNACK.TYPE: return new CONNACK().decode(frame).toString(); case SUBACK.TYPE: return new SUBACK().decode(frame).toString(); default: return frame.toString(); } } catch (Throwable e) { LOG.warn(e.getMessage(), e); return frame.toString(); } }
public boolean isCleanSession() { return connect.cleanSession(); }
public void onTransportError() { if (connect != null) { if (connected.get()) { if (connect.willTopic() != null && connect.willMessage() != null && !willSent) { willSent = true; try { PUBLISH publish = new PUBLISH(); publish.topicName(connect.willTopic()); publish.qos(connect.willQos()); publish.messageId(MQTTPacketIdGenerator.getNextSequenceId(getClientId())); publish.payload(connect.willMessage()); ActiveMQMessage message = convertMessage(publish); message.setProducerId(producerId); message.onSend(); sendToActiveMQ(message, null); } catch (Exception e) { LOG.warn("Failed to publish Will Message " + connect.willMessage()); } } // remove connection info sendToActiveMQ(connectionInfo.createRemoveCommand(), null); } } }
@Override public void call(Object o) { if (o instanceof MQTTFrame) { MQTTFrame command = (MQTTFrame) o; try { if (command.messageType() == CONNECT.TYPE) { connect_message = received(new CONNECT().decode(command)); on_mqtt_connect(); } else { die("Expecting an MQTT CONNECT message, but got: " + command.getClass()); } } catch (java.net.ProtocolException e) { die("Internal Server Error: bad mqtt command: " + command); } } else if ("failure".equals(o)) { } else { die("Internal Server Error: unexpected mqtt command: " + o.getClass()); } } };
if( mqtt.connect.clientId() == null ) { String id = hex(transport.getLocalAddress())+Long.toHexString(System.currentTimeMillis()/1000); if(id.length() > 23) { id = id.substring(0,23); mqtt.connect.clientId(utf8(id)); MQTTFrame encoded = mqtt.connect.encode(); boolean accepted = transport.offer(encoded); mqtt.tracer.onSend(encoded);
public void setWillTopic(UTF8Buffer willTopic) { connect.willTopic(willTopic); }
public void setWillMessage(UTF8Buffer willMessage) { connect.willMessage(willMessage); }
public String getVersion() { switch(connect.version()) { case 3: return "3.1"; case 4: return "3.1.1"; default: return "unknown"; } }
public short getKeepAlive() { return connect.keepAlive(); }
public void setPassword(UTF8Buffer password) { connect.password(password); }
if (connect.version() < 3 || connect.version() > 4) { CONNACK ack = new CONNACK(); ack.code(CONNACK.Code.CONNECTION_REFUSED_UNACCEPTED_PROTOCOL_VERSION); if (connect.clientId() != null) { clientId = connect.clientId().toString(); if (connect.userName() != null) { userName = connect.userName().toString(); if (connect.password() != null) { if (userName == null && connect.version() != V3_1) { passswd = connect.password().toString(); version = connect.version(); configureInactivityMonitor(connect.keepAlive()); } else { if (!connect.cleanSession()) { CONNACK ack = new CONNACK(); ack.code(CONNACK.Code.CONNECTION_REFUSED_IDENTIFIER_REJECTED);
try { if (event.messageType() == org.fusesource.mqtt.codec.CONNECT.TYPE) { CONNECT connect = new CONNECT().decode(event); ConnectionParameters parameters = new ConnectionParameters(); if( connect.clientId()!=null ) { parameters.protocolClientId = connect.clientId().toString(); if( connect.userName()!=null ) { parameters.protocolUser = connect.userName().toString(); connect.userName(new UTF8Buffer(parameters.protocolUser)); append(received, connect.encode()); received.appendBuffer(tail);