use of org.apache.xmlrpc.client.TimingOutCallback 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);
}
}
use of org.apache.xmlrpc.client.TimingOutCallback in project cloudstack by apache.
the class Connection method callTimeoutInSec.
public Object callTimeoutInSec(String method, Object[] params, int timeout, boolean debug) throws XmlRpcException {
TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
Object[] mParams = new Object[params.length + 1];
mParams[0] = method;
for (int i = 0; i < params.length; i++) {
mParams[i + 1] = params[i];
}
if (debug) {
/*
* some parameters including user password should not be printed in log
*/
s_logger.debug("Call Ovm agent: " + Coder.toJson(mParams));
}
long startTime = System.currentTimeMillis();
_client.executeAsync("OvmDispatch", mParams, callback);
try {
return callback.waitForResponse();
} catch (TimingOutCallback.TimeoutException to) {
throw to;
} catch (Throwable e) {
throw new XmlRpcException(-2, e.getMessage());
} finally {
long endTime = System.currentTimeMillis();
// in secs
long during = (endTime - startTime) / 1000;
s_logger.debug("Ovm call " + method + " finished in " + String.valueOf(during) + " secs");
}
}
Aggregations