查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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    *   https://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.util.internal.StringUtil;
20  
21  /**
22   * Variable Header for the {@link MqttConnectMessage}
23   */
24  public final class MqttConnectVariableHeader {
25  
26      private final String name;
27      private final int version;
28      private final boolean hasUserName;
29      private final boolean hasPassword;
30      private final boolean isWillRetain;
31      private final int willQos;
32      private final boolean isWillFlag;
33      private final boolean isCleanSession;
34      private final int keepAliveTimeSeconds;
35      private final MqttProperties properties;
36  
37      public MqttConnectVariableHeader(
38              String name,
39              int version,
40              boolean hasUserName,
41              boolean hasPassword,
42              boolean isWillRetain,
43              int willQos,
44              boolean isWillFlag,
45              boolean isCleanSession,
46              int keepAliveTimeSeconds) {
47          this(name,
48                  version,
49                  hasUserName,
50                  hasPassword,
51                  isWillRetain,
52                  willQos,
53                  isWillFlag,
54                  isCleanSession,
55                  keepAliveTimeSeconds,
56                  MqttProperties.NO_PROPERTIES);
57      }
58  
59      public MqttConnectVariableHeader(
60              String name,
61              int version,
62              boolean hasUserName,
63              boolean hasPassword,
64              boolean isWillRetain,
65              int willQos,
66              boolean isWillFlag,
67              boolean isCleanSession,
68              int keepAliveTimeSeconds,
69              MqttProperties properties) {
70          this.name = name;
71          this.version = version;
72          this.hasUserName = hasUserName;
73          this.hasPassword = hasPassword;
74          this.isWillRetain = isWillRetain;
75          this.willQos = willQos;
76          this.isWillFlag = isWillFlag;
77          this.isCleanSession = isCleanSession;
78          this.keepAliveTimeSeconds = keepAliveTimeSeconds;
79          this.properties = MqttProperties.withEmptyDefaults(properties);
80      }
81  
82      public String name() {
83          return name;
84      }
85  
86      public int version() {
87          return version;
88      }
89  
90      public boolean hasUserName() {
91          return hasUserName;
92      }
93  
94      public boolean hasPassword() {
95          return hasPassword;
96      }
97  
98      public boolean isWillRetain() {
99          return isWillRetain;
100     }
101 
102     public int willQos() {
103         return willQos;
104     }
105 
106     public boolean isWillFlag() {
107         return isWillFlag;
108     }
109 
110     public boolean isCleanSession() {
111         return isCleanSession;
112     }
113 
114     public int keepAliveTimeSeconds() {
115         return keepAliveTimeSeconds;
116     }
117 
118     public MqttProperties properties() {
119         return properties;
120     }
121 
122     @Override
123     public String toString() {
124         return new StringBuilder(StringUtil.simpleClassName(this))
125             .append('[')
126             .append("name=").append(name)
127             .append(", version=").append(version)
128             .append(", hasUserName=").append(hasUserName)
129             .append(", hasPassword=").append(hasPassword)
130             .append(", isWillRetain=").append(isWillRetain)
131             .append(", isWillFlag=").append(isWillFlag)
132             .append(", isCleanSession=").append(isCleanSession)
133             .append(", keepAliveTimeSeconds=").append(keepAliveTimeSeconds)
134             .append(']')
135             .toString();
136     }
137 }