本文整理汇总了Java中java.rmi.server.RMIFailureHandler类的典型用法代码示例。如果您正苦于以下问题:Java RMIFailureHandler类的具体用法?Java RMIFailureHandler怎么用?Java RMIFailureHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RMIFailureHandler类属于java.rmi.server包,在下文中一共展示了RMIFailureHandler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.rmi.server.RMIFailureHandler; //导入依赖的package包/类
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");
}
示例2: continueAfterAcceptFailure
import java.rmi.server.RMIFailureHandler; //导入依赖的package包/类
/**
* 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;
}
}
示例3: run
import java.rmi.server.RMIFailureHandler; //导入依赖的package包/类
/**
* 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;
}
}
}
}
}
示例4: testGetSetFailureHandler
import java.rmi.server.RMIFailureHandler; //导入依赖的package包/类
public void testGetSetFailureHandler() {
RMIFailureHandler fh = new RMIFailureHandler() {
public boolean failure(Exception ex) {
return false;
}
};
RMISocketFactory.setFailureHandler(fh);
assertSame(fh, RMISocketFactory.getFailureHandler());
}