本文整理匯總了Java中io.netty.channel.Channel.hasAttr方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.hasAttr方法的具體用法?Java Channel.hasAttr怎麽用?Java Channel.hasAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.hasAttr方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import io.netty.channel.Channel; //導入方法依賴的package包/類
@Override
public void call(ChannelHandlerContext context, PushResp message) {
Channel channel = context.channel();
if (!channel.hasAttr(Constants.CHANNEL_ATTR_HANDSHAKE)) {
log.warn("channel not handshake, channel:{}", channel);
context.close();
return;
}
//接收成功後,將推送的消息置換成已讀或刪除等操作
if (PushResp.Result.S.equals(message.getResult()) || PushResp.Result.D.equals(message.getResult())) {
putMsg(message);
log.info("receive pushResp, device:{}, msg_id:{}, result:{}!", message.getDevice(), message.getMsgId(), message.getResult());
} else {
log.warn("receive pushResp, device:{}, msg_id:{}, result:{}", message.getDevice(), message.getMsgId(), message.getResult());
}
}
示例2: clearUnheart
import io.netty.channel.Channel; //導入方法依賴的package包/類
private void clearUnheart() {
if (checkHeartWhenConnectionCount > connectionCount.get()) {
return;
}
long now = System.currentTimeMillis();
for (Channel channel : validatedChannels) {
long last = 0;
long first = 0;
int count = 0;
if (channel.hasAttr(LAST_HEART_TIME)) {
last = channel.attr(LAST_HEART_TIME).get();
}
if (channel.hasAttr(FIRST_HEART_TIME)) {
first = channel.attr(FIRST_HEART_TIME).get();
}
if (channel.hasAttr(HEART_COUNT)) {
count = channel.attr(HEART_COUNT).get();
}
int allow = (int) ((now - first) / (heartIntervalSec * 1000));
if (count - 2 > allow) {
log.error(channel + " heart too quick,might be Game Accelerator,please check!");
channel.pipeline().fireExceptionCaught(new HeartTooQuickException(channel, first, now, count, allow));
channel.attr(FIRST_HEART_TIME).set(now);
channel.attr(HEART_COUNT).set(0);
}
if (count < allow - 2) {
channel.pipeline().fireExceptionCaught(new HeartNotAnswerException(channel, first, last, count));
channel.close();
}
}
}
示例3: isDcChannelToSave
import io.netty.channel.Channel; //導入方法依賴的package包/類
@Override
public void isDcChannelToSave(Channel channel) {
if (!channel.hasAttr(Constants.CHANNEL_ATTR_DATACENTER)) {
//添加相應的值
String dcId = dataCenterId(channel);
channel.attr(Constants.CHANNEL_ATTR_DATACENTER).set(dcId);
if (!contains(dcId)) {
addChannel(dcId, channel);
}
}
}
示例4: isDcChannelToRemove
import io.netty.channel.Channel; //導入方法依賴的package包/類
@Override
public void isDcChannelToRemove(Channel channel) {
String dcId = null;
if (!channel.hasAttr(Constants.CHANNEL_ATTR_DATACENTER)) {
dcId = dataCenterId(channel);
} else {
dcId = channel.attr(Constants.CHANNEL_ATTR_DATACENTER).get();
}
if (contains(dcId)) {
removeChannel(dcId, channel);
}
}
示例5: checkHandShake
import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
* 檢測是否已經握手
*
* @param channel
* @return
*/
protected boolean checkHandShake(Channel channel) {
if (!channel.hasAttr(Constants.CHANNEL_ATTR_HANDSHAKE)) {
log.warn("channel not handshake, channel:{}", channel);
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例6: checkAuth
import io.netty.channel.Channel; //導入方法依賴的package包/類
protected void checkAuth(Channel ch) throws NotAuthException {
if (!ch.hasAttr(Constants.KEY_USER_ID)) {
throw new NotAuthException();
}
}