Java Code Examples for com.alipay.remoting.BizContext#getRemoteAddress()

The following examples show how to use com.alipay.remoting.BizContext#getRemoteAddress() . 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: SpecificServerUserProcessor.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: SpecificServerUserProcessor.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: ConcurrentServerUserProcessor.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
@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: SimpleServerMultiInterestUserProcessor.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: SimpleServerUserProcessor.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@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;
}