Message.java 3.2 KB
Newer Older
如梦技术's avatar
如梦技术 已提交
1
/*
2
 * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net).
如梦技术's avatar
如梦技术 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.dreamlu.iot.mqtt.core.server.model;

import java.io.Serializable;
import java.util.Arrays;
21
import java.util.Objects;
如梦技术's avatar
如梦技术 已提交
22 23 24 25 26 27 28

/**
 * 消息模型,用于存储
 *
 * @author L.cm
 */
public class Message implements Serializable {
29 30 31 32

	/**
	 * 客户端 id
	 */
如梦技术's avatar
如梦技术 已提交
33
	private String clientId;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
	/**
	 * 消息类型
	 */
	private int messageType;
	/**
	 * topic
	 */
	private String topic;
	/**
	 * qos
	 */
	private int qos;
	/**
	 * retain
	 */
	private boolean retain;
	/**
	 * 是否重发
	 */
	private boolean dup;
	/**
	 * 消息内容
	 */
如梦技术's avatar
如梦技术 已提交
57
	private byte[] payload;
58 59 60
	/**
	 * 存储时间
	 */
61
	private long timestamp;
如梦技术's avatar
如梦技术 已提交
62 63 64 65 66 67 68 69 70

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

71 72
	public int getMessageType() {
		return messageType;
如梦技术's avatar
如梦技术 已提交
73 74
	}

75 76
	public void setMessageType(int messageType) {
		this.messageType = messageType;
如梦技术's avatar
如梦技术 已提交
77 78
	}

79 80
	public String getTopic() {
		return topic;
如梦技术's avatar
如梦技术 已提交
81 82
	}

83 84
	public void setTopic(String topic) {
		this.topic = topic;
如梦技术's avatar
如梦技术 已提交
85 86
	}

87 88
	public int getQos() {
		return qos;
如梦技术's avatar
如梦技术 已提交
89 90
	}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	public void setQos(int qos) {
		this.qos = qos;
	}

	public boolean isRetain() {
		return retain;
	}

	public void setRetain(boolean retain) {
		this.retain = retain;
	}

	public boolean isDup() {
		return dup;
	}

	public void setDup(boolean dup) {
		this.dup = dup;
如梦技术's avatar
如梦技术 已提交
109 110 111 112 113 114 115 116 117 118
	}

	public byte[] getPayload() {
		return payload;
	}

	public void setPayload(byte[] payload) {
		this.payload = payload;
	}

119 120
	public long getTimestamp() {
		return timestamp;
如梦技术's avatar
如梦技术 已提交
121 122
	}

123 124
	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
如梦技术's avatar
如梦技术 已提交
125 126
	}

127 128 129 130 131 132 133 134 135 136 137 138 139
	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}
		Message message = (Message) o;
		return messageType == message.messageType &&
			qos == message.qos &&
			retain == message.retain &&
			dup == message.dup &&
140
			timestamp == message.timestamp &&
141 142 143 144 145 146 147
			Objects.equals(clientId, message.clientId) &&
			Objects.equals(topic, message.topic) &&
			Arrays.equals(payload, message.payload);
	}

	@Override
	public int hashCode() {
148
		int result = Objects.hash(clientId, messageType, topic, qos, retain, dup, timestamp);
149 150 151 152
		result = 31 * result + Arrays.hashCode(payload);
		return result;
	}

如梦技术's avatar
如梦技术 已提交
153 154
	@Override
	public String toString() {
155
		return "Message{" +
如梦技术's avatar
如梦技术 已提交
156 157
			"clientId='" + clientId + '\'' +
			", messageType=" + messageType +
158 159 160 161
			", topic='" + topic + '\'' +
			", qos=" + qos +
			", retain=" + retain +
			", dup=" + dup +
如梦技术's avatar
如梦技术 已提交
162
			", payload=" + Arrays.toString(payload) +
163
			", timestamp=" + timestamp +
如梦技术's avatar
如梦技术 已提交
164 165 166
			'}';
	}
}