"Call to " + addr + " failed because " + exception).initCause(exception); } else if (exception instanceof ConnectionClosingException) { return (ConnectionClosingException) new ConnectionClosingException( "Call to " + addr + " failed on local exception: " + exception).initCause(exception); } else if (exception instanceof ServerTooBusyException) {
/** * Cleans the call not yet sent when we finish. */ public void cleanup(IOException e) { IOException ie = new ConnectionClosingException( "Connection to " + remoteId.address + " is closing."); for (Call call : callsToWrite) { call.setException(ie); } callsToWrite.clear(); } }
@Test public void testWrapException() throws Exception { final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0); assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException); assertTrue( wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException); assertTrue(wrapException(address, new ConnectionClosingException( "Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException); assertTrue( wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")) .getCause() instanceof CallTimeoutException); } }
"Call to " + addr + " failed because " + exception).initCause(exception); } else if (exception instanceof ConnectionClosingException) { return (ConnectionClosingException) new ConnectionClosingException( "Call to " + addr + " failed on local exception: " + exception).initCause(exception); } else if (exception instanceof ServerTooBusyException) {
/** * Cleans the call not yet sent when we finish. */ public void cleanup(IOException e) { IOException ie = new ConnectionClosingException( "Connection to " + remoteId.address + " is closing."); for (Call call : callsToWrite) { call.setException(ie); } callsToWrite.clear(); } }
/** * Takes an Exception and the address we were trying to connect to and return an IOException with * the input exception as the cause. The new exception provides the stack trace of the place where * the exception is thrown and some extra diagnostics information. If the exception is * ConnectException or SocketTimeoutException, return a new one of the same type; Otherwise return * an IOException. * @param addr target address * @param exception the relevant exception * @return an exception to throw */ protected IOException wrapException(InetSocketAddress addr, Exception exception) { if (exception instanceof ConnectException) { // connection refused; include the host:port in the error return (ConnectException) new ConnectException("Call to " + addr + " failed on connection exception: " + exception).initCause(exception); } else if (exception instanceof SocketTimeoutException) { return (SocketTimeoutException) new SocketTimeoutException("Call to " + addr + " failed because " + exception).initCause(exception); } else if (exception instanceof ConnectionClosingException) { return (ConnectionClosingException) new ConnectionClosingException("Call to " + addr + " failed on local exception: " + exception).initCause(exception); } else { return (IOException) new IOException("Call to " + addr + " failed on local exception: " + exception).initCause(exception); } }
@Test public void testWrapException() throws Exception { final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0); assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException); assertTrue( wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException); assertTrue(wrapException(address, new ConnectionClosingException( "Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException); assertTrue( wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")) .getCause() instanceof CallTimeoutException); } }
"Call to " + addr + " failed because " + exception).initCause(exception); } else if (exception instanceof ConnectionClosingException) { return (ConnectionClosingException) new ConnectionClosingException( "Call to " + addr + " failed on local exception: " + exception).initCause(exception); } else if (exception instanceof ServerTooBusyException) {
/** * Cleans the call not yet sent when we finish. */ public void cleanup(IOException e) { IOException ie = new ConnectionClosingException( "Connection to " + remoteId.address + " is closing."); for (Call call : callsToWrite) { call.setException(ie); } callsToWrite.clear(); } }
/** * @throws IOException if the connection is not open. */ private void checkIsOpen() throws IOException { if (shouldCloseConnection.get()) { throw new ConnectionClosingException(getName() + " is closing"); } }
/** * Cleans the call not yet sent when we finish. */ private void cleanup() { assert shouldCloseConnection.get(); IOException ie = new ConnectionClosingException("Connection to " + server + " is closing."); while (true) { CallFuture cts = callsToWrite.poll(); if (cts == null) { break; } if (cts.call != null && !cts.call.done) { cts.call.setException(ie); } } } }
/** * Cleanup the calls older than a given timeout, in milli seconds. * @param allCalls true for all calls, false for only the calls in timeout */ protected synchronized void cleanupCalls(boolean allCalls) { Iterator<Entry<Integer, Call>> itor = calls.entrySet().iterator(); while (itor.hasNext()) { Call c = itor.next().getValue(); if (c.done) { // To catch the calls without timeout that were cancelled. itor.remove(); } else if (allCalls) { long waitTime = EnvironmentEdgeManager.currentTime() - c.getStartTime(); IOException ie = new ConnectionClosingException("Connection to " + getRemoteAddress() + " is closing. Call id=" + c.id + ", waitTime=" + waitTime); c.setException(ie); itor.remove(); } else if (c.checkAndSetTimeout()) { itor.remove(); } else { // We expect the call to be ordered by timeout. It may not be the case, but stopping // at the first valid call allows to be sure that we still have something to do without // spending too much time by reading the full list. break; } } } }
call.setFailed(closeException != null ? closeException : new ConnectionClosingException( "Call id=" + call.id + " on server " + address + " aborted: connection is closing"));
throw new ConnectionClosingException("This connection is closing");
throw new ConnectionClosingException("Call id=" + call.id + " on server " + addr + " aborted: connection is closing");