Search in sources :

Example 1 with SentinelClusterException

use of com.alibaba.csp.sentinel.cluster.exception.SentinelClusterException in project Sentinel by alibaba.

the class NettyTransportClient method sendRequest.

@Override
public ClusterResponse sendRequest(ClusterRequest request) throws Exception {
    if (!isReady()) {
        throw new SentinelClusterException(ClusterErrorMessages.CLIENT_NOT_READY);
    }
    if (!validRequest(request)) {
        throw new SentinelClusterException(ClusterErrorMessages.BAD_REQUEST);
    }
    int xid = getCurrentId();
    try {
        request.setId(xid);
        channel.writeAndFlush(request);
        ChannelPromise promise = channel.newPromise();
        TokenClientPromiseHolder.putPromise(xid, promise);
        if (!promise.await(ClusterClientConfigManager.getRequestTimeout())) {
            throw new SentinelClusterException(ClusterErrorMessages.REQUEST_TIME_OUT);
        }
        SimpleEntry<ChannelPromise, ClusterResponse> entry = TokenClientPromiseHolder.getEntry(xid);
        if (entry == null || entry.getValue() == null) {
            // Should not go through here.
            throw new SentinelClusterException(ClusterErrorMessages.UNEXPECTED_STATUS);
        }
        return entry.getValue();
    } finally {
        TokenClientPromiseHolder.remove(xid);
    }
}
Also used : SentinelClusterException(com.alibaba.csp.sentinel.cluster.exception.SentinelClusterException) ClusterResponse(com.alibaba.csp.sentinel.cluster.response.ClusterResponse) ChannelPromise(io.netty.channel.ChannelPromise)

Aggregations

SentinelClusterException (com.alibaba.csp.sentinel.cluster.exception.SentinelClusterException)1 ClusterResponse (com.alibaba.csp.sentinel.cluster.response.ClusterResponse)1 ChannelPromise (io.netty.channel.ChannelPromise)1