Package com.alibaba.dubbo.remoting.exchange

Examples of com.alibaba.dubbo.remoting.exchange.Response


        if (req.getData() != null && req.getData().equals(Request.READONLY_EVENT)){
            channel.setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        }
        if (req.isTwoWay()){
            if (req.isHeartbeat()) {
              Response res = new Response(req.getId(), req.getVersion());
                res.setEvent(req.getData() == null ? null : req.getData().toString());
                channel.send(res);
                if (logger.isInfoEnabled()) {
                  int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                  logger.info("Received heartbeat from remote channel " + channel.getRemoteAddress()
                      + ", cause: The channel has no data-transmission exceeds a heartbeat period"
View Full Code Here


            }
        }
    }

    Response handleRequest(ExchangeChannel channel, Request req) throws RemotingException {
        Response res = new Response(req.getId(), req.getVersion());
        if (req.isBroken()) {
            Object data = req.getData();

            String msg;
            if (data == null) msg = null;
            else if (data instanceof Throwable) msg = StringUtils.toString((Throwable) data);
            else msg = data.toString();
            res.setErrorMessage("Fail to decode request due to: " + msg);
            res.setStatus(Response.BAD_REQUEST);

            return res;
        }
        // find handler by message class.
        Object msg = req.getData();
        try {
            // handle data.
            Object result = handler.reply(channel, msg);
            res.setStatus(Response.OK);
            res.setResult(result);
        } catch (Throwable e) {
            res.setStatus(Response.SERVICE_ERROR);
            res.setErrorMessage(StringUtils.toString(e));
        }
        return res;
    }
View Full Code Here

                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());
                    }
                }
View Full Code Here

            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;
                }
            }
        }
View Full Code Here

    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 (log.isDebugEnabled()) {
                    log.debug(
                        new StringBuilder(32)
                            .append("Receive heartbeat request and send heartbeat in thread ")
View Full Code Here

            channel.setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        }
    }

    Response handleRequest(ExchangeChannel channel, Request req) throws RemotingException {
        Response res = new Response(req.getId(), req.getVersion());
        if (req.isBroken()) {
            Object data = req.getData();

            String msg;
            if (data == null) msg = null;
            else if (data instanceof Throwable) msg = StringUtils.toString((Throwable) data);
            else msg = data.toString();
            res.setErrorMessage("Fail to decode request due to: " + msg);
            res.setStatus(Response.BAD_REQUEST);

            return res;
        }
        // find handler by message class.
        Object msg = req.getData();
        try {
            // handle data.
            Object result = handler.reply(channel, msg);
            res.setStatus(Response.OK);
            res.setResult(result);
        } catch (Throwable e) {
            res.setStatus(Response.SERVICE_ERROR);
            res.setErrorMessage(StringUtils.toString(e));
        }
        return res;
    }
View Full Code Here

                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());
                    }
                }
View Full Code Here

            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;
                }
            }
        }
View Full Code Here

          ObjectInput in = s.deserialize(channel.getUrl(), is);
          // get request id.
          long id = Bytes.bytes2long(header, 4);
          if( ( flag & FLAG_REQUEST ) == 0 ) {
              // decode response.
              Response res = new Response(id);
              if (( flag & FLAG_EVENT ) != 0){
                  res.setEvent(Response.HEARTBEAT_EVENT);
              }
              // get status.
              byte status = header[3];
              res.setStatus(status);
              if( status == Response.OK ) {
                  try {
                      Object data;
                      if (res.isHeartbeat()) {
                          data = decodeHeartbeatData(channel, in);
                      } else if (res.isEvent()) {
                          data = decodeEventData(channel, in);
                      } else {
                          data = decodeResponseData(channel, in, getRequestData(id));
                      }
                      res.setResult(data);
                  } catch (Throwable t) {
                      res.setStatus(Response.CLIENT_ERROR);
                      res.setErrorMessage(StringUtils.toString(t));
                  }
              } else {
                  res.setErrorMessage(in.readUTF());
              }
              return res;
          } else {
              // decode request.
              Request req = new Request(id);
View Full Code Here

            if (! res.isEvent() && res.getStatus() != Response.BAD_RESPONSE) {
                try {
                    // FIXME 在Codec中打印出错日志?在IoHanndler的caught中统一处理?
                    logger.warn("Fail to encode response: " + res + ", send bad_response info instead, cause: " + t.getMessage(), t);
                   
                    Response r = new Response(res.getId(), res.getVersion());
                    r.setStatus(Response.BAD_RESPONSE);
                    r.setErrorMessage("Failed to send response: " + res + ", cause: " + StringUtils.toString(t));
                    channel.send(r);
                   
                    return;
                } catch (RemotingException e) {
                    logger.warn("Failed to send bad_response info back: " + res + ", cause: " + e.getMessage(), e);
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.remoting.exchange.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.