Search in sources :

Example 56 with MotanFrameworkException

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

the class ProtobufCodec method decodeResponse.

private Object decodeResponse(CodedInputStream input, byte dataType, long requestId, Serialization serialization) throws IOException, ClassNotFoundException {
    long processTime = input.readInt64();
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(requestId);
    response.setProcessTime(processTime);
    if (dataType == MotanConstants.FLAG_RESPONSE_VOID) {
        return response;
    }
    String className = input.readString();
    Class<?> clz = ReflectUtil.forName(className);
    Object result = serialization.deserialize(input.readByteArray(), clz);
    if (dataType == MotanConstants.FLAG_RESPONSE) {
        response.setValue(result);
    } else if (dataType == MotanConstants.FLAG_RESPONSE_EXCEPTION) {
        response.setException((Exception) result);
    } else {
        throw new MotanFrameworkException("decode error: response dataType not support " + dataType, MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
    }
    response.setRequestId(requestId);
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) IOException(java.io.IOException) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 57 with MotanFrameworkException

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

the class GrpcServer method addExporter.

@SuppressWarnings("rawtypes")
public void addExporter(Exporter<?> exporter) throws Exception {
    Provider provider = exporter.getProvider();
    ServerServiceDefinition serviceDefine = GrpcUtil.getServiceDefByAnnotation(provider.getInterface());
    boolean urlShareChannel = exporter.getUrl().getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
    synchronized (serviceDefinetions) {
        if (!(shareChannel && urlShareChannel) && !serviceDefinetions.isEmpty()) {
            URL url = serviceDefinetions.keySet().iterator().next();
            throw new MotanFrameworkException("url:" + exporter.getUrl() + " cannot share channel with url:" + url);
        }
        registry.addService(serviceDefine, provider);
        if (httpHandler != null) {
            httpHandler.addProvider(provider);
        }
        serviceDefinetions.put(exporter.getUrl(), serviceDefine);
    }
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) ServerServiceDefinition(io.grpc.ServerServiceDefinition) URL(com.weibo.api.motan.rpc.URL) Provider(com.weibo.api.motan.rpc.Provider)

Aggregations

MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)57 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)11 URL (com.weibo.api.motan.rpc.URL)10 IOException (java.io.IOException)9 Method (java.lang.reflect.Method)8 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)6 Response (com.weibo.api.motan.rpc.Response)5 TransportException (com.weibo.api.motan.transport.TransportException)4 ArrayList (java.util.ArrayList)4 Serialization (com.weibo.api.motan.codec.Serialization)3 ConfigHandler (com.weibo.api.motan.config.handler.ConfigHandler)3 Registry (com.weibo.api.motan.registry.Registry)3 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)3 HashMap (java.util.HashMap)3 CommandListener (com.weibo.api.motan.registry.support.command.CommandListener)2 ServiceListener (com.weibo.api.motan.registry.support.command.ServiceListener)2 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)2 Request (com.weibo.api.motan.rpc.Request)2 DeserializableObject (com.weibo.api.motan.serialize.DeserializableObject)2 ChannelFuture (io.netty.channel.ChannelFuture)2