本文整理匯總了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());
}