Search in sources :

Example 1 with ParamFlowRequestData

use of com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData 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 ParamFlowRequestData

use of com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData in project Sentinel by alibaba.

the class ParamFlowRequestDataDecoder method decode.

@Override
public ParamFlowRequestData decode(ByteBuf source) {
    if (source.readableBytes() >= 16) {
        ParamFlowRequestData requestData = new ParamFlowRequestData().setFlowId(source.readLong()).setCount(source.readInt());
        int amount = source.readInt();
        if (amount > 0) {
            List<Object> params = new ArrayList<>(amount);
            for (int i = 0; i < amount; i++) {
                decodeParam(source, params);
            }
            requestData.setParams(params);
            return requestData;
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ParamFlowRequestData(com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData)

Aggregations

ParamFlowRequestData (com.alibaba.csp.sentinel.cluster.request.data.ParamFlowRequestData)2 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)1 ClusterRequest (com.alibaba.csp.sentinel.cluster.request.ClusterRequest)1 ArrayList (java.util.ArrayList)1