Search in sources :

Example 1 with ClusterRequest

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);
    }
}
Also used : TokenResult(com.alibaba.csp.sentinel.cluster.TokenResult) ClusterRequest(com.alibaba.csp.sentinel.cluster.request.ClusterRequest) ParamFlowRequestData(com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData)

Example 2 with ClusterRequest

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);
        }
    }
}
Also used : ClusterRequest(com.alibaba.csp.sentinel.cluster.request.ClusterRequest)

Example 3 with ClusterRequest

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);
    }
}
Also used : TokenResult(com.alibaba.csp.sentinel.cluster.TokenResult) ClusterRequest(com.alibaba.csp.sentinel.cluster.request.ClusterRequest) FlowRequestData(com.alibaba.csp.sentinel.cluster.request.data.FlowRequestData) ParamFlowRequestData(com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData)

Aggregations

ClusterRequest (com.alibaba.csp.sentinel.cluster.request.ClusterRequest)3 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)2 ParamFlowRequestData (com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData)2 FlowRequestData (com.alibaba.csp.sentinel.cluster.request.data.FlowRequestData)1