use of com.alibaba.csp.sentinel.cluster.request.ClusterRequest in project Sentinel by alibaba.
the class DefaultClusterTokenClient method requestParamToken.
@Override
public TokenResult requestParamToken(Long flowId, int acquireCount, Collection<Object> params) {
if (notValidRequest(flowId, acquireCount) || params == null || params.isEmpty()) {
return badRequest();
}
ParamFlowRequestData data = new ParamFlowRequestData().setCount(acquireCount).setFlowId(flowId).setParams(params);
ClusterRequest<ParamFlowRequestData> request = new ClusterRequest<>(ClusterConstants.MSG_TYPE_PARAM_FLOW, data);
try {
TokenResult result = sendTokenRequest(request);
logForResult(result);
return result;
} catch (Exception ex) {
ClusterClientStatLogUtil.log(ex.getMessage());
return new TokenResult(TokenResultStatus.FAIL);
}
}
use of com.alibaba.csp.sentinel.cluster.request.ClusterRequest in project Sentinel by alibaba.
the class TokenServerHandler method channelRead.
@Override
@SuppressWarnings("unchecked")
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
globalConnectionPool.refreshLastReadTime(ctx.channel());
if (msg instanceof ClusterRequest) {
ClusterRequest request = (ClusterRequest) msg;
// Client ping with its namespace, add to connection manager.
if (request.getType() == ClusterConstants.MSG_TYPE_PING) {
handlePingRequest(ctx, request);
return;
}
// Pick request processor for request type.
RequestProcessor<?, ?> processor = RequestProcessorProvider.getProcessor(request.getType());
if (processor == null) {
RecordLog.warn("[TokenServerHandler] No processor for request type: " + request.getType());
writeBadResponse(ctx, request);
} else {
ClusterResponse<?> response = processor.processRequest(request);
writeResponse(ctx, response);
}
}
}
use of com.alibaba.csp.sentinel.cluster.request.ClusterRequest in project Sentinel by alibaba.
the class DefaultClusterTokenClient method requestToken.
@Override
public TokenResult requestToken(Long flowId, int acquireCount, boolean prioritized) {
if (notValidRequest(flowId, acquireCount)) {
return badRequest();
}
FlowRequestData data = new FlowRequestData().setCount(acquireCount).setFlowId(flowId).setPriority(prioritized);
ClusterRequest<FlowRequestData> request = new ClusterRequest<>(ClusterConstants.MSG_TYPE_FLOW, data);
try {
TokenResult result = sendTokenRequest(request);
logForResult(result);
return result;
} catch (Exception ex) {
ClusterClientStatLogUtil.log(ex.getMessage());
return new TokenResult(TokenResultStatus.FAIL);
}
}
Aggregations