use of org.rstudio.core.client.js.JsArrayEx in project rstudio by rstudio.
the class RemoteServer method sendRemoteServerRequest.
// this code runs in the main workbench and implements the server request
// and then calls back the satellite on the provided js responseCallback
private void sendRemoteServerRequest(final JavaScriptObject sourceWindow, final String scope, final String method, final JavaScriptObject params, final boolean redactLog, final JavaScriptObject responseCallback) {
// get the WindowEx from the sourceWindow
final WindowEx srcWnd = sourceWindow.<WindowEx>cast();
// unwrap the parameter array
JsArrayEx array = params.cast();
final JSONArray jsonParams = array.toJSONArray();
// setup an rpc response handler that proxies back to the js object
class ResponseHandler extends RpcResponseHandler {
@Override
public void onResponseReceived(RpcResponse response) {
if (!srcWnd.isClosed())
performCallback(responseCallback, response);
}
public void onError(RpcError error) {
RpcResponse errorResponse = RpcResponse.create(error);
if (!srcWnd.isClosed())
performCallback(responseCallback, errorResponse);
}
private native void performCallback(JavaScriptObject responseCallback, RpcResponse response);
}
;
final ResponseHandler responseHandler = new ResponseHandler();
// setup a retry handler which will call back the second time with
// the same args (but no retryHandler, ensurin at most 1 retry)
RetryHandler retryHandler = new RetryHandler() {
public void onRetry() {
// retry one time (passing null as last param ensures there
// is no retry handler installed)
sendRequest(getSourceWindowName(sourceWindow), scope, method, jsonParams, redactLog, responseHandler, null);
}
public void onError(RpcError error) {
// propagate error which caused the retry to the caller
responseHandler.onError(error);
}
};
// submit request (retry same request up to one time)
sendRequest(getSourceWindowName(sourceWindow), scope, method, jsonParams, redactLog, responseHandler, retryHandler);
}
Aggregations