当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

本文整理汇总了Java中com.alibaba.dubbo.remoting.exchange.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于com.alibaba.dubbo.remoting.exchange包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
    if (closed) {
        throw new RemotingException(this.getLocalAddress(), null, "Failed to send message " + message + ", cause: The channel " + this + " is closed!");
    }
    if (message instanceof Request
            || message instanceof Response
            || message instanceof String) {
        channel.send(message, sent);
    } else {
        Request request = new Request();
        request.setVersion("2.0.0");
        request.setTwoWay(false);
        request.setData(message);
        channel.send(request, sent);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:HeaderExchangeChannel.java

示例2: caught

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void caught(Channel channel, Throwable exception) throws RemotingException {
    if (exception instanceof ExecutionException) {
        ExecutionException e = (ExecutionException) exception;
        Object msg = e.getRequest();
        if (msg instanceof Request) {
            Request req = (Request) msg;
            if (req.isTwoWay() && ! req.isHeartbeat()) {
                Response res = new Response(req.getId(), req.getVersion());
                res.setStatus(Response.SERVER_ERROR);
                res.setErrorMessage(StringUtils.toString(e));
                channel.send(res);
                return;
            }
        }
    }
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        handler.caught(exchangeChannel, exception);
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:23,代码来源:HeaderExchangeHandler.java

示例3: received

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public static void received(Channel channel, Response response) {
    try {
        DefaultFuture future = FUTURES.remove(response.getId());
        if (future != null) {
            future.doReceived(response);
        } else {
            logger.warn("The timeout response finally returned at " 
                        + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date())) 
                        + ", response " + response 
                        + (channel == null ? "" : ", channel: " + channel.getLocalAddress() 
                            + " -> " + channel.getRemoteAddress()));
        }
    } finally {
        CHANNELS.remove(response.getId());
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:DefaultFuture.java

示例4: testMessageLengthExceedPayloadLimitWhenEncode

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
@Test
public void testMessageLengthExceedPayloadLimitWhenEncode() throws Exception {
    Request request = new Request(1L);
    request.setData("hello");
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(512);
    AbstractMockChannel channel = getCliendSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
    try {
        codec.encode(channel, encodeBuffer, request);
        Assert.fail();
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().startsWith("Data length too large: " + 6));
    }

    Response response = new Response(1L);
    response.setResult("hello");
    encodeBuffer = ChannelBuffers.dynamicBuffer(512);
    channel = getServerSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
    codec.encode(channel, encodeBuffer, response);
    Assert.assertTrue(channel.getReceivedMessage() instanceof Response);
    Response receiveMessage = (Response) channel.getReceivedMessage();
    Assert.assertEquals(Response.BAD_RESPONSE, receiveMessage.getStatus());
    Assert.assertTrue(receiveMessage.getErrorMessage().contains("Data length too large: "));
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:24,代码来源:ExchangeCodecTest.java

示例5: test_received_request_twoway_error_reqeustBroken

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
@Test
public void test_received_request_twoway_error_reqeustBroken() throws RemotingException{
    final Request request = new Request();
    request.setTwoWay(true);
    request.setData(new BizException());
    request.setBroken(true);
    
    final AtomicInteger count = new AtomicInteger(0);
    final Channel mchannel = new MockedChannel(){
        @Override
        public void send(Object message) throws RemotingException {
            Response res = (Response)message;
            Assert.assertEquals(request.getId(), res.getId());
            Assert.assertEquals(request.getVersion(), res.getVersion());
            Assert.assertEquals(Response.BAD_REQUEST, res.getStatus());
            Assert.assertNull(res.getResult());
            Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
            count.incrementAndGet();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
    hexhandler.received(mchannel, request);
    Assert.assertEquals(1, count.get());
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:25,代码来源:HeaderExchangeHandlerTest.java

示例6: encode

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void encode( Channel channel, ChannelBuffer buffer, Object message )
        throws IOException {

    if ( message instanceof Request ) {
        encodeRequest( channel, buffer, ( Request ) message );
    }
    else if ( message instanceof Response ) {
        encodeResponse( channel, buffer, ( Response ) message );
    } else {
        throw new UnsupportedOperationException(
                new StringBuilder( 32 )
                        .append( "Thrift codec only support encode " )
                        .append( Request.class.getName() )
                        .append( " and " )
                        .append( Response.class.getName() )
                        .toString() );
    }

}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:ThriftCodec.java

示例7: encode

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void encode(Channel channel, ChannelBuffer buffer, Object msg) throws IOException {
        if (msg instanceof Request) {
            encodeRequest(channel, buffer, (Request) msg);
        } else if (msg instanceof Response) {
            encodeResponse(channel, buffer, (Response) msg);
        } else {
            super.encode(channel, buffer, msg);
        }

        // TODO modified by lishen
//        System.out.println(">>>>>>>>>>>>>>>>>>>>>> the resulting byte size of encoding is " + buffer.readableBytes());
        if (logger.isTraceEnabled()) {
            logger.trace("the resulting byte size of encoding is " + buffer.readableBytes());
        }

    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:17,代码来源:ExchangeCodec.java

示例8: run

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void run() {
    while (true) {
        try {
            for (DefaultFuture future : FUTURES.values()) {
                if (future == null || future.isDone()) {
                    continue;
                }
                if (System.currentTimeMillis() - future.getStartTimestamp() > future.getTimeout()) {
                    // create exception response.
                    Response timeoutResponse = new Response(future.getId());
                    // set timeout status.
                    timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);
                    timeoutResponse.setErrorMessage(future.getTimeoutMessage(true));
                    // handle response.
                    DefaultFuture.received(future.getChannel(), timeoutResponse);
                }
            }
            Thread.sleep(30);
        } catch (Throwable e) {
            logger.error("Exception when scan the timeout invocation of remoting.", e);
        }
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:24,代码来源:DefaultFuture.java

示例9: received

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:32,代码来源:HeartbeatHandler.java

示例10: received

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
    channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        if (message instanceof Request) {
            // handle request.
            Request request = (Request) message;
            if (request.isEvent()) {
                handlerEvent(channel, request);
            } else {
                if (request.isTwoWay()) {
                    Response response = handleRequest(exchangeChannel, request);
                    channel.send(response);
                } else {
                    handler.received(exchangeChannel, request.getData());
                }
            }
        } else if (message instanceof Response) {
            handleResponse(channel, (Response) message);
        } else if (message instanceof String) {
            if (isClientSide(channel)) {
                Exception e = new Exception("Dubbo client can not supported string message: " + message + " in channel: " + channel + ", url: " + channel.getUrl());
                logger.error(e.getMessage(), e);
            } else {
                String echo = handler.telnet(channel, (String) message);
                if (echo != null && echo.length() > 0) {
                    channel.send(echo);
                }
            }
        } else {
            handler.received(exchangeChannel, message);
        }
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:37,代码来源:HeaderExchangeHandler.java

示例11: cancel

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void cancel(){
    Response errorResult = new Response(id);
    errorResult.setErrorMessage("request future has been canceled.");
    response = errorResult ;
    FUTURES.remove(id);
    CHANNELS.remove(id);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:DefaultFuture.java

示例12: returnFromResponse

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
private Object returnFromResponse() throws RemotingException {
    Response res = response;
    if (res == null) {
        throw new IllegalStateException("response cannot be null");
    }
    if (res.getStatus() == Response.OK) {
        return res.getResult();
    }
    if (res.getStatus() == Response.CLIENT_TIMEOUT || res.getStatus() == Response.SERVER_TIMEOUT) {
        throw new TimeoutException(res.getStatus() == Response.SERVER_TIMEOUT, channel, res.getErrorMessage());
    }
    throw new RemotingException(channel, res.getErrorMessage());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:DefaultFuture.java

示例13: doReceived

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
private void doReceived(Response res) {
    lock.lock();
    try {
        response = res;
        if (done != null) {
            done.signal();
        }
    } finally {
        lock.unlock();
    }
    if (callback != null) {
        invokeCallback(callback);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:15,代码来源:DefaultFuture.java

示例14: received

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
    if (message instanceof Decodeable) {
        decode(message);
    }

    if (message instanceof Request) {
        decode(((Request)message).getData());
    }

    if (message instanceof Response) {
        decode( ((Response)message).getResult());
    }

    handler.received(channel, message);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:DecodeHandler.java

示例15: encode

import com.alibaba.dubbo.remoting.exchange.Response; //导入依赖的package包/类
public void encode(Channel channel, OutputStream os, Object msg) throws IOException {
    if (msg instanceof Request) {
        encodeRequest(channel, os, (Request) msg);
    } else if (msg instanceof Response) {
        encodeResponse(channel, os, (Response) msg);
    } else {
        super.encode(channel, os, msg);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:DeprecatedExchangeCodec.java


注:本文中的com.alibaba.dubbo.remoting.exchange.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。