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