com.alipay.remoting.AsyncContext Java Examples

The following examples show how to use com.alipay.remoting.AsyncContext. 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: AsyncUserProcessorAdapter.java    From sofa-registry with Apache License 2.0 5 votes vote down vote up
@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 #2
Source File: AsyncExceptionUserProcessor.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: BoltSendableResponseCallback.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化数据
 */
protected void init() {
    // 从ThreadLocal取出当前长连接,request等信息设置进去,需要接到请求时提前设置到ThreadLocal里
    RpcInternalContext context = RpcInternalContext.getContext();
    asyncContext = (AsyncContext) context.getAttachment(RpcConstants.HIDDEN_KEY_ASYNC_CONTEXT);
    request = (SofaRequest) context.getAttachment(RpcConstants.HIDDEN_KEY_ASYNC_REQUEST);
}
 
Example #4
Source File: BoltRpcServer.java    From sofa-jraft with Apache License 2.0 4 votes vote down vote up
@Override
public void registerProcessor(final RpcProcessor processor) {
    this.rpcServer.registerUserProcessor(new AsyncUserProcessor<Object>() {

        @SuppressWarnings("unchecked")
        @Override
        public void handleRequest(final BizContext bizCtx, final AsyncContext asyncCtx, final Object request) {
            final RpcContext rpcCtx = new RpcContext() {

                @Override
                public void sendResponse(final Object responseObj) {
                    asyncCtx.sendResponse(responseObj);
                }

                @Override
                public Connection getConnection() {
                    com.alipay.remoting.Connection conn = bizCtx.getConnection();
                    if (conn == null) {
                        return null;
                    }
                    return new BoltConnection(conn);
                }

                @Override
                public String getRemoteAddress() {
                    return bizCtx.getRemoteAddress();
                }
            };

            processor.handleRequest(rpcCtx, request);
        }

        @Override
        public String interest() {
            return processor.interest();
        }

        @Override
        public ExecutorSelector getExecutorSelector() {
            final RpcProcessor.ExecutorSelector realSelector = processor.executorSelector();
            if (realSelector == null) {
                return null;
            }
            return realSelector::select;
        }

        @Override
        public Executor getExecutor() {
            return processor.executor();
        }
    });
}
 
Example #5
Source File: SyncUserProcessorAdapter.java    From sofa-registry with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, Object request) {
    super.handleRequest(bizCtx, asyncCtx, request);
}
 
Example #6
Source File: SyncUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
/**
 * 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!");
}
 
Example #7
Source File: SyncMultiInterestUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
/**
 * 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 SyncMultiInterestUserProcessor!");
}
 
Example #8
Source File: AsyncServerUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, RequestBody request) {
    this.asyncExecutor.execute(new InnerTask(bizCtx, asyncCtx, request));
}
 
Example #9
Source File: AsyncServerUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
public InnerTask(BizContext bizCtx, AsyncContext asyncCtx, RequestBody request) {
    this.bizCtx = bizCtx;
    this.asyncCtx = asyncCtx;
    this.request = request;
}
 
Example #10
Source File: AsyncClientUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, RequestBody request) {
    this.asyncExecutor.execute(new InnerTask(asyncCtx, request));
}
 
Example #11
Source File: AsyncClientUserProcessor.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
public InnerTask(AsyncContext asyncCtx, RequestBody request) {
    this.asyncCtx = asyncCtx;
    this.request = request;
}
 
Example #12
Source File: BoltChannel.java    From sofa-registry with Apache License 2.0 2 votes vote down vote up
/**
 * Getter method for property <tt>asyncContext</tt>.
 *
 * @return property value of asyncContext
 */
public AsyncContext getAsyncContext() {
    return asyncContext;
}
 
Example #13
Source File: BoltChannel.java    From sofa-registry with Apache License 2.0 2 votes vote down vote up
/**
 * Setter method for property <tt>asyncContext</tt>.
 *
 * @param asyncContext  value to be assigned to property asyncContext
 */
public void setAsyncContext(AsyncContext asyncContext) {
    this.asyncContext = asyncContext;
}
 
Example #14
Source File: AsyncUserProcessor.java    From sofa-bolt with Apache License 2.0 2 votes vote down vote up
/**
 * @see com.alipay.remoting.rpc.protocol.UserProcessor#handleRequest(com.alipay.remoting.BizContext, com.alipay.remoting.AsyncContext, java.lang.Object)
 */
@Override
public abstract void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, T request);
 
Example #15
Source File: UserProcessor.java    From sofa-bolt with Apache License 2.0 2 votes vote down vote up
/**
 * Handle request with {@link AsyncContext}.
 * @param bizCtx biz context
 * @param asyncCtx async context
 * @param request request
 */
void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, T request);
 
Example #16
Source File: AsyncMultiInterestUserProcessor.java    From sofa-bolt with Apache License 2.0 2 votes vote down vote up
/**
 * @see com.alipay.remoting.rpc.protocol.UserProcessor#handleRequest(com.alipay.remoting.BizContext, com.alipay.remoting.AsyncContext, java.lang.Object)
 */
@Override
public abstract void handleRequest(BizContext bizCtx, AsyncContext asyncCtx, T request);