Java Code Examples for io.netty.channel.Channel.hasAttr()

The following are Jave code examples for showing how to use hasAttr() of the io.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GoPush   File: PushRespHandler.java   Source Code and License Vote up 6 votes
@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());
    }

}
 
Example 2
Project: Limitart   File: BinaryServer.java   Source Code and License Vote up 5 votes
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();
		}
	}
}
 
Example 3
Project: GoPush   File: DataCenterChannelStore.java   Source Code and License Vote up 5 votes
@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);
        }
    }
}
 
Example 4
Project: GoPush   File: DataCenterChannelStore.java   Source Code and License Vote up 5 votes
@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);
    }
}
 
Example 5
Project: GoPush   File: PingPongProcessor.java   Source Code and License Vote up 5 votes
/**
 * 检测是否已经握手
 *
 * @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;
}
 
Example 6
Project: os   File: AbstractOperation.java   Source Code and License Vote up 4 votes
protected void checkAuth(Channel ch) throws NotAuthException {
    if (!ch.hasAttr(Constants.KEY_USER_ID)) {
        throw new NotAuthException();
    }
}