Search in sources :

Example 1 with XmlRpcClientRequestImpl

use of org.apache.xmlrpc.client.XmlRpcClientRequestImpl in project cloudstack by apache.

the class Connection method callTimeoutInSec.

public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
    TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
    if (debug) {
        LOGGER.debug("Call Ovm3 agent " + hostName + "(" + hostIp + "): " + method + " with " + params);
    }
    long startTime = System.currentTimeMillis();
    try {
        /* returns actual xml */
        XmlRpcClientRequestImpl req = new XmlRpcClientRequestImpl(xmlClient.getClientConfig(), method, params);
        xmlClient.executeAsync(req, callback);
        return callback.waitForResponse();
    } catch (TimingOutCallback.TimeoutException e) {
        LOGGER.info("Timeout: ", e);
        throw new XmlRpcException(e.getMessage());
    } catch (XmlRpcException e) {
        LOGGER.info("XML RPC Exception occured: ", e);
        throw e;
    } catch (RuntimeException e) {
        LOGGER.info("Runtime Exception: ", e);
        throw new XmlRpcException(e.getMessage());
    } catch (Throwable e) {
        LOGGER.error("Holy crap batman!: ", e);
        throw new XmlRpcException(e.getMessage(), e);
    } finally {
        long endTime = System.currentTimeMillis();
        /* in seconds */
        float during = (endTime - startTime) / (float) 1000;
        LOGGER.debug("Ovm3 call " + method + " finished in " + during + " secs, on " + hostIp + ":" + hostPort);
    }
}
Also used : XmlRpcClientRequestImpl(org.apache.xmlrpc.client.XmlRpcClientRequestImpl) TimingOutCallback(org.apache.xmlrpc.client.TimingOutCallback) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 TimingOutCallback (org.apache.xmlrpc.client.TimingOutCallback)1 XmlRpcClientRequestImpl (org.apache.xmlrpc.client.XmlRpcClientRequestImpl)1