use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class RSConnectDeploy method setPreviousInfo.
private void setPreviousInfo() {
// content as currently deployed
if (fromPrevious_ != null) {
appProgressName_.setText(fromPrevious_.getName());
appExistingName_.setText(fromPrevious_.getDisplayName());
appProgressPanel_.setVisible(true);
appInfoPanel_.setVisible(true);
final ServerRequestCallback<JsArray<RSConnectApplicationInfo>> onAppsReceived = new ServerRequestCallback<JsArray<RSConnectApplicationInfo>>() {
@Override
public void onResponseReceived(JsArray<RSConnectApplicationInfo> infos) {
// hide server progress
appProgressPanel_.setVisible(false);
// find an app with the same account, server, and name;
// when found, populate the UI with app details
boolean found = false;
if (infos != null) {
for (int i = 0; i < infos.length(); i++) {
RSConnectApplicationInfo info = infos.get(i);
if (info.getName() == fromPrevious_.getName()) {
showAppInfo(info);
found = true;
break;
}
}
}
if (!found) {
forgetPreviousDeployment();
}
}
@Override
public void onError(ServerError error) {
// it's okay if we fail here, since the application info
// display is purely informative
appProgressPanel_.setVisible(false);
showAppInfo(null);
}
};
if (!StringUtil.isNullOrEmpty(fromPrevious_.getAppId())) {
// we know this app's ID, so get its details directly
server_.getRSConnectApp(fromPrevious_.getAppId(), fromPrevious_.getAccountName(), fromPrevious_.getServer(), new ServerRequestCallback<RSConnectApplicationInfo>() {
@Override
public void onResponseReceived(RSConnectApplicationInfo info) {
// create a single-entry array with the app ID
JsArray<RSConnectApplicationInfo> infos = JsArray.createArray().cast();
if (info != null)
infos.push(info);
onAppsReceived.onResponseReceived(infos);
}
@Override
public void onError(ServerError error) {
onAppsReceived.onError(error);
}
});
} else {
// we don't know the app ID, get the apps by name
server_.getRSConnectAppList(fromPrevious_.getAccountName(), fromPrevious_.getServer(), onAppsReceived);
}
}
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class RemoteFileSystemContext method cd.
public void cd(String relativeOrAbsolutePath) {
final String newPath = combine(workingDir_, relativeOrAbsolutePath);
final FileSystemItem newPathEntry = FileSystemItem.createDir(newPath);
final ArrayList<FileSystemItem> fsi = new ArrayList<FileSystemItem>();
server_.listFiles(newPathEntry, // since this is used for the file dialog don't
false, // cause the call to reset the server monitoring state
new ServerRequestCallback<DirectoryListing>() {
@Override
public void onError(ServerError error) {
if (callbacks_ != null)
callbacks_.onError(error.getUserMessage());
}
@Override
public void onResponseReceived(final DirectoryListing response) {
final JsArray<FileSystemItem> files = response.getFiles();
for (int i = 0; i < files.length(); i++) fsi.add(files.get(i));
workingDir_ = newPath;
contents_ = fsi.toArray(new FileSystemItem[0]);
if (callbacks_ != null)
callbacks_.onNavigated();
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class RemoteFileSystemContext method mkdir.
public void mkdir(final String directoryName, final ProgressIndicator progress) {
String error;
if (null != (error = validatePathElement(directoryName, true))) {
progress.onError(error);
return;
}
final String baseDir = workingDir_;
String newPath = combine(baseDir, directoryName);
final FileSystemItem newFolder = FileSystemItem.createDir(newPath);
server_.createFolder(newFolder, new ServerRequestCallback<org.rstudio.studio.client.server.Void>() {
@Override
public void onError(ServerError error) {
progress.onError(error.getUserMessage());
}
@Override
public void onResponseReceived(Void response) {
if (baseDir.equals(workingDir_)) {
progress.onCompleted();
if (callbacks_ != null)
callbacks_.onDirectoryCreated(newFolder);
}
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class RemoteServerEventListener method doListen.
private void doListen() {
// abort if we are no longer running
if (!isListening_)
return;
// setup request callback (save reference for cancellation)
activeRequestCallback_ = new ServerRequestCallback<JsArray<ClientEvent>>() {
@Override
public void onResponseReceived(JsArray<ClientEvent> events) {
// keep watchdog appraised of successful receipt of events
watchdog_.notifyResponseReceived();
try {
// only processs events if we are still listening
if (isListening_ && (events != null)) {
for (int i = 0; i < events.length(); i++) {
// is dispatched
if (!isListening_)
return;
// disppatch event
ClientEvent event = events.get(i);
dispatchEvent(event);
lastEventId_ = event.getId();
}
}
}// listen() again after processing
catch (Throwable e) {
GWT.log("ERROR: Processing client events", e);
}
// listen for more events
listen();
}
@Override
public void onError(ServerError error) {
// stop listening for events
stop();
// if this was server unavailable then signal event and return
if (error.getCode() == ServerError.UNAVAILABLE) {
ServerUnavailableEvent event = new ServerUnavailableEvent();
server_.getEventBus().fireEvent(event);
return;
}
// result in our server getting hammered with requests)
if (listenErrorCount_++ <= 5) {
Timer startTimer = new Timer() {
@Override
public void run() {
// by some other means (e.g. ensureListening, etc)
if (!isListening_)
start();
}
};
startTimer.schedule(500);
} else // otherwise reset the listen error count and remain stopped
{
listenErrorCount_ = 0;
}
}
};
// retry handler (restart listener)
RetryHandler retryHandler = new RetryHandler() {
public void onRetry() {
// need to do a full restart to ensure that the existing
// activeRequest_ and activeRequestCallback_ are cleaned up
// and all state is reset correctly
restart();
}
public void onError(RpcError error) {
// error while attempting to recover, to be on the safe side
// we simply stop listening for events. if rather than stopping
// we restarted we would open ourselves up to a situation
// where we keep hitting the same error over and over again.
stop();
}
};
// send request
activeRequest_ = server_.getEvents(lastEventId_, activeRequestCallback_, retryHandler);
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class SnippetHelper method applySnippet.
public void applySnippet(final String token, final String snippetName) {
// Set the selection based on what we want to replace. For auto-paired
// insertions, e.g. `[|]`, we want to replace both characters; typically
// we only want to replace the token.
String snippetContent = transformMacros(getSnippetContents(snippetName), token, snippetName);
// snippet down to the server and then apply the response.
if (containsExecutableRCode(snippetContent)) {
server_.transformSnippet(snippetContent, new ServerRequestCallback<String>() {
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
@Override
public void onResponseReceived(String transformed) {
selectToken(token);
applySnippetImpl(transformed, manager_, editor_.getWidget().getEditor());
}
});
} else {
selectToken(token);
applySnippetImpl(snippetContent, manager_, editor_.getWidget().getEditor());
}
}
Aggregations