Search in sources :

Example 71 with ServerError

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);
        }
    }
}
Also used : RSConnectApplicationInfo(org.rstudio.studio.client.rsconnect.model.RSConnectApplicationInfo) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 72 with ServerError

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();
        }
    });
}
Also used : DirectoryListing(org.rstudio.studio.client.workbench.views.files.model.DirectoryListing) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList)

Example 73 with ServerError

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);
            }
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) Void(org.rstudio.studio.client.server.Void)

Example 74 with ServerError

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);
}
Also used : JsArray(com.google.gwt.core.client.JsArray) Timer(com.google.gwt.user.client.Timer) ServerError(org.rstudio.studio.client.server.ServerError) RpcError(org.rstudio.core.client.jsonrpc.RpcError)

Example 75 with ServerError

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());
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6