XML-RPC
  1. XML-RPC
  2. XMLRPC-56

An asynchronous callback object that manages timeouts

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      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.

        Activity

        Hide
        Jochen Wiedmann added a comment -

        Added to version 2 and version 3.

        Show
        Jochen Wiedmann added a comment - Added to version 2 and version 3.
        Hide
        suriya simsuwat added a comment -

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

        Show
        suriya simsuwat added a comment - Thank you for giving me the way how to do asyncronous call back with java class and implement it.
        Hide
        Ken Weiner added a comment -

        This attachment is an updated version of the TimingOutAsyncCallback code that throws an exception when a timeout has occured. Note that the TimeoutException needs to be written and included with the XML-RPC framework.

        Show
        Ken Weiner added a comment - This attachment is an updated version of the TimingOutAsyncCallback code that throws an exception when a timeout has occured. Note that the TimeoutException needs to be written and included with the XML-RPC framework.
        Hide
        Aaron Crow added a comment -

        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?

        Show
        Aaron Crow added a comment - 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?

          People

          • Assignee:
            Jochen Wiedmann
            Reporter:
            Ken Weiner
          • Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development