com.alipay.remoting.BizContext Java Examples
The following examples show how to use
com.alipay.remoting.BizContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockServer.java From sofa-registry with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, SubscriberRegister request) throws Exception { if ("subscribeAndRefused".equals(request.getDataId())) { return response(request, true); } Result result = new Result(); result.setSuccess(true); String registId = request.getRegistId(); if (EventTypeConstants.REGISTER.equals(request.getEventType())) { subscriberMap.put(registId, request); } else if (EventTypeConstants.UNREGISTER.equals(request.getEventType())) { subscriberMap.remove(registId); } return response(request); }
Example #2
Source File: RemotingUtilTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
public void startServer() { server = new RpcServer(port); server.registerUserProcessor(new SyncUserProcessor<RequestBody>() { ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 3, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(4), new NamedThreadFactory("Request-process-pool")); @Override public Object handleRequest(BizContext bizCtx, RequestBody request) { logger.warn("Request received:" + request); return "Hello world!"; } @Override public String interest() { return RequestBody.class.toString(); } @Override public Executor getExecutor() { return executor; } }); server.start(); }
Example #3
Source File: ConcurrentServerUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); this.remoteAddr = bizCtx.getRemoteAddress(); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("Server User processor process wait time [" + waittime + "]."); latch.countDown(); logger.warn("Server User processor say, remote address is [" + this.remoteAddr + "]."); Assert.assertEquals(RequestBody.class, request.getClass()); processTimes(request); if (!delaySwitch) { return RequestBody.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_SERVER_RETURN_STR; }
Example #4
Source File: SpecificServerUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { String threadName = Thread.currentThread().getName(); Assert.assertTrue(threadName.contains("Rpc-netty-server-worker")); logger.warn("Request received:" + request); this.remoteAddr = bizCtx.getRemoteAddress(); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("Server User processor process wait time [" + waittime + "]."); latch.countDown(); logger.warn("Server User processor say, remote address is [" + this.remoteAddr + "]."); Assert.assertEquals(RequestBody.class, request.getClass()); processTimes(request); if (!delaySwitch) { return RequestBody.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_SERVER_RETURN_STR; }
Example #5
Source File: SpecificClientUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { String threadName = Thread.currentThread().getName(); Assert.assertTrue(threadName.contains("bolt-netty-client-worker")); logger.warn("Request received:" + request); Assert.assertEquals(RequestBody.class, request.getClass()); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("Client User processor process wait time [" + waittime + "]."); invokeTimes.incrementAndGet(); if (!delaySwitch) { return RequestBody.DEFAULT_CLIENT_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_CLIENT_RETURN_STR; }
Example #6
Source File: SimpleClientMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
private Object handleRequest(BizContext bizCtx, RequestBodyC2 request) { Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Client User processor process wait time {}", waittime); } processTimes(request); if (!delaySwitch) { return RequestBodyC2.DEFAULT_CLIENT_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBodyC2.DEFAULT_CLIENT_RETURN_STR; }
Example #7
Source File: SimpleClientMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
private Object handleRequest(BizContext bizCtx, RequestBodyC1 request) { Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Client User processor process wait time {}", waittime); } processTimes(request); if (!delaySwitch) { return RequestBodyC1.DEFAULT_CLIENT_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBodyC1.DEFAULT_CLIENT_RETURN_STR; }
Example #8
Source File: SimpleClientMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, MultiInterestBaseRequestBody request) throws Exception { logger.warn("Request received:" + request); if (bizCtx.isRequestTimeout()) { String errMsg = "Stop process in client biz thread, already timeout!"; logger.warn(errMsg); throw new Exception(errMsg); } if (request instanceof RequestBodyC1) { Assert.assertEquals(RequestBodyC1.class, request.getClass()); return handleRequest(bizCtx, (RequestBodyC1) request); } else if (request instanceof RequestBodyC2) { Assert.assertEquals(RequestBodyC2.class, request.getClass()); return handleRequest(bizCtx, (RequestBodyC2) request); } else { throw new Exception("RequestBody does not belong to defined interests !"); } }
Example #9
Source File: SimpleServerMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
private Object handleRequest(BizContext bizCtx, RequestBodyC2 request) { Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Client User processor process wait time {}", waittime); } processTimes(request); if (!delaySwitch) { return RequestBodyC2.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBodyC2.DEFAULT_SERVER_RETURN_STR; }
Example #10
Source File: SimpleServerMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
private Object handleRequest(BizContext bizCtx, RequestBodyC1 request) { Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Client User processor process wait time {}", waittime); } processTimes(request); if (!delaySwitch) { return RequestBodyC1.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBodyC1.DEFAULT_SERVER_RETURN_STR; }
Example #11
Source File: SpecificServerUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { String threadName = Thread.currentThread().getName(); Assert.assertTrue(threadName.contains("Rpc-specific0-executor")); logger.warn("Request received:" + request); this.remoteAddr = bizCtx.getRemoteAddress(); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("Server User processor process wait time [" + waittime + "]."); latch.countDown(); logger.warn("Server User processor say, remote address is [" + this.remoteAddr + "]."); Assert.assertEquals(RequestBody.class, request.getClass()); processTimes(request); if (!delaySwitch) { return RequestBody.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_SERVER_RETURN_STR; }
Example #12
Source File: SpecificClientUserProcessor.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { String threadName = Thread.currentThread().getName(); Assert.assertTrue(threadName.contains("Rpc-specific1-executor")); logger.warn("Request received:" + request); Assert.assertEquals(RequestBody.class, request.getClass()); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("Client User processor process wait time [" + waittime + "]."); invokeTimes.incrementAndGet(); if (!delaySwitch) { return RequestBody.DEFAULT_CLIENT_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_CLIENT_RETURN_STR; }
Example #13
Source File: UserProcessorRegisterHelperTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testInterestEmptyException() { MultiInterestUserProcessor userProcessor = new SyncMultiInterestUserProcessor() { @Override public Object handleRequest(BizContext bizCtx, Object request) throws Exception { return request; } @Override public List<String> multiInterest() { return new ArrayList<String>(); } }; try { UserProcessorRegisterHelper.registerUserProcessor(userProcessor, userProcessors); } catch (RuntimeException e) { } Assert.assertEquals(0, userProcessors.size()); }
Example #14
Source File: UserProcessorRegisterHelperTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testInterestNullException() { UserProcessor userProcessor = new SyncUserProcessor() { @Override public Object handleRequest(BizContext bizCtx, Object request) throws Exception { return request; } @Override public String interest() { return null; } }; try { UserProcessorRegisterHelper.registerUserProcessor(userProcessor, userProcessors); } catch (RuntimeException e) { } Assert.assertEquals(0, userProcessors.size()); }
Example #15
Source File: BadServerIpTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
public void startServer() { server = new RpcServer(ip, 1111); server.registerUserProcessor(new SyncUserProcessor<RequestBody>() { @Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); return "hello world!"; } @Override public String interest() { return String.class.getName(); } @Override public Executor getExecutor() { return null; } }); server.start(); }
Example #16
Source File: MockServer.java From sofa-registry with Apache License 2.0 | 6 votes |
@Override public Object handleRequest(BizContext bizCtx, ConfiguratorRegister request) throws Exception { if ("subscribeAndRefused".equals(request.getDataId())) { return response(request, true); } String registId = request.getRegistId(); LOGGER.info("dataId: {} registId: {}", request.getDataId(), registId); if (EventTypeConstants.REGISTER.equals(request.getEventType())) { configuratorMap.put(registId, request); } else if (EventTypeConstants.UNREGISTER.equals(request.getEventType())) { configuratorMap.remove(registId); } return response(request); }
Example #17
Source File: BoltChannelUtilTest.java From sofa-registry with Apache License 2.0 | 6 votes |
@Test public void testGetBoltCustomSerializer() { Assert.assertNull(BoltChannelUtil.getBoltCustomSerializer(new MockChannel())); BoltChannel boltChannel = new BoltChannel(); InvokeContext invokeContext = new InvokeContext(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, new Object()); RemotingContext remotingContext = new RemotingContext(new MockChannelHandlerContext(), invokeContext, false, new ConcurrentHashMap<>()); BizContext bizContext = new DefaultBizContext(remotingContext); boltChannel.setBizContext(bizContext); boolean isException = false; try { BoltChannelUtil.getBoltCustomSerializer(boltChannel); } catch (Throwable r) { isException = true; } Assert.assertTrue(isException); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, new Byte("3")); Assert.assertEquals(new Byte("3"), BoltChannelUtil.getBoltCustomSerializer(boltChannel)); }
Example #18
Source File: AsyncExceptionUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, RequestBody request) { logger.warn("Request received:" + request); invokeTimes.incrementAndGet(); if (!delaySwitch) { throw new RuntimeException("Hello exception!"); } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } throw new RuntimeException("Hello exception!"); }
Example #19
Source File: ExceptionUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); invokeTimes.incrementAndGet(); if (!delaySwitch) { throw new Exception("Hello exception!"); } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } throw new Exception("Hello exception!"); }
Example #20
Source File: SyncUserProcessorAdapter.java From sofa-registry with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, Object request) throws Exception { BoltChannel boltChannel = new BoltChannel(); boltChannel.setBizContext(bizCtx); boltChannel.setConnection(bizCtx.getConnection()); if (userProcessorHandler != null) { return userProcessorHandler.reply(boltChannel, request); } return null; }
Example #21
Source File: AsyncUserProcessorAdapter.java From sofa-registry with Apache License 2.0 | 5 votes |
@Override public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, Object request) { BoltChannel boltChannel = new BoltChannel(); boltChannel.setAsyncContext(asyncCtx); boltChannel.setConnection(bizCtx.getConnection()); try { if (userProcessorHandler != null) { userProcessorHandler.received(boltChannel, request); } } catch (Exception e) { LOGGER.error("Handle request error!", e); throw new RuntimeException("Handle request error!", e); } }
Example #22
Source File: SimpleServerMultiInterestUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, MultiInterestBaseRequestBody request) throws Exception { logger.warn("Request received:" + request + ", timeout:" + bizCtx.getClientTimeout() + ", arriveTimestamp:" + bizCtx.getArriveTimestamp()); if (bizCtx.isRequestTimeout()) { String errMsg = "Stop process in server biz thread, already timeout!"; logger.warn(errMsg); throw new Exception(errMsg); } this.remoteAddr = bizCtx.getRemoteAddress(); //test biz context get connection Assert.assertNotNull(bizCtx.getConnection()); Assert.assertTrue(bizCtx.getConnection().isFine()); Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Server User processor process wait time {}", waittime); } latch.countDown(); logger.warn("Server User processor say, remote address is [" + this.remoteAddr + "]."); if (request instanceof RequestBodyC1) { Assert.assertEquals(RequestBodyC1.class, request.getClass()); return handleRequest(bizCtx, (RequestBodyC1) request); } else if (request instanceof RequestBodyC2) { Assert.assertEquals(RequestBodyC2.class, request.getClass()); return handleRequest(bizCtx, (RequestBodyC2) request); } else { throw new Exception("RequestBody does not belong to defined interests !"); } }
Example #23
Source File: SimpleServerUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request + ", timeout:" + bizCtx.getClientTimeout() + ", arriveTimestamp:" + bizCtx.getArriveTimestamp()); if (bizCtx.isRequestTimeout()) { String errMsg = "Stop process in server biz thread, already timeout!"; processTimes(request); logger.warn(errMsg); throw new Exception(errMsg); } this.remoteAddr = bizCtx.getRemoteAddress(); //test biz context get connection Assert.assertNotNull(bizCtx.getConnection()); Assert.assertTrue(bizCtx.getConnection().isFine()); Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Server User processor process wait time {}", waittime); } latch.countDown(); logger.warn("Server User processor say, remote address is [" + this.remoteAddr + "]."); Assert.assertEquals(RequestBody.class, request.getClass()); processTimes(request); if (!delaySwitch) { return RequestBody.DEFAULT_SERVER_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_SERVER_RETURN_STR; }
Example #24
Source File: PreHandleUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); invokeTimes.incrementAndGet(); long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); logger.warn("PreHandleUserProcessor User processor process wait time [" + waittime + "]."); Assert.assertEquals(RequestBody.class, request.getClass()); Assert.assertEquals("127.0.0.1", bizCtx.getRemoteHost()); Assert.assertTrue(bizCtx.getRemotePort() != -1); return bizCtx.get("test"); }
Example #25
Source File: MockServer.java From sofa-registry with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, PublisherRegister request) throws Exception { if ("publishAndRefused".equals(request.getDataId())) { return response(request, true); } String registId = request.getRegistId(); List<DataBox> dataList = request.getDataList(); LOGGER.info(registId + " " + request.getEventType() + " " + dataList); if (EventTypeConstants.REGISTER.equals(request.getEventType())) { publisherMap.put(registId, request); } else if (EventTypeConstants.UNREGISTER.equals(request.getEventType())) { publisherMap.remove(registId); } return response(request); }
Example #26
Source File: NullUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); invokeTimes.incrementAndGet(); if (!delaySwitch) { return null; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return null; }
Example #27
Source File: SimpleClientUserProcessor.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object handleRequest(BizContext bizCtx, RequestBody request) throws Exception { logger.warn("Request received:" + request); if (bizCtx.isRequestTimeout()) { String errMsg = "Stop process in client biz thread, already timeout!"; logger.warn(errMsg); processTimes(request); throw new Exception(errMsg); } Assert.assertEquals(RequestBody.class, request.getClass()); Long waittime = (Long) bizCtx.getInvokeContext().get(InvokeContext.BOLT_PROCESS_WAIT_TIME); Assert.assertNotNull(waittime); if (logger.isInfoEnabled()) { logger.info("Client User processor process wait time {}", waittime); } processTimes(request); if (!delaySwitch) { return RequestBody.DEFAULT_CLIENT_RETURN_STR; } try { Thread.sleep(delayMs); } catch (InterruptedException e) { e.printStackTrace(); } return RequestBody.DEFAULT_CLIENT_RETURN_STR; }
Example #28
Source File: PreHandleUserProcessor.java From sofa-bolt with Apache License 2.0 | 4 votes |
@Override public BizContext preHandleRequest(RemotingContext remotingCtx, RequestBody request) { BizContext ctx = new MyBizContext(remotingCtx); ctx.put("test", "test"); return ctx; }
Example #29
Source File: AsyncUserProcessor.java From sofa-bolt with Apache License 2.0 | 4 votes |
/** * unsupported here! * * @see com.alipay.remoting.rpc.protocol.UserProcessor#handleRequest(com.alipay.remoting.BizContext, java.lang.Object) */ @Override public Object handleRequest(BizContext bizCtx, T request) throws Exception { throw new UnsupportedOperationException( "SYNC handle request is unsupported in AsyncUserProcessor!"); }
Example #30
Source File: SyncUserProcessor.java From sofa-bolt with Apache License 2.0 | 4 votes |
/** * unsupported here! * * @see com.alipay.remoting.rpc.protocol.UserProcessor#handleRequest(com.alipay.remoting.BizContext, com.alipay.remoting.AsyncContext, java.lang.Object) */ @Override public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, T request) { throw new UnsupportedOperationException( "ASYNC handle request is unsupported in SyncUserProcessor!"); }