protected BaseSimpleChannelInboundHandler( ServerProperties props, HardwareStateHolder handlerState) { this.matcher = TypeParameterMatcher.find(this, BaseSimpleChannelInboundHandler.class, "I"); this.handlerState = handlerState; this.USER_QUOTA_LIMIT = props.getIntProperty("user.message.quota.limit"); this.USER_QUOTA_LIMIT_WARN_PERIOD = props.getIntProperty("user.message.quota.limit.exceeded.warning.period"); this.quotaMeter = new InstanceLoadMeter(); }
@Override @SuppressWarnings("unchecked") public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (matcher.match(msg)) { final I typedMsg = (I) msg; try { if (quotaMeter.getOneMinuteRate() > USER_QUOTA_LIMIT) { sendErrorResponseIfTicked(typedMsg.id); return; } quotaMeter.mark(); messageReceived(ctx, handlerState, typedMsg); } catch (Exception e) { handleGeneralException(ctx, e); } finally { ThreadContext.clearMap(); ReferenceCountUtil.release(msg); } } }