Search in sources :

Example 21 with SofaResponseCallback

use of com.alipay.sofa.rpc.core.invoke.SofaResponseCallback in project sofa-rpc by sofastack.

the class ProtostuffSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(ProtostuffService.class.getName());
    request.setMethodName("echoStr");
    request.setMethod(ProtostuffService.class.getMethod("echoStr", ExampleObj.class));
    ExampleObj exampleObj = new ExampleObj();
    exampleObj.setName("xxxx");
    request.setMethodArgs(new Object[] { exampleObj });
    request.setMethodArgSigs(new String[] { ExampleObj.class.getCanonicalName() });
    request.setTargetServiceUniqueName(ProtostuffService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 22 with SofaResponseCallback

use of com.alipay.sofa.rpc.core.invoke.SofaResponseCallback in project sofa-rpc by sofastack.

the class ProtobufSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(ProtoService.class.getName());
    request.setMethodName("echoStr");
    request.setMethod(ProtoService.class.getMethod("echoStr", EchoStrReq.class));
    request.setMethodArgs(new Object[] { EchoStrReq.newBuilder().setS("xxxx").build() });
    request.setMethodArgSigs(new String[] { EchoStrReq.class.getCanonicalName() });
    request.setTargetServiceUniqueName(ProtoService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 23 with SofaResponseCallback

use of com.alipay.sofa.rpc.core.invoke.SofaResponseCallback in project sofa-rpc by sofastack.

the class MsgPackSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(DemoService.class.getName());
    request.setMethodName("say");
    request.setMethod(DemoService.class.getMethod("say", DemoRequest.class));
    final DemoRequest demoRequest = new DemoRequest();
    demoRequest.setName("name");
    request.setMethodArgs(new Object[] { demoRequest });
    request.setMethodArgSigs(new String[] { DemoRequest.class.getCanonicalName() });
    request.setTargetServiceUniqueName(DemoService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) DemoService(com.alipay.sofa.rpc.codec.msgpack.model.DemoService) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) DemoRequest(com.alipay.sofa.rpc.codec.msgpack.model.DemoRequest) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 24 with SofaResponseCallback

use of com.alipay.sofa.rpc.core.invoke.SofaResponseCallback in project sofa-rpc by sofastack.

the class SofaHessianSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(Invoker.class.getName());
    request.setMethodName("invoke");
    request.setMethod(Invoker.class.getMethod("invoke", SofaRequest.class));
    request.setMethodArgs(new Object[] { new SofaRequest() });
    request.setMethodArgSigs(new String[] { SofaRequest.class.getCanonicalName() });
    request.setTargetServiceUniqueName(Invoker.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) Invoker(com.alipay.sofa.rpc.invoke.Invoker) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) GenericObject(com.alipay.hessian.generic.model.GenericObject) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 25 with SofaResponseCallback

use of com.alipay.sofa.rpc.core.invoke.SofaResponseCallback in project sofa-rpc by sofastack.

the class InvocationStatDimensionStatTest method prepareInvokeContext.

private void prepareInvokeContext() {
    final RpcInvokeContext context = new RpcInvokeContext();
    context.setResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(final Object appResponse, String methodName, RequestBase request) {
            // 放到 future 中方便测试.
            LOGGER.info("回调成功" + appResponse);
            context.setFuture(new ResponseFuture<String>() {

                @Override
                public ResponseFuture addListeners(List<SofaResponseCallback> sofaResponseCallbacks) {
                    return null;
                }

                @Override
                public ResponseFuture addListener(SofaResponseCallback sofaResponseCallback) {
                    return null;
                }

                @Override
                public boolean cancel(boolean mayInterruptIfRunning) {
                    return false;
                }

                @Override
                public boolean isCancelled() {
                    return false;
                }

                @Override
                public boolean isDone() {
                    return false;
                }

                @Override
                public String get() throws InterruptedException, ExecutionException {
                    return (String) appResponse;
                }

                @Override
                public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                    return null;
                }
            });
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
            LOGGER.info("回调发生应用异常" + throwable);
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
            LOGGER.info("回调发生sofa异常" + sofaException);
        }
    });
    RpcInvokeContext.setContext(context);
}
Also used : RpcInvokeContext(com.alipay.sofa.rpc.context.RpcInvokeContext) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) TimeUnit(java.util.concurrent.TimeUnit) ResponseFuture(com.alipay.sofa.rpc.message.ResponseFuture) List(java.util.List) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Aggregations

SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)34 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)27 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)25 CountDownLatch (java.util.concurrent.CountDownLatch)16 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)14 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)14 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)13 Test (org.junit.Test)13 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)12 HelloService (com.alipay.sofa.rpc.test.HelloService)10 Filter (com.alipay.sofa.rpc.filter.Filter)8 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)7 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)7 ResponseFuture (com.alipay.sofa.rpc.message.ResponseFuture)7 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)6 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)6 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)5 EchoRequest (com.alipay.sofa.rpc.server.bolt.pb.EchoRequest)5 EchoResponse (com.alipay.sofa.rpc.server.bolt.pb.EchoResponse)5 HttpService (com.alipay.sofa.rpc.server.http.HttpService)5