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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations