Moved parser_commons submodule to org.eclipse.moquette
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.commons;
|
||||
|
||||
/**
|
||||
* Contains some useful constants.
|
||||
*/
|
||||
public class Constants {
|
||||
public static final int PORT = 1883;
|
||||
public static final int WEBSOCKET_PORT = 8080;
|
||||
public static final String HOST = "0.0.0.0";
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT = 10;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class MQTTException extends RuntimeException {
|
||||
|
||||
public MQTTException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MQTTException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public MQTTException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public MQTTException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto;
|
||||
|
||||
import org.eclipse.moquette.proto.messages.AbstractMessage;
|
||||
|
||||
/**
|
||||
* Common utils methodd used in codecs.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static final int MAX_LENGTH_LIMIT = 268435455;
|
||||
|
||||
// /**
|
||||
// * Read 2 bytes from in buffer first MSB, and then LSB returning as int.
|
||||
// */
|
||||
// static int readWord(IoBuffer in) {
|
||||
// int msb = in.get() & 0x00FF; //remove sign extension due to casting
|
||||
// int lsb = in.get() & 0x00FF;
|
||||
// msb = (msb << 8) | lsb ;
|
||||
// return msb;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Writes as 2 bytes the int value into buffer first MSB, and then LSB.
|
||||
// */
|
||||
// static void writeWord(IoBuffer out, int value) {
|
||||
// out.put((byte) ((value & 0xFF00) >> 8)); //msb
|
||||
// out.put((byte) (value & 0x00FF)); //lsb
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Decode the variable remaining lenght as defined in MQTT v3.1 specification
|
||||
// * (section 2.1).
|
||||
// *
|
||||
// * @return the decoded length or -1 if needed more data to decode the length field.
|
||||
// */
|
||||
// static int decodeRemainingLenght(IoBuffer in) {
|
||||
// int multiplier = 1;
|
||||
// int value = 0;
|
||||
// byte digit;
|
||||
// do {
|
||||
// if (in.remaining() < 1) {
|
||||
// return -1;
|
||||
// }
|
||||
// digit = in.get();
|
||||
// value += (digit & 0x7F) * multiplier;
|
||||
// multiplier *= 128;
|
||||
// } while ((digit & 0x80) != 0);
|
||||
// return value;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return the number of bytes to encode the gicen remaining length value
|
||||
*/
|
||||
static int numBytesToEncode(int len) {
|
||||
if (0 <= len && len <= 127) return 1;
|
||||
if (128 <= len && len <= 16383) return 2;
|
||||
if (16384 <= len && len <= 2097151) return 3;
|
||||
if (2097152 <= len && len <= 268435455) return 4;
|
||||
throw new IllegalArgumentException("value shoul be in the range [0..268435455]");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Encode the value in the format defined in specification as variable length
|
||||
// * array.
|
||||
// *
|
||||
// * @throws IllegalArgumentException if the value is not in the specification bounds
|
||||
// * [0..268435455].
|
||||
// */
|
||||
// static IoBuffer encodeRemainingLength(int value) throws IllegalAccessException {
|
||||
// if (value > MAX_LENGTH_LIMIT || value < 0) {
|
||||
// throw new IllegalAccessException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
|
||||
// }
|
||||
//
|
||||
// IoBuffer encoded = IoBuffer.allocate(4);
|
||||
// byte digit;
|
||||
// do {
|
||||
// digit = (byte) (value % 128);
|
||||
// value = value / 128;
|
||||
// // if there are more digits to encode, set the top bit of this digit
|
||||
// if (value > 0) {
|
||||
// digit = (byte) (digit | 0x80);
|
||||
// }
|
||||
// encoded.put(digit);
|
||||
// } while (value > 0);
|
||||
// encoded.flip();
|
||||
// return encoded;
|
||||
// }
|
||||
//
|
||||
// static MessageDecoderResult checkDecodable(byte type, IoBuffer in) {
|
||||
// if (in.remaining() < 1) {
|
||||
// return MessageDecoderResult.NEED_DATA;
|
||||
// }
|
||||
// byte h1 = in.get();
|
||||
// byte messageType = (byte) ((h1 & 0x00F0) >> 4);
|
||||
//
|
||||
// int remainingLength = Utils.decodeRemainingLenght(in);
|
||||
// if (remainingLength == -1) {
|
||||
// return MessageDecoderResult.NEED_DATA;
|
||||
// }
|
||||
//
|
||||
// //check remaining length
|
||||
// if (in.remaining() < remainingLength) {
|
||||
// return MessageDecoderResult.NEED_DATA;
|
||||
// }
|
||||
//
|
||||
// return messageType == type ? MessageDecoderResult.OK : MessageDecoderResult.NOT_OK;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Return the IoBuffer with string encoded as MSB, LSB and UTF-8 encoded
|
||||
// * string content.
|
||||
// */
|
||||
// static IoBuffer encodeString(String str) {
|
||||
// IoBuffer out = IoBuffer.allocate(2).setAutoExpand(true);
|
||||
// byte[] raw;
|
||||
// try {
|
||||
// raw = str.getBytes("UTF-8");
|
||||
// //NB every Java platform has got UTF-8 encoding by default, so this
|
||||
// //exception are never raised.
|
||||
// } catch (UnsupportedEncodingException ex) {
|
||||
// LoggerFactory.getLogger(ConnectEncoder.class).error(null, ex);
|
||||
// return null;
|
||||
// }
|
||||
// Utils.writeWord(out, raw.length);
|
||||
// out.put(raw).flip();
|
||||
// return out;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Load a string from the given buffer, reading first the two bytes of len
|
||||
// * and then the UTF-8 bytes of the string.
|
||||
// *
|
||||
// * @return the decoded string or null if NEED_DATA
|
||||
// */
|
||||
// static String decodeString(IoBuffer in) throws UnsupportedEncodingException {
|
||||
// if (in.remaining() < 2) {
|
||||
// return null;
|
||||
// }
|
||||
// int strLen = Utils.readWord(in);
|
||||
// if (in.remaining() < strLen) {
|
||||
// return null;
|
||||
// }
|
||||
// byte[] strRaw = new byte[strLen];
|
||||
// in.get(strRaw);
|
||||
//
|
||||
// return new String(strRaw, "UTF-8");
|
||||
// }
|
||||
|
||||
static byte encodeFlags(AbstractMessage message) {
|
||||
byte flags = 0;
|
||||
if (message.isDupFlag()) {
|
||||
flags |= 0x08;
|
||||
}
|
||||
if (message.isRetainFlag()) {
|
||||
flags |= 0x01;
|
||||
}
|
||||
|
||||
flags |= ((message.getQos().ordinal() & 0x03) << 1);
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts MQTT message type to a textual description.
|
||||
* */
|
||||
public static String msgType2String(int type) {
|
||||
switch (type) {
|
||||
case AbstractMessage.CONNECT: return "CONNECT";
|
||||
case AbstractMessage.CONNACK: return "CONNACK";
|
||||
case AbstractMessage.PUBLISH: return "PUBLISH";
|
||||
case AbstractMessage.PUBACK: return "PUBACK";
|
||||
case AbstractMessage.PUBREC: return "PUBREC";
|
||||
case AbstractMessage.PUBREL: return "PUBREL";
|
||||
case AbstractMessage.PUBCOMP: return "PUBCOMP";
|
||||
case AbstractMessage.SUBSCRIBE: return "SUBSCRIBE";
|
||||
case AbstractMessage.SUBACK: return "SUBACK";
|
||||
case AbstractMessage.UNSUBSCRIBE: return "UNSUBSCRIBE";
|
||||
case AbstractMessage.UNSUBACK: return "UNSUBACK";
|
||||
case AbstractMessage.PINGREQ: return "PINGREQ";
|
||||
case AbstractMessage.PINGRESP: return "PINGRESP";
|
||||
case AbstractMessage.DISCONNECT: return "DISCONNECT";
|
||||
default: throw new RuntimeException("Can't decode message type " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Basic abstract message for all MQTT protocol messages.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public abstract class AbstractMessage {
|
||||
|
||||
public static final byte CONNECT = 1; // Client request to connect to Server
|
||||
public static final byte CONNACK = 2; // Connect Acknowledgment
|
||||
public static final byte PUBLISH = 3; // Publish message
|
||||
public static final byte PUBACK = 4; // Publish Acknowledgment
|
||||
public static final byte PUBREC = 5; //Publish Received (assured delivery part 1)
|
||||
public static final byte PUBREL = 6; // Publish Release (assured delivery part 2)
|
||||
public static final byte PUBCOMP = 7; //Publish Complete (assured delivery part 3)
|
||||
public static final byte SUBSCRIBE = 8; //Client Subscribe request
|
||||
public static final byte SUBACK = 9; // Subscribe Acknowledgment
|
||||
public static final byte UNSUBSCRIBE = 10; //Client Unsubscribe request
|
||||
public static final byte UNSUBACK = 11; // Unsubscribe Acknowledgment
|
||||
public static final byte PINGREQ = 12; //PING Request
|
||||
public static final byte PINGRESP = 13; //PING Response
|
||||
public static final byte DISCONNECT = 14; //Client is Disconnecting
|
||||
|
||||
public static enum QOSType {
|
||||
MOST_ONE, LEAST_ONE, EXACTLY_ONCE, RESERVED;
|
||||
|
||||
public static String formatQoS(QOSType qos) {
|
||||
return String.format("%d - %s", qos.ordinal(), qos.name());
|
||||
}
|
||||
}
|
||||
//type
|
||||
protected boolean m_dupFlag;
|
||||
protected QOSType m_qos;
|
||||
protected boolean m_retainFlag;
|
||||
protected int m_remainingLength;
|
||||
protected byte m_messageType;
|
||||
|
||||
public byte getMessageType() {
|
||||
return m_messageType;
|
||||
}
|
||||
|
||||
public void setMessageType(byte messageType) {
|
||||
this.m_messageType = messageType;
|
||||
}
|
||||
|
||||
public boolean isDupFlag() {
|
||||
return m_dupFlag;
|
||||
}
|
||||
|
||||
public void setDupFlag(boolean dupFlag) {
|
||||
this.m_dupFlag = dupFlag;
|
||||
}
|
||||
|
||||
public QOSType getQos() {
|
||||
return m_qos;
|
||||
}
|
||||
|
||||
public void setQos(QOSType qos) {
|
||||
this.m_qos = qos;
|
||||
}
|
||||
|
||||
public boolean isRetainFlag() {
|
||||
return m_retainFlag;
|
||||
}
|
||||
|
||||
public void setRetainFlag(boolean retainFlag) {
|
||||
this.m_retainFlag = retainFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* TOBE used only internally
|
||||
*/
|
||||
public int getRemainingLength() {
|
||||
return m_remainingLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* TOBE used only internally
|
||||
*/
|
||||
public void setRemainingLength(int remainingLength) {
|
||||
this.m_remainingLength = remainingLength;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* The attributes Qos, Dup and Retain aren't used.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class ConnAckMessage extends AbstractMessage {
|
||||
public static final byte CONNECTION_ACCEPTED = 0x00;
|
||||
public static final byte UNNACEPTABLE_PROTOCOL_VERSION = 0x01;
|
||||
public static final byte IDENTIFIER_REJECTED = 0x02;
|
||||
public static final byte SERVER_UNAVAILABLE = 0x03;
|
||||
public static final byte BAD_USERNAME_OR_PASSWORD = 0x04;
|
||||
public static final byte NOT_AUTHORIZED = 0x05;
|
||||
|
||||
private byte m_returnCode;
|
||||
private boolean sessionPresent;
|
||||
|
||||
public ConnAckMessage() {
|
||||
m_messageType = AbstractMessage.CONNACK;
|
||||
}
|
||||
|
||||
public byte getReturnCode() {
|
||||
return m_returnCode;
|
||||
}
|
||||
|
||||
public void setReturnCode(byte returnCode) {
|
||||
this.m_returnCode = returnCode;
|
||||
}
|
||||
|
||||
public boolean isSessionPresent() {
|
||||
return this.sessionPresent;
|
||||
}
|
||||
|
||||
public void setSessionPresent(boolean present) {
|
||||
this.sessionPresent = present;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* The attributes Qos, Dup and Retain aren't used for Connect message
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class ConnectMessage extends AbstractMessage {
|
||||
String m_protocolName;
|
||||
byte m_procotolVersion;
|
||||
|
||||
//Connection flags
|
||||
boolean m_cleanSession;
|
||||
boolean m_willFlag;
|
||||
byte m_willQos;
|
||||
boolean m_willRetain;
|
||||
boolean m_passwordFlag;
|
||||
boolean m_userFlag;
|
||||
int m_keepAlive;
|
||||
|
||||
//Variable part
|
||||
String m_username;
|
||||
String m_password;
|
||||
String m_clientID;
|
||||
String m_willtopic;
|
||||
String m_willMessage;
|
||||
|
||||
public ConnectMessage() {
|
||||
m_messageType = AbstractMessage.CONNECT;
|
||||
}
|
||||
|
||||
public boolean isCleanSession() {
|
||||
return m_cleanSession;
|
||||
}
|
||||
|
||||
public void setCleanSession(boolean cleanSession) {
|
||||
this.m_cleanSession = cleanSession;
|
||||
}
|
||||
|
||||
public int getKeepAlive() {
|
||||
return m_keepAlive;
|
||||
}
|
||||
|
||||
public void setKeepAlive(int keepAlive) {
|
||||
this.m_keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
public boolean isPasswordFlag() {
|
||||
return m_passwordFlag;
|
||||
}
|
||||
|
||||
public void setPasswordFlag(boolean passwordFlag) {
|
||||
this.m_passwordFlag = passwordFlag;
|
||||
}
|
||||
|
||||
public byte getProcotolVersion() {
|
||||
return m_procotolVersion;
|
||||
}
|
||||
|
||||
public void setProcotolVersion(byte procotolVersion) {
|
||||
this.m_procotolVersion = procotolVersion;
|
||||
}
|
||||
|
||||
public String getProtocolName() {
|
||||
return m_protocolName;
|
||||
}
|
||||
|
||||
public void setProtocolName(String protocolName) {
|
||||
this.m_protocolName = protocolName;
|
||||
}
|
||||
|
||||
public boolean isUserFlag() {
|
||||
return m_userFlag;
|
||||
}
|
||||
|
||||
public void setUserFlag(boolean userFlag) {
|
||||
this.m_userFlag = userFlag;
|
||||
}
|
||||
|
||||
public boolean isWillFlag() {
|
||||
return m_willFlag;
|
||||
}
|
||||
|
||||
public void setWillFlag(boolean willFlag) {
|
||||
this.m_willFlag = willFlag;
|
||||
}
|
||||
|
||||
public byte getWillQos() {
|
||||
return m_willQos;
|
||||
}
|
||||
|
||||
public void setWillQos(byte willQos) {
|
||||
this.m_willQos = willQos;
|
||||
}
|
||||
|
||||
public boolean isWillRetain() {
|
||||
return m_willRetain;
|
||||
}
|
||||
|
||||
public void setWillRetain(boolean willRetain) {
|
||||
this.m_willRetain = willRetain;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return m_password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.m_password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return m_username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.m_username = username;
|
||||
}
|
||||
|
||||
public String getClientID() {
|
||||
return m_clientID;
|
||||
}
|
||||
|
||||
public void setClientID(String clientID) {
|
||||
this.m_clientID = clientID;
|
||||
}
|
||||
|
||||
public String getWillTopic() {
|
||||
return m_willtopic;
|
||||
}
|
||||
|
||||
public void setWillTopic(String topic) {
|
||||
this.m_willtopic = topic;
|
||||
}
|
||||
|
||||
public String getWillMessage() {
|
||||
return m_willMessage;
|
||||
}
|
||||
|
||||
public void setWillMessage(String willMessage) {
|
||||
this.m_willMessage = willMessage;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Doesn't care DUP, QOS and RETAIN flags.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class DisconnectMessage extends ZeroLengthMessage {
|
||||
|
||||
public DisconnectMessage() {
|
||||
m_messageType = AbstractMessage.DISCONNECT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Base class for alla the messages that carries only MessageID. (PUBACK, PUBREC,
|
||||
* PUBREL, PUBCOMP, UNSUBACK)
|
||||
*
|
||||
* The flags dup, QOS and Retained doesn't take care.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public abstract class MessageIDMessage extends AbstractMessage {
|
||||
private Integer m_messageID; //could be null if Qos is == 0
|
||||
|
||||
public Integer getMessageID() {
|
||||
return m_messageID;
|
||||
}
|
||||
|
||||
public void setMessageID(Integer messageID) {
|
||||
this.m_messageID = messageID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Doesn't care DUP, QOS and RETAIN flags.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PingReqMessage extends ZeroLengthMessage {
|
||||
|
||||
public PingReqMessage() {
|
||||
m_messageType = AbstractMessage.PINGREQ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Doesn't care DUP, QOS and RETAIN flags.
|
||||
* @author andrea
|
||||
*/
|
||||
public class PingRespMessage extends ZeroLengthMessage {
|
||||
|
||||
public PingRespMessage() {
|
||||
m_messageType = AbstractMessage.PINGRESP;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Placeholder for PUBACK message.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PubAckMessage extends MessageIDMessage {
|
||||
|
||||
public PubAckMessage() {
|
||||
m_messageType = AbstractMessage.PUBACK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PubCompMessage extends MessageIDMessage {
|
||||
|
||||
public PubCompMessage() {
|
||||
m_messageType = AbstractMessage.PUBCOMP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
* Placeholder for PUBREC message.
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PubRecMessage extends MessageIDMessage {
|
||||
|
||||
public PubRecMessage() {
|
||||
m_messageType = AbstractMessage.PUBREC;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PubRelMessage extends MessageIDMessage {
|
||||
|
||||
public PubRelMessage() {
|
||||
m_messageType = AbstractMessage.PUBREL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class PublishMessage extends MessageIDMessage {
|
||||
|
||||
private String m_topicName;
|
||||
// private Integer m_messageID; //could be null if Qos is == 0
|
||||
private ByteBuffer m_payload;
|
||||
|
||||
/*public Integer getMessageID() {
|
||||
return m_messageID;
|
||||
}
|
||||
|
||||
public void setMessageID(Integer messageID) {
|
||||
this.m_messageID = messageID;
|
||||
}*/
|
||||
|
||||
public PublishMessage() {
|
||||
m_messageType = AbstractMessage.PUBLISH;
|
||||
}
|
||||
|
||||
public String getTopicName() {
|
||||
return m_topicName;
|
||||
}
|
||||
|
||||
public void setTopicName(String topicName) {
|
||||
this.m_topicName = topicName;
|
||||
}
|
||||
|
||||
public ByteBuffer getPayload() {
|
||||
return m_payload;
|
||||
}
|
||||
|
||||
public void setPayload(ByteBuffer payload) {
|
||||
this.m_payload = payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class SubAckMessage extends MessageIDMessage {
|
||||
|
||||
List<QOSType> m_types = new ArrayList<QOSType>();
|
||||
|
||||
public SubAckMessage() {
|
||||
m_messageType = AbstractMessage.SUBACK;
|
||||
}
|
||||
|
||||
public List<QOSType> types() {
|
||||
return m_types;
|
||||
}
|
||||
|
||||
public void addType(QOSType type) {
|
||||
m_types.add(type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class SubscribeMessage extends MessageIDMessage {
|
||||
|
||||
public static class Couple {
|
||||
|
||||
private byte m_qos;
|
||||
private String m_topicFilter;
|
||||
|
||||
public Couple(byte qos, String topic) {
|
||||
m_qos = qos;
|
||||
m_topicFilter = topic;
|
||||
}
|
||||
|
||||
public byte getQos() {
|
||||
return m_qos;
|
||||
}
|
||||
|
||||
public String getTopicFilter() {
|
||||
return m_topicFilter;
|
||||
}
|
||||
}
|
||||
private List<Couple> m_subscriptions = new ArrayList<Couple>();
|
||||
|
||||
public SubscribeMessage() {
|
||||
//Subscribe has always QoS 1
|
||||
m_messageType = AbstractMessage.SUBSCRIBE;
|
||||
m_qos = AbstractMessage.QOSType.LEAST_ONE;
|
||||
}
|
||||
|
||||
public List<Couple> subscriptions() {
|
||||
return m_subscriptions;
|
||||
}
|
||||
|
||||
public void addSubscription(Couple subscription) {
|
||||
m_subscriptions.add(subscription);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class UnsubAckMessage extends MessageIDMessage {
|
||||
|
||||
public UnsubAckMessage() {
|
||||
m_messageType = AbstractMessage.UNSUBACK;
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class UnsubscribeMessage extends MessageIDMessage {
|
||||
List<String> m_types = new ArrayList<String>();
|
||||
|
||||
public UnsubscribeMessage() {
|
||||
m_messageType = AbstractMessage.UNSUBSCRIBE;
|
||||
}
|
||||
|
||||
public List<String> topicFilters() {
|
||||
return m_types;
|
||||
}
|
||||
|
||||
public void addTopicFilter(String type) {
|
||||
m_types.add(type);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package org.eclipse.moquette.proto.messages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public abstract class ZeroLengthMessage extends AbstractMessage {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user