View Javadoc
1   /*
2    * Copyright 2016 The Lannister Project
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.anyflow.lannister.plugin;
18  
19  import java.util.Arrays;
20  
21  import io.netty.handler.codec.mqtt.MqttQoS;
22  
23  /**
24   * Represent MQTT message.
25   */
26  public interface IMessage {
27  	/**
28  	 * @return message identifier(packet identifier in MQTT 3.1.1)
29  	 */
30  	int id();
31  
32  	/**
33  	 * @return topic's name the message belongs to
34  	 */
35  	String topicName();
36  
37  	/**
38  	 * @return client identifier whose client published the message
39  	 */
40  	String publisherId();
41  
42  	/**
43  	 * @return message itself
44  	 */
45  	byte[] message();
46  
47  	/**
48  	 * @return message QoS. The value can be used different in client publishing
49  	 *         time and broker publishing time
50  	 */
51  	MqttQoS qos();
52  
53  	/**
54  	 * @return whether the message is retained or not
55  	 */
56  	boolean isRetain();
57  
58  	default String log() {
59  		return (new StringBuilder()).append("messageId=").append(id()).append(", topicName=").append(topicName())
60  				.append(", publisherId=").append(publisherId()).append(", message=").append(Arrays.toString(message()))
61  				.append(", qos=").append(qos()).append(", isRetain=").append(isRetain()).toString();
62  	}
63  }