Search in sources :

Example 1 with MotanAbstractException

use of com.weibo.api.motan.exception.MotanAbstractException in project motan by weibocom.

the class NettyClient method request.

/**
	 * 请求remote service
	 * 
	 * <pre>
	 * 		1)  get connection from pool
	 * 		2)  async requset
	 * 		3)  return connection to pool
	 * 		4)  check if async return response, true: return ResponseFuture;  false: return result
	 * </pre>
	 * 
	 * @param request
	 * @param async
	 * @return
	 * @throws TransportException
	 */
private Response request(Request request, boolean async) throws TransportException {
    Channel channel = null;
    Response response = null;
    try {
        // return channel or throw exception(timeout or connection_fail)
        channel = borrowObject();
        if (channel == null) {
            LoggerUtil.error("NettyClient borrowObject null: url=" + url.getUri() + " " + MotanFrameworkUtil.toString(request));
            return null;
        }
        // async request
        response = channel.request(request);
        // return channel to pool
        returnObject(channel);
    } catch (Exception e) {
        LoggerUtil.error("NettyClient request Error: url=" + url.getUri() + " " + MotanFrameworkUtil.toString(request), e);
        //TODO 对特定的异常回收channel
        invalidateObject(channel);
        if (e instanceof MotanAbstractException) {
            throw (MotanAbstractException) e;
        } else {
            throw new MotanServiceException("NettyClient request Error: url=" + url.getUri() + " " + MotanFrameworkUtil.toString(request), e);
        }
    }
    // aysnc or sync result
    response = asyncResponse(response, async);
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) MotanAbstractException(com.weibo.api.motan.exception.MotanAbstractException) Channel(com.weibo.api.motan.transport.Channel) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException) MotanAbstractException(com.weibo.api.motan.exception.MotanAbstractException) TransportException(com.weibo.api.motan.transport.TransportException)

Aggregations

MotanAbstractException (com.weibo.api.motan.exception.MotanAbstractException)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)1 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)1 Response (com.weibo.api.motan.rpc.Response)1 Channel (com.weibo.api.motan.transport.Channel)1 TransportException (com.weibo.api.motan.transport.TransportException)1