Search in sources :

Example 1 with FlowTokenResponseData

use of com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData in project Sentinel by alibaba.

the class DefaultClusterTokenClient method sendTokenRequest.

private TokenResult sendTokenRequest(ClusterRequest request) throws Exception {
    if (transportClient == null) {
        RecordLog.warn("[DefaultClusterTokenClient] Client not created, please check your config for cluster client");
        return clientFail();
    }
    ClusterResponse response = transportClient.sendRequest(request);
    TokenResult result = new TokenResult(response.getStatus());
    if (response.getData() != null) {
        FlowTokenResponseData responseData = (FlowTokenResponseData) response.getData();
        result.setRemaining(responseData.getRemainingCount()).setWaitInMs(responseData.getWaitInMs());
    }
    return result;
}
Also used : FlowTokenResponseData(com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData) TokenResult(com.alibaba.csp.sentinel.cluster.TokenResult) ClusterResponse(com.alibaba.csp.sentinel.cluster.response.ClusterResponse)

Example 2 with FlowTokenResponseData

use of com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData in project Sentinel by alibaba.

the class FlowResponseDataDecoderTest method testDecode.

@Test
public void testDecode() {
    ByteBuf buf = Unpooled.buffer();
    FlowResponseDataDecoder decoder = new FlowResponseDataDecoder();
    FlowTokenResponseData data = new FlowTokenResponseData();
    data.setRemainingCount(12);
    data.setWaitInMs(13);
    buf.writeInt(12);
    buf.writeInt(13);
    Assert.assertEquals(decoder.decode(buf), data);
}
Also used : FlowTokenResponseData(com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 3 with FlowTokenResponseData

use of com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData in project Sentinel by alibaba.

the class FlowResponseDataDecoder method decode.

@Override
public FlowTokenResponseData decode(ByteBuf source) {
    FlowTokenResponseData data = new FlowTokenResponseData();
    if (source.readableBytes() == 8) {
        data.setRemainingCount(source.readInt());
        data.setWaitInMs(source.readInt());
    }
    return data;
}
Also used : FlowTokenResponseData(com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData)

Aggregations

FlowTokenResponseData (com.alibaba.csp.sentinel.cluster.response.data.FlowTokenResponseData)3 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)1 ClusterResponse (com.alibaba.csp.sentinel.cluster.response.ClusterResponse)1 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1