You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by "Aaron Crow (JIRA)" <xm...@ws.apache.org> on 2005/02/17 00:35:50 UTC

[jira] Commented: (XMLRPC-56) An asynchronous callback object that manages timeouts

     [ http://issues.apache.org/jira/browse/XMLRPC-56?page=comments#action_59288 ]
     
Aaron Crow commented on XMLRPC-56:
----------------------------------

This seems like a great idea! Just wondering if there's a good way to let the client code know explicitly that a timeout occurred?

> An asynchronous callback object that manages timeouts
> -----------------------------------------------------
>
>          Key: XMLRPC-56
>          URL: http://issues.apache.org/jira/browse/XMLRPC-56
>      Project: XML-RPC
>         Type: New Feature
>     Reporter: Ken Weiner

>
> 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira