ws-xmlrpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "suriya simsuwat (JIRA)" <xmlrpc-...@ws.apache.org>
Subject [jira] Commented: (XMLRPC-56) An asynchronous callback object that manages timeouts
Date Wed, 16 Mar 2005 08:42:21 GMT
     [ http://issues.apache.org/jira/browse/XMLRPC-56?page=comments#action_60953 ]
     
suriya simsuwat commented on XMLRPC-56:
---------------------------------------

Thank you for giving me the way how to do asyncronous call back with java class and implement
it.

> 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
>  Attachments: TimingOutAsyncCallback.java
>
> 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


Mime
View raw message