本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttQoS.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java MqttQoS.valueOf方法的具体用法?Java MqttQoS.valueOf怎么用?Java MqttQoS.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.mqtt.MqttQoS
的用法示例。
在下文中一共展示了MqttQoS.valueOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToInternal
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
/**
* Convert Map to InternalMessage
*
* @param map Map
* @return InternalMessage
*/
public static InternalMessage mapToInternal(Map<String, String> map) {
if (map == null || map.isEmpty()) return null;
int type = Integer.parseInt(map.get("type"));
if (type == MqttMessageType.PUBLISH.value()) {
byte[] payload = null;
if (map.get("payload") != null) try {
payload = map.get("payload").getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException ignore) {
}
return new InternalMessage<>(
MqttMessageType.PUBLISH,
BooleanUtils.toBoolean(map.getOrDefault("dup", "0"), "1", "0"),
MqttQoS.valueOf(Integer.parseInt(map.getOrDefault("qos", "0"))),
BooleanUtils.toBoolean(map.getOrDefault("retain", "0"), "1", "0"),
MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
map.get("clientId"),
map.get("userName"),
null,
new Publish(
map.get("topicName"),
Integer.parseInt(map.getOrDefault("packetId", "0")),
payload
));
} else if (type == MqttMessageType.PUBREL.value()) {
return new InternalMessage<>(
MqttMessageType.PUBREL,
false,
MqttQoS.AT_LEAST_ONCE,
false,
MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
map.get("clientId"),
map.get("userName"),
null,
new PacketId(Integer.parseInt(map.getOrDefault("packetId", "0"))));
} else {
throw new IllegalArgumentException("Invalid in-flight MQTT message type: " + MqttMessageType.valueOf(type));
}
}
示例2: newWill
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
private Message newWill(String clientId, MqttConnectMessage conn) {
if (!conn.variableHeader().isWillFlag()) { return null; } // [MQTT-3.1.2-12]
return new Message(-1, conn.payload().willTopic(), clientId,
conn.payload().willMessage().getBytes(CharsetUtil.UTF_8),
MqttQoS.valueOf(conn.variableHeader().willQos()), conn.variableHeader().isWillRetain());
}
示例3: readData
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
@Override
public void readData(ObjectDataInput in) throws IOException {
id = in.readInt();
topicName = in.readUTF();
publisherId = in.readUTF();
message = in.readByteArray();
int rawInt = in.readInt();
qos = rawInt != Byte.MIN_VALUE ? MqttQoS.valueOf(rawInt) : null;
isRetain = in.readBoolean();
}
示例4: readData
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
@Override
public void readData(ObjectDataInput in) throws IOException {
super.readData(in);
Byte rawByte = in.readByte();
status = rawByte != Byte.MIN_VALUE ? Status.valueOf(rawByte) : null;
int rawInt = in.readInt();
qos = rawInt != Byte.MIN_VALUE ? MqttQoS.valueOf(rawInt) : null;
}
示例5: readData
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
@Override
public void readData(ObjectDataInput in) throws IOException {
clientId = in.readUTF();
topicFilter = in.readUTF();
int rawInt = in.readInt();
qos = rawInt != Integer.MIN_VALUE ? MqttQoS.valueOf(rawInt) : null;
}
示例6: from
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
/**
* Return an AMQP_WILL message from the raw AMQP one
*
* @param message raw AMQP message
* @return AMQP_WILL message
*/
public static AmqpWillMessage from(Message message) {
if (!message.getSubject().equals(AMQP_SUBJECT)) {
throw new IllegalArgumentException(String.format("AMQP message subject is no s%", AMQP_SUBJECT));
}
MessageAnnotations messageAnnotations = message.getMessageAnnotations();
if (messageAnnotations == null) {
throw new IllegalArgumentException("AMQP message has no annotations");
} else {
boolean isRetain = false;
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
}
MqttQoS qos;
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) {
int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION));
qos = MqttQoS.valueOf(value);
} else {
if (message.getHeader() != null) {
// if qos annotation isn't present, fallback to "durable" header field
qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
} else {
qos = MqttQoS.AT_MOST_ONCE;
}
}
String topic = message.getAddress();
Section section = message.getBody();
if ((section != null) && (section instanceof Data)) {
Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
return new AmqpWillMessage(isRetain, topic, qos, payload);
} else {
throw new IllegalArgumentException("AMQP message wrong body type");
}
}
}
示例7: from
import io.netty.handler.codec.mqtt.MqttQoS; //导入方法依赖的package包/类
/**
* Return an AMQP_PUBLISH message from the raw AMQP one
*
* @param message raw AMQP message
* @return AMQP_PUBLISH message
*/
public static AmqpPublishMessage from(Message message) {
boolean isRetain = false;
MqttQoS qos = MqttQoS.AT_MOST_ONCE;
// raw AMQP messages published from native AMQP clients could not have annotations
MessageAnnotations messageAnnotations = message.getMessageAnnotations();
if (messageAnnotations == null) {
if (message.getHeader() != null) {
// if qos annotation isn't present, fallback to "durable" header field
qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
}
} else {
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
}
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) {
int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION));
qos = MqttQoS.valueOf(value);
} else {
if (message.getHeader() != null) {
// if qos annotation isn't present, fallback to "durable" header field
qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
}
}
}
boolean isDup = (message.getDeliveryCount() > 0);
String topic = message.getAddress();
// TODO: to remove
// workaround for the Artemis broker which change the original "To" property
// in the AMQP message when message-id is null
ApplicationProperties applicationProperties = message.getApplicationProperties();
if (applicationProperties != null) {
Object amqOrigAddress = applicationProperties.getValue().get("_AMQ_ORIG_ADDRESS");
topic = (amqOrigAddress != null) ? amqOrigAddress.toString() : topic;
}
Section section = message.getBody();
if ((section != null) && (section instanceof Data)) {
Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
return new AmqpPublishMessage(message.getMessageId(), qos, isDup, isRetain, topic, payload);
} else {
throw new IllegalArgumentException("AMQP message wrong body type");
}
}