@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { System.out.println("********************************* : debug"); resp.getOutputStream().print(broker.getDebugInfo()); resp.getOutputStream().flush(); resp.getOutputStream().close(); } catch (final Exception e) { resp.getOutputStream().print(e.getMessage()); resp.getOutputStream().flush(); resp.getOutputStream().close(); LOGGER.error("Caught exception while processing GET request", e); brokerMetrics.addMeteredValue(null, BrokerMeter.UNCAUGHT_GET_EXCEPTIONS, 1); } }
private void runInternal() { if (_isCancelled.get()) { LOGGER.error( "Request {} to server {} cancelled even before request is sent !! Not sending request", _request.getRequestId(), _server); _requestDispatchLatch.countDown(); return; } NettyClientConnection conn = null; boolean gotConnection = false; boolean error = true; try { KeyedFuture<ServerInstance, NettyClientConnection> c = _connPool.checkoutObject(_server); byte[] serializedRequest = _request.getRequestForService(_server, _segmentIds); long timeRemaining = _timeoutMS - (System.currentTimeMillis() - _startTime); int ntries = 0; // Try a maximum of pool size objects. while (true) { if (timeRemaining <= 0) { c.cancel(true); throw new TimeoutException( "Timed out trying to connect to " + _server + "(timeout=" + _timeoutMS + "ms,ntries=" + ntries + ")"); } conn = c.getOne(timeRemaining, TimeUnit.MILLISECONDS); // conn may be null if we cannot get any connection from the pool. This condition can // happen either // due to a timeout (server host is switched off, or cable disconnected), or due to // immediate connection refusal // (host is up, but server JVM is not running, or not up yet). It will also get a null // when the AsyncPoolImpl.create() // is not able to create a connection, and this one was a waiting request. // In either case, there is no point in retrying this request if (conn != null && conn.validate()) { gotConnection = true; break; } // If we get a null error map, then it is most likely a case of "Connection Refused" from // remote. // The connect errors are obtained from two different objects -- 'conn' and 'c'. // We pick the error from 'c' here, if we find it. Unfortunately there is not a way (now) // to pass the // error from 'c' to 'conn' (need to do it via AsyncPoolImpl) Map<ServerInstance, Throwable> errorMap = c.getError(); String errStr = ""; if (errorMap != null && errorMap.containsKey(_server)) { errStr = errorMap.get(_server).getMessage(); } LOGGER.warn("Destroying invalid conn {}:{}", conn, errStr); if (conn != null) { _connPool.destroyObject(_server, conn); } if (++ntries == MAX_CONN_RETRIES - 1) { throw new RuntimeException( "Could not connect to " + _server + " after " + ntries + "attempts(timeRemaining=" + timeRemaining + "ms)"); } c = _connPool.checkoutObject(_server); timeRemaining = _timeoutMS - (System.currentTimeMillis() - _startTime); } ByteBuf req = Unpooled.wrappedBuffer(serializedRequest); _responseFuture = conn.sendRequest(req, _request.getRequestId(), timeRemaining); _isSent.set(true); LOGGER.debug("Response Future is : {}", _responseFuture); error = false; } catch (TimeoutException e1) { LOGGER.error( "Timed out waiting for connection for server ({})({})(gotConnection={}). Setting error future", _server, _request.getRequestId(), gotConnection, e1); _responseFuture = new ResponseFuture(_server, e1, "Error Future for request " + _request.getRequestId()); } catch (Exception e) { LOGGER.error( "Got exception sending request ({})(gotConnection={}). Setting error future", _request.getRequestId(), gotConnection, e); _responseFuture = new ResponseFuture(_server, e, "Error Future for request " + _request.getRequestId()); } finally { _requestDispatchLatch.countDown(); BrokerRequest brokerRequest = (BrokerRequest) _request.getBrokerRequest(); if (error) { if (gotConnection) { _brokerMetrics.addMeteredValue( brokerRequest, BrokerMeter.REQUEST_DROPPED_DUE_TO_SEND_ERROR, 1); } else { _brokerMetrics.addMeteredValue( brokerRequest, BrokerMeter.REQUEST_DROPPED_DUE_TO_CONNECTION_ERROR, 1); } } } }