Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
None
Description
I have created an object that helps clients to XmlRpcClient impose a timeout value onto a call to send an XML-RPC message.
I want to propose that this callback object be added to the XML-RPC codebase. Feel free to change the name of the class or any of its variables or methods.
Here is example client code for the class:
TimingOutAsyncCallback callback = new TimingOutAsyncCallback(10000);
XmlRpcClient client = new XmlRpcClient(url);
client.executeAsync(methodName, aVector, callback);
callback.waitForResponse();
if (callback.getException() != null) {
throw callback.getException();
}
Object result = callback.getResult();
Here is the code for TimingOutAsyncCallback:
/**
- A callback object that can wait up to a specified amount
- of time for the XML-RPC response.
*/
protected class TimingOutAsyncCallback implements AsyncCallback {
private long timeout = 10 * 1000; // default to 10 seconds
private Object result;
private Exception exception;
public TimingOutAsyncCallback()
{ super(); }public TimingOutAsyncCallback(long timeout)
{ this.timeout = timeout; }public void setTimeout(long timeout) { this.timeout = timeout; }
public long getTimeout()
{ return this.timeout; }public Object getResult()
{ return this.result; }public Exception getException()
{ return this.exception; }public synchronized void handleError(Exception exception, URL url, String method)
{ this.exception = exception; this.notify(); }public synchronized void handleResult(Object result, URL url, String method)
{ this.result = result; this.notify(); }public synchronized void waitForResponse() throws InterruptedException
{ this.wait(timeout); }}
Please comment if you have any questions or comments.