@Test public void testCall2() throws Exception { class TestBizSocket extends AbstractBizSocket { public TestBizSocket(Configuration configuration) { super(configuration); } @Override protected PacketFactory createPacketFactory() { return null; } } TestBizSocket bizSocket = new TestBizSocket(new Configuration.Builder() .host("127.0.0.1") .port(8080).build()); BizSocketRxSupport bizSocketRxSupport = new BizSocketRxSupport.Builder() .requestConverter(new JSONRequestConverter()) .responseConverter(new JSONResponseConverter()) .bizSocket(bizSocket).build(); Method method = serviceClazz.getMethod("testCall2",String.class,String.class); BizSocketCall call = new BizSocketCall(); call.call(bizSocketRxSupport,method,"username","password"); }
public Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args) throws Exception { Request request = null; if ((request = method.getAnnotation(Request.class)) == null) { throw new IllegalArgumentException("Can not found annotation(" + Request.class.getPackage() + "." + Request.class.getSimpleName() + ")"); } final int command = getCommand(request,method,args); System.out.print("cmd: " + command); final Object tag = getTag(method,args); final ByteString requestBody = getRequestBody(bizSocketRxSupport,method,args); final String desc = request.desc(); return Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(final ObservableEmitter<Object> emitter) throws Exception { bizsocket.tcp.Request req = new bizsocket.tcp.Request.Builder().tag(tag).command(command).body(requestBody).description(desc).build(); bizSocketRxSupport.getBizSocket().request(req, new ResponseHandler() { @Override public void sendSuccessMessage(int command, ByteString requestBody, Packet responsePacket) { Object response = bizSocketRxSupport.getResponseConverter().convert(command,requestBody,getResponseType(method),responsePacket); emitter.onNext(response); } @Override public void sendFailureMessage(int command, Throwable error) { emitter.onError(error); } }); } }); }
BizSocketCall { public Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args) throws Exception { Request request = null; if ((request = method.getAnnotation(Request.class)) == null) { throw new IllegalArgumentException("Can not found annotation(" + Request.class.getPackage() + "." + Request.class.getSimpleName() + ")"); } final int command = getCommand(request,method,args); System.out.print("cmd: " + command); final Object tag = getTag(method,args); final ByteString requestBody = getRequestBody(bizSocketRxSupport,method,args); final String desc = request.desc(); return Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(final ObservableEmitter<Object> emitter) throws Exception { bizsocket.tcp.Request req = new bizsocket.tcp.Request.Builder().tag(tag).command(command).body(requestBody).description(desc).build(); bizSocketRxSupport.getBizSocket().request(req, new ResponseHandler() { @Override public void sendSuccessMessage(int command, ByteString requestBody, Packet responsePacket) { Object response = bizSocketRxSupport.getResponseConverter().convert(command,requestBody,getResponseType(method),responsePacket); emitter.onNext(response); } @Override public void sendFailureMessage(int command, Throwable error) { emitter.onError(error); } }); } }); } }
BizSocketCall { public Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args) throws Exception { Request request = null; if ((request = method.getAnnotation(Request.class)) == null) { throw new IllegalArgumentException("Can not found annotation(" + Request.class.getPackage() + "." + Request.class.getSimpleName() + ")"); } final int command = getCommand(request,method,args); System.out.print("cmd: " + command); final Object tag = getTag(method,args); final ByteString requestBody = getRequestBody(bizSocketRxSupport,method,args); final String desc = request.desc(); return Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(final ObservableEmitter<Object> emitter) throws Exception { bizsocket.tcp.Request req = new bizsocket.tcp.Request.Builder().tag(tag).command(command).body(requestBody).description(desc).build(); bizSocketRxSupport.getBizSocket().request(req, new ResponseHandler() { @Override public void sendSuccessMessage(int command, ByteString requestBody, Packet responsePacket) { Object response = bizSocketRxSupport.getResponseConverter().convert(command,requestBody,getResponseType(method),responsePacket); emitter.onNext(response); } @Override public void sendFailureMessage(int command, Throwable error) { emitter.onError(error); } }); } }); }  }
BizSocketCall { public Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args) throws Exception { Request request = null; if ((request = method.getAnnotation(Request.class)) == null) { throw new IllegalArgumentException("Can not found annotation(" + Request.class.getPackage() + "." + Request.class.getSimpleName() + ")"); } final int command = getCommand(request,method,args); System.out.print("cmd: " + command); final Object tag = getTag(method,args); final ByteString requestBody = getRequestBody(bizSocketRxSupport,method,args); final String desc = request.desc(); return Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(final ObservableEmitter<Object> emitter) throws Exception { bizsocket.tcp.Request req = new bizsocket.tcp.Request.Builder().tag(tag).command(command).body(requestBody).description(desc).build(); bizSocketRxSupport.getBizSocket().request(req, new ResponseHandler() { @Override public void sendSuccessMessage(int command, ByteString requestBody, Packet responsePacket) { Object response = bizSocketRxSupport.getResponseConverter().convert(command,requestBody,getResponseType(method),responsePacket); emitter.onNext(response); } @Override public void sendFailureMessage(int command, Throwable error) { emitter.onError(error); } }); } }); }  Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args); int getCommand(Request request,Method method, Object[] args); Object getDefaultTag(); Type getResponseType(Method method); Object getTag(Method method,Object... args); ByteString getRequestBody(BizSocketRxSupport bizSocketRxSupport, Method method, Object[] args); }
BizSocketCall { public Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args) throws Exception { Request request = null; if ((request = method.getAnnotation(Request.class)) == null) { throw new IllegalArgumentException("Can not found annotation(" + Request.class.getPackage() + "." + Request.class.getSimpleName() + ")"); } final int command = getCommand(request,method,args); System.out.print("cmd: " + command); final Object tag = getTag(method,args); final ByteString requestBody = getRequestBody(bizSocketRxSupport,method,args); final String desc = request.desc(); return Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(final ObservableEmitter<Object> emitter) throws Exception { bizsocket.tcp.Request req = new bizsocket.tcp.Request.Builder().tag(tag).command(command).body(requestBody).description(desc).build(); bizSocketRxSupport.getBizSocket().request(req, new ResponseHandler() { @Override public void sendSuccessMessage(int command, ByteString requestBody, Packet responsePacket) { Object response = bizSocketRxSupport.getResponseConverter().convert(command,requestBody,getResponseType(method),responsePacket); emitter.onNext(response); } @Override public void sendFailureMessage(int command, Throwable error) { emitter.onError(error); } }); } }); }  Observable<?> call(final BizSocketRxSupport bizSocketRxSupport, final Method method, Object... args); int getCommand(Request request,Method method, Object[] args); Object getDefaultTag(); Type getResponseType(Method method); Object getTag(Method method,Object... args); ByteString getRequestBody(BizSocketRxSupport bizSocketRxSupport, Method method, Object[] args);  }