本文整理汇总了Java中io.netty.channel.Channel.attr方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.attr方法的具体用法?Java Channel.attr怎么用?Java Channel.attr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.attr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConsoleUser
import io.netty.channel.Channel; //导入方法依赖的package包/类
private ConsoleUser getConsoleUser(Channel channel) {
Attribute<String> attr = channel.attr(USERNAME_KEY);
if (attr == null) {
return null;
}
String username = attr.get();
if (username == null) {
return null;
}
return users.get(username);
}
示例2: pubcomp
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void pubcomp(MqttMessage mqttPubAckMessage, Channel ch){
int messageId = ((MqttMessageIdVariableHeader)mqttPubAckMessage.variableHeader()).messageId();
Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
ChannelInfo channelInfo = attr.get();
MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
if (session == null) return;
QoSMessagePack messagePack = session.getMessageList().get(messageId);
if (messagePack == null) return;
session.removeMessageTask(messageId);
}
示例3: decodeAndHuntMessage
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 「内部使用」将 TCP 帧解码并转换为消息对象,而后传递至 Server
*
* @param head TCP 帧头
* @param subMsgId TCP 子帧功能位
* @param data TCP 子帧数据体
* @param channel 该消息帧的容器 Channel
*/
public void decodeAndHuntMessage(FrameMajorHeader head, int subMsgId, byte[] data, Channel channel) {
BaseMsg msg = msgProcessor.decode(head, subMsgId, data);
if (msg == null) {
logger.warn("帧解析出错");
return;
}
logger.info("收到正常消息对象:「" + msg.getMsgDetail() + "」");
switch (msg.getJointMsgFlag()) {
case JointMsgType.HeartBeat:
Attribute<Integer> key = channel.attr(AttributeKey.valueOf("ID"));
MsgReplyNormal replyHeartbeat = MsgCodecReplyNormal.createByBaseMsg(MsgCodecHeartbeat.create(key.get()));
logger.info("已生成并发送正常回复消息对象:「" + replyHeartbeat.getMsgDetail() + "」");
sendMessageToTcp(replyHeartbeat);
break;
default:
//剩下的均为正常需回复消息
server.huntMessage(msg);
MsgReplyNormal replyNormal = MsgCodecReplyNormal.createByBaseMsg(msg);
if (replyNormal == null) {
logger.warn("生成正常回复消息对象出错");
return;
}
logger.info("已生成并发送正常回复消息对象:「" + replyNormal.getMsgDetail() + "」");
sendMessageToTcp(replyNormal);
}
}
示例4: activeChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 保存已激活的 Channel
*
* @param channel 已激活的 Channel
*/
public void activeChannel(Channel channel) {
Attribute<Integer> key = channel.attr(AttributeKey.valueOf("ID"));
int id = key.get();
CHANNEL_ARRAY.set(id, channel);
SENDING_MESSAGE_QUEUE.get(id).clear();
}
示例5: pubrec
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void pubrec(MqttMessage mqttPubAckMessage, Channel ch){
int messageId = ((MqttMessageIdVariableHeader)mqttPubAckMessage.variableHeader()).messageId();
Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
ChannelInfo channelInfo = attr.get();
MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
if (session == null) return;
QoSMessagePack messagePack = session.getMessageList().get(messageId);
if (messagePack == null) return;
messagePack.setState(QoSMessagePack.STATE.PUBREC);
session.removeMessageTask(messageId);
MessageExecutor.put(messagePack);
}
示例6: puback
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void puback(MqttPubAckMessage mqttPubAckMessage, Channel ch){
int messageId = mqttPubAckMessage.variableHeader().messageId();
Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
ChannelInfo channelInfo = attr.get();
MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
if (session == null) return;
QoSMessagePack messagePack = session.getMessageList().get(messageId);
if (messagePack == null) return;
if (messagePack.getLevel() == mqttPubAckMessage.fixedHeader().qosLevel()){
session.removeMessageTask(messageId);
}
}
示例7: bindKey
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void bindKey(Channel ctx, String key) {
Attribute<String> attr = ctx.attr(attributeKey);
if(attr!=null){
attr.set(key);
//put delivery
deliveryClient.putKey(getModelName(),getUniqueKey(ctx),key);
}
}
示例8: getKey
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public String getKey(Channel channel) {
if(channel!=null){
Attribute<String> attr = channel.attr(attributeKey);
if(attr!=null){
return attr.get();
}
}
return null;
}
示例9: process
import io.netty.channel.Channel; //导入方法依赖的package包/类
public void process(MqttMessage mqttMessage, Channel ch){
MqttMessageType mqttMessageType = mqttMessage.fixedHeader().messageType();
Attribute<RequestRecorder> attribute =
ch.attr(DovakinConstants.RECORDER_ATTRIBUTE_KEY);
/** 请求记录 */
RequestRecorder requestRecorder = attribute.get();
requestRecorder.record(mqttMessageType);
switch (mqttMessageType){
/** 连接服务器 */
case CONNECT:
System.out.println("### CONNECT");
connect((MqttConnectMessage)mqttMessage, ch, requestRecorder);
break;
/** 确认连接请求 */
case PUBLISH:
System.out.println("### PUBLISH");
publish((MqttPublishMessage)mqttMessage, ch, requestRecorder);
break;
/** 发布确认 */
case PUBACK:
System.out.println("### PUBACK");
puback((MqttPubAckMessage)mqttMessage, ch);
break;
/** 发布收到(QoS 2 , STEP 1) */
case PUBREC:
System.out.println("### PUBREC");
pubrec(mqttMessage, ch);
break;
/** 发布释放(QoS 2 , STEP 2) */
case PUBREL:
System.out.println("### PUBREL");
break;
/** 发布完成(QoS 2 , STEP 3) */
case PUBCOMP:
System.out.println("### PUBCOMP");
pubcomp(mqttMessage, ch);
break;
/** 订阅主题 */
case SUBSCRIBE:
System.out.println("### SUBSCRIBE");
subscribe((MqttSubscribeMessage)mqttMessage, ch, requestRecorder);
break;
/** 取消订阅 */
case UNSUBSCRIBE:
break;
/** 取消订阅确认 */
case UNSUBACK:
break;
/** 心跳请求 */
case PINGREQ:
pingresp(ch);
break;
/** 心跳响应 */
case PINGRESP:
break;
/** 断开连接 */
case DISCONNECT:
break;
}
}
示例10: subscribe
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void subscribe(MqttSubscribeMessage mqttSubscribeMessage, Channel ch, RequestRecorder recorder){
Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
ChannelInfo channelInfo = attr.get();
SubscriptionCache.subscribe(mqttSubscribeMessage,channelInfo.getIdentifier());
}