Java Code Examples for com.alipay.remoting.Connection#removeInvokeFuture()

The following examples show how to use com.alipay.remoting.Connection#removeInvokeFuture() . 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: ScheduledDisconnectStrategyTest.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseFreshSelectConnections_bySystemSetting() throws RemotingException,
                                                             InterruptedException {
    System.setProperty(Configs.RETRY_DETECT_PERIOD, "500");
    System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000");
    System.setProperty(Configs.CONN_MONITOR_PERIOD, "100");
    System.setProperty(Configs.CONN_THRESHOLD, "0");
    doInit(true, false);

    String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=1";
    Url url = addressParser.parse(addr);

    final Connection connection = client.getConnection(url, 1000);
    connection.addInvokeFuture(new DefaultInvokeFuture(1, null, null, RpcCommandType.REQUEST,
        null));
    Thread.sleep(2100);
    Assert.assertTrue(0 == clientDisConnectProcessor.getDisConnectTimes());
    Assert.assertEquals(1, clientConnectProcessor.getConnectTimes());
    connection.removeInvokeFuture(1);
    /* Monitor task sleep 500ms*/
    Thread.sleep(100);
    Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes());
    Thread.sleep(500);
    Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes());
}
 
Example 2
Source File: ScheduledDisconnectStrategyTest.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseFreshSelectConnections_byUserSetting() throws RemotingException,
                                                           InterruptedException {
    System.setProperty(Configs.RETRY_DETECT_PERIOD, "500");
    System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000");
    System.setProperty(Configs.CONN_MONITOR_PERIOD, "100");
    System.setProperty(Configs.CONN_THRESHOLD, "0");
    doInit(false, true);

    String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=1";
    Url url = addressParser.parse(addr);

    final Connection connection = client.getConnection(url, 1000);
    connection.addInvokeFuture(new DefaultInvokeFuture(1, null, null, RpcCommandType.REQUEST,
        null));
    Thread.sleep(2100);
    Assert.assertTrue(0 == clientDisConnectProcessor.getDisConnectTimes());
    Assert.assertEquals(1, clientConnectProcessor.getConnectTimes());
    connection.removeInvokeFuture(1);
    /* Monitor task sleep 500ms*/
    Thread.sleep(100);
    Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes());
    Thread.sleep(500);
    Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes());
}
 
Example 3
Source File: RpcResponseProcessor.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.alipay.remoting.AbstractRemotingProcessor#doProcess
 */
@Override
public void doProcess(RemotingContext ctx, RemotingCommand cmd) {

    Connection conn = ctx.getChannelContext().channel().attr(Connection.CONNECTION).get();
    InvokeFuture future = conn.removeInvokeFuture(cmd.getId());
    ClassLoader oldClassLoader = null;
    try {
        if (future != null) {
            if (future.getAppClassLoader() != null) {
                oldClassLoader = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(future.getAppClassLoader());
            }
            future.putResponse(cmd);
            future.cancelTimeout();
            try {
                future.executeInvokeCallback();
            } catch (Exception e) {
                logger.error("Exception caught when executing invoke callback, id={}",
                    cmd.getId(), e);
            }
        } else {
            logger
                .warn("Cannot find InvokeFuture, maybe already timeout, id={}, from={} ",
                    cmd.getId(),
                    RemotingUtil.parseRemoteAddress(ctx.getChannelContext().channel()));
        }
    } finally {
        if (null != oldClassLoader) {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }

}
 
Example 4
Source File: ConnectionUtil.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
public static InvokeFuture removeIdGroupCallbackMapping(Integer id, Channel channel) {
    Connection connection = getConnectionFromChannel(channel);
    if (connection != null) {
        return connection.removeInvokeFuture(id);
    }
    return null;
}