public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 4924577\n"); RMISocketFactory.setFailureHandler(new RMIFailureHandler() { public boolean failure(Exception e) { return false; } }); tryWith(new IOException()); tryWith(new NullPointerException()); tryWith(new OutOfMemoryError()); tryWith(new NoClassDefFoundError()); tryWith(new InternalError()); tryWith(new Throwable()); System.err.println("TEST PASSED"); }
/** * Returns true if the accept loop should continue after the * specified exception has been caught, or false if the accept * loop should terminate (closing the server socket). If * there is an RMIFailureHandler, this method returns the * result of passing the specified exception to it; otherwise, * this method always returns true, after sleeping to throttle * the accept loop if necessary. **/ private boolean continueAfterAcceptFailure(Throwable t) { RMIFailureHandler fh = RMISocketFactory.getFailureHandler(); if (fh != null) { return fh.failure(t instanceof Exception ? (Exception) t : new InvocationTargetException(t)); } else { throttleLoopOnException(); return true; } }
/** * Starts waiting for incoming remote calls. When connection from remote * is accepted, separate thread to process remote call is spawned. Waits * for connections until this thread will not be interrupted. */ public void run() { while (!Thread.interrupted()) { try { Socket s = ss.accept(); startConnection(s); failedAcceptsNum = 0; } catch (Exception ex) { RMIFailureHandler rfh = RMISocketFactory.getFailureHandler(); if (rfh != null) { if (rfh.failure(ex)) { return; } } else { // We will try to immediately accept another client again, // but if we have a bad client which fails our accept tries // for a number of times, we should sleep for a while. if (failedAcceptsNum >= 5) { try { Thread.sleep(defaultFailureDelay); } catch (InterruptedException ie) { return; } failedAcceptsNum = 0; } } } } }
public void testGetSetFailureHandler() { RMIFailureHandler fh = new RMIFailureHandler() { public boolean failure(Exception ex) { return false; } }; RMISocketFactory.setFailureHandler(fh); assertSame(fh, RMISocketFactory.getFailureHandler()); }