View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.handler.codec.mqtt;
18  
19  import io.netty.buffer.ByteBuf;
20  import io.netty.buffer.ByteBufHolder;
21  import io.netty.util.IllegalReferenceCountException;
22  
23  /**
24   * See <a href="http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#publish">MQTTV3.1/publish</a>
25   */
26  public class MqttPublishMessage extends MqttMessage implements ByteBufHolder {
27  
28      public MqttPublishMessage(
29              MqttFixedHeader mqttFixedHeader,
30              MqttPublishVariableHeader variableHeader,
31              ByteBuf payload) {
32          super(mqttFixedHeader, variableHeader, payload);
33      }
34  
35      @Override
36      public MqttPublishVariableHeader variableHeader() {
37          return (MqttPublishVariableHeader) super.variableHeader();
38      }
39  
40      @Override
41      public ByteBuf payload() {
42          return content();
43      }
44  
45      @Override
46      public ByteBuf content() {
47          final ByteBuf data = (ByteBuf) super.payload();
48          if (data.refCnt() <= 0) {
49              throw new IllegalReferenceCountException(data.refCnt());
50          }
51          return data;
52      }
53  
54      @Override
55      public MqttPublishMessage copy() {
56          return replace(content().copy());
57      }
58  
59      @Override
60      public MqttPublishMessage duplicate() {
61          return replace(content().duplicate());
62      }
63  
64      @Override
65      public MqttPublishMessage retainedDuplicate() {
66          return replace(content().retainedDuplicate());
67      }
68  
69      @Override
70      public MqttPublishMessage replace(ByteBuf content) {
71          return new MqttPublishMessage(fixedHeader(), variableHeader(), content);
72      }
73  
74      @Override
75      public int refCnt() {
76          return content().refCnt();
77      }
78  
79      @Override
80      public MqttPublishMessage retain() {
81          content().retain();
82          return this;
83      }
84  
85      @Override
86      public MqttPublishMessage retain(int increment) {
87          content().retain(increment);
88          return this;
89      }
90  
91      @Override
92      public MqttPublishMessage touch() {
93          content().touch();
94          return this;
95      }
96  
97      @Override
98      public MqttPublishMessage touch(Object hint) {
99          content().touch(hint);
100         return this;
101     }
102 
103     @Override
104     public boolean release() {
105         return content().release();
106     }
107 
108     @Override
109     public boolean release(int decrement) {
110         return content().release(decrement);
111     }
112 
113 }