{"action":"created","comment":{"url":"https://api.github.com/repos/codenvy/che-core/pulls/comments/41002995","id":41002995,"diff_hunk":"@@ -35,84 +38,135 @@\n import org.eclipse.che.ide.util.Config;\n import org.eclipse.che.ide.util.loging.Log;\n import org.eclipse.che.ide.websocket.MessageBus;\n+import org.eclipse.che.ide.websocket.MessageBusProvider;\n import org.eclipse.che.ide.websocket.WebSocketException;\n+import org.eclipse.che.ide.websocket.events.ConnectionOpenedHandler;\n import org.eclipse.che.ide.websocket.rest.SubscriptionHandler;\n import org.eclipse.che.ide.websocket.rest.Unmarshallable;\n+import org.eclipse.che.ide.workspace.create.CreateWorkspacePresenter;\n+import org.eclipse.che.ide.workspace.start.StartWorkspaceEvent;\n+import org.eclipse.che.ide.workspace.start.StartWorkspacePresenter;\n \n import java.util.List;\n \n+import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;\n+\n /**\n  * @author Evgen Vidolob\n+ * @author Dmitry Shnurenko\n  */\n @Singleton\n-public class WorkspaceComponent implements Component {\n+public class WorkspaceComponent implements Component, ExtServerStateHandler {\n \n     private final WorkspaceServiceClient   workspaceServiceClient;\n     private final CoreLocalizationConstant locale;\n     private final CreateWorkspacePresenter createWorkspacePresenter;\n+    private final StartWorkspacePresenter  startWorkspacePresenter;\n     private final DtoUnmarshallerFactory   dtoUnmarshallerFactory;\n-    private final MessageBus               messageBus;\n     private final EventBus                 eventBus;\n     private final LoaderPresenter          loader;\n     private final AppContext               appContext;\n+    private final NotificationManager      notificationManager;\n+    private final MessageBusProvider       messageBusProvider;\n \n-    private OperationInfo startMachineOperation;\n+    private OperationInfo                  startMachineOperation;\n+    private Callback<Component, Exception> callback;\n+    private MessageBus                     messageBus;\n \n     @Inject\n     public WorkspaceComponent(WorkspaceServiceClient workspaceServiceClient,\n                               CreateWorkspacePresenter createWorkspacePresenter,\n+                              StartWorkspacePresenter startWorkspacePresenter,\n                               CoreLocalizationConstant locale,\n                               DtoUnmarshallerFactory dtoUnmarshallerFactory,\n-                              MessageBus messageBus,\n                               EventBus eventBus,\n                               LoaderPresenter loader,\n-                              AppContext appContext) {\n+                              AppContext appContext,\n+                              NotificationManager notificationManager,\n+                              final MessageBusProvider messageBusProvider) {\n         this.workspaceServiceClient = workspaceServiceClient;\n         this.createWorkspacePresenter = createWorkspacePresenter;\n+        this.startWorkspacePresenter = startWorkspacePresenter;\n         this.locale = locale;\n         this.dtoUnmarshallerFactory = dtoUnmarshallerFactory;\n-        this.messageBus = messageBus;\n         this.eventBus = eventBus;\n         this.loader = loader;\n         this.appContext = appContext;\n+        this.notificationManager = notificationManager;\n+        this.messageBusProvider = messageBusProvider;\n+\n+        eventBus.addHandler(ExtServerStateEvent.TYPE, this);\n+    }\n+\n+    /** {@inheritDoc} */\n+    @Override\n+    public void onExtServerStarted(ExtServerStateEvent event) {\n+        notificationManager.showInfo(locale.extServerStarted());\n     }\n \n+    /** {@inheritDoc} */\n+    @Override\n+    public void onExtServerStopped(ExtServerStateEvent event) {\n+        notificationManager.showInfo(locale.extServerStopped());\n+    }\n+\n+    /** {@inheritDoc} */\n     @Override\n     public void start(final Callback<Component, Exception> callback) {\n+        this.callback = callback;\n+\n         final OperationInfo operationInfo = new OperationInfo(locale.gettingWorkspace(), Status.IN_PROGRESS, loader);\n \n-        workspaceServiceClient.getWorkspaces(0, 1).then(new Operation<List<UsersWorkspaceDto>>() {\n+        workspaceServiceClient.getWorkspaces(0, 10).then(new Operation<List<UsersWorkspaceDto>>() {\n             @Override\n-            public void apply(List<UsersWorkspaceDto> arg) throws OperationException {\n-                if (!arg.isEmpty()) {\n-                    operationInfo.setStatus(Status.FINISHED);\n-                    Config.setCurrentWorkspace(arg.get(0));\n-                    appContext.setWorkspace(arg.get(0));\n-                    callback.onSuccess(WorkspaceComponent.this);\n-                } else {\n+            public void apply(List<UsersWorkspaceDto> workspaces) throws OperationException {\n+                operationInfo.setStatus(Status.FINISHED);\n+\n+                if (workspaces.isEmpty()) {\n                     createWorkspacePresenter.show(operationInfo, callback);\n+\n+                    return;\n                 }\n+\n+                for (UsersWorkspaceDto workspace : workspaces) {\n+                    if (RUNNING.equals(workspace.getStatus())) {\n+                        setCurrentWorkspace(operationInfo, workspace);\n+\n+                        return;\n+                    }\n+                }\n+\n+                startWorkspacePresenter.show(workspaces, callback, operationInfo);\n             }\n         }).catchError(new Operation<PromiseError>() {\n             @Override\n             public void apply(PromiseError arg) throws OperationException {\n                 operationInfo.setStatus(Status.ERROR);\n+                loader.show(operationInfo);\n+\n                 callback.onFailure(new Exception(arg.getCause()));\n             }\n         });\n     }\n \n-    public void startWorkspace(String id, String envName, final Callback<Component, Exception> callback) {\n-        final OperationInfo startWsOperation =\n-                new OperationInfo(locale.startingOperation(\"workspace\"), Status.IN_PROGRESS, loader);\n+    private void setCurrentWorkspace(OperationInfo operationInfo, UsersWorkspaceDto workspace) {\n+        operationInfo.setStatus(Status.FINISHED);\n+        Config.setCurrentWorkspace(workspace);\n+        appContext.setWorkspace(workspace);\n+        callback.onSuccess(WorkspaceComponent.this);\n+    }\n+\n+    public void startWorkspace(String id, final String envName) {\n+        final OperationInfo startWsOperation = new OperationInfo(locale.startingOperation(\"workspace\"), Status.IN_PROGRESS, loader);\n+\n         loader.print(startWsOperation);\n+\n         workspaceServiceClient.startById(id, envName).then(new Operation<UsersWorkspaceDto>() {\n             @Override\n-            public void apply(UsersWorkspaceDto arg) throws OperationException {\n-                startWsOperation.setStatus(Status.FINISHED);\n-                Config.setCurrentWorkspace(arg);\n-                appContext.setWorkspace(arg);\n-                callback.onSuccess(WorkspaceComponent.this);\n+            public void apply(UsersWorkspaceDto workspace) throws OperationException {\n+                messageBus = messageBusProvider.createMessageBus(workspace.getId());","path":"ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/bootstrap/WorkspaceComponent.java","position":173,"original_position":173,"commit_id":"2bb34b933bf0b2a7a3906d349223500eedcb08a9","original_commit_id":"2bb34b933bf0b2a7a3906d349223500eedcb08a9","user":{"login":"azatsarynnyy","id":1636395,"avatar_url":"https://avatars.githubusercontent.com/u/1636395?v=3","gravatar_id":"","url":"https://api.github.com/users/azatsarynnyy","html_url":"https://github.com/azatsarynnyy","followers_url":"https://api.github.com/users/azatsarynnyy/followers","following_url":"https://api.github.com/users/azatsarynnyy/following{/other_user}","gists_url":"https://api.github.com/users/azatsarynnyy/gists{/gist_id}","starred_url":"https://api.github.com/users/azatsarynnyy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azatsarynnyy/subscriptions","organizations_url":"https://api.github.com/users/azatsarynnyy/orgs","repos_url":"https://api.github.com/users/azatsarynnyy/repos","events_url":"https://api.github.com/users/azatsarynnyy/events{/privacy}","received_events_url":"https://api.github.com/users/azatsarynnyy/received_events","type":"User","site_admin":false},"body":"MessageBusProvider#createMessageBus(String) method should receive WebSocket URL but you pass workspace ID.\r\nIsn't it mistake?","created_at":"2015-10-02T09:05:43Z","updated_at":"2015-10-02T09:05:43Z","html_url":"https://github.com/codenvy/che-core/pull/300#discussion_r41002995","pull_request_url":"https://api.github.com/repos/codenvy/che-core/pulls/300","_links":{"self":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/comments/41002995"},"html":{"href":"https://github.com/codenvy/che-core/pull/300#discussion_r41002995"},"pull_request":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/300"}}},"pull_request":{"url":"https://api.github.com/repos/codenvy/che-core/pulls/300","id":46539312,"html_url":"https://github.com/codenvy/che-core/pull/300","diff_url":"https://github.com/codenvy/che-core/pull/300.diff","patch_url":"https://github.com/codenvy/che-core/pull/300.patch","issue_url":"https://api.github.com/repos/codenvy/che-core/issues/300","number":300,"state":"open","locked":false,"title":"IDEX-3117: Added ability to manage workspaces","user":{"login":"dimasnurenko","id":7605230,"avatar_url":"https://avatars.githubusercontent.com/u/7605230?v=3","gravatar_id":"","url":"https://api.github.com/users/dimasnurenko","html_url":"https://github.com/dimasnurenko","followers_url":"https://api.github.com/users/dimasnurenko/followers","following_url":"https://api.github.com/users/dimasnurenko/following{/other_user}","gists_url":"https://api.github.com/users/dimasnurenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dimasnurenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimasnurenko/subscriptions","organizations_url":"https://api.github.com/users/dimasnurenko/orgs","repos_url":"https://api.github.com/users/dimasnurenko/repos","events_url":"https://api.github.com/users/dimasnurenko/events{/privacy}","received_events_url":"https://api.github.com/users/dimasnurenko/received_events","type":"User","site_admin":false},"body":"@vparfonov ","created_at":"2015-10-01T15:34:33Z","updated_at":"2015-10-02T09:05:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codenvy/che-core/pulls/300/commits","review_comments_url":"https://api.github.com/repos/codenvy/che-core/pulls/300/comments","review_comment_url":"https://api.github.com/repos/codenvy/che-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codenvy/che-core/issues/300/comments","statuses_url":"https://api.github.com/repos/codenvy/che-core/statuses/2bb34b933bf0b2a7a3906d349223500eedcb08a9","head":{"label":"codenvy:IDEX-3117","ref":"IDEX-3117","sha":"2bb34b933bf0b2a7a3906d349223500eedcb08a9","user":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"repo":{"id":32935706,"name":"che-core","full_name":"codenvy/che-core","owner":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codenvy/che-core","description":"Core for che","fork":false,"url":"https://api.github.com/repos/codenvy/che-core","forks_url":"https://api.github.com/repos/codenvy/che-core/forks","keys_url":"https://api.github.com/repos/codenvy/che-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codenvy/che-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codenvy/che-core/teams","hooks_url":"https://api.github.com/repos/codenvy/che-core/hooks","issue_events_url":"https://api.github.com/repos/codenvy/che-core/issues/events{/number}","events_url":"https://api.github.com/repos/codenvy/che-core/events","assignees_url":"https://api.github.com/repos/codenvy/che-core/assignees{/user}","branches_url":"https://api.github.com/repos/codenvy/che-core/branches{/branch}","tags_url":"https://api.github.com/repos/codenvy/che-core/tags","blobs_url":"https://api.github.com/repos/codenvy/che-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codenvy/che-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codenvy/che-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/codenvy/che-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codenvy/che-core/statuses/{sha}","languages_url":"https://api.github.com/repos/codenvy/che-core/languages","stargazers_url":"https://api.github.com/repos/codenvy/che-core/stargazers","contributors_url":"https://api.github.com/repos/codenvy/che-core/contributors","subscribers_url":"https://api.github.com/repos/codenvy/che-core/subscribers","subscription_url":"https://api.github.com/repos/codenvy/che-core/subscription","commits_url":"https://api.github.com/repos/codenvy/che-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/codenvy/che-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/codenvy/che-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/codenvy/che-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/codenvy/che-core/contents/{+path}","compare_url":"https://api.github.com/repos/codenvy/che-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codenvy/che-core/merges","archive_url":"https://api.github.com/repos/codenvy/che-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codenvy/che-core/downloads","issues_url":"https://api.github.com/repos/codenvy/che-core/issues{/number}","pulls_url":"https://api.github.com/repos/codenvy/che-core/pulls{/number}","milestones_url":"https://api.github.com/repos/codenvy/che-core/milestones{/number}","notifications_url":"https://api.github.com/repos/codenvy/che-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codenvy/che-core/labels{/name}","releases_url":"https://api.github.com/repos/codenvy/che-core/releases{/id}","created_at":"2015-03-26T15:30:10Z","updated_at":"2015-09-27T11:41:27Z","pushed_at":"2015-10-02T09:00:07Z","git_url":"git://github.com/codenvy/che-core.git","ssh_url":"git@github.com:codenvy/che-core.git","clone_url":"https://github.com/codenvy/che-core.git","svn_url":"https://github.com/codenvy/che-core","homepage":null,"size":12660,"stargazers_count":13,"watchers_count":13,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":7,"forks":22,"open_issues":7,"watchers":13,"default_branch":"master"}},"base":{"label":"codenvy:4.0","ref":"4.0","sha":"4324e2c1cc13d3c03fdc7e5e7b4a80c1fd7399e9","user":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"repo":{"id":32935706,"name":"che-core","full_name":"codenvy/che-core","owner":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codenvy/che-core","description":"Core for che","fork":false,"url":"https://api.github.com/repos/codenvy/che-core","forks_url":"https://api.github.com/repos/codenvy/che-core/forks","keys_url":"https://api.github.com/repos/codenvy/che-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codenvy/che-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codenvy/che-core/teams","hooks_url":"https://api.github.com/repos/codenvy/che-core/hooks","issue_events_url":"https://api.github.com/repos/codenvy/che-core/issues/events{/number}","events_url":"https://api.github.com/repos/codenvy/che-core/events","assignees_url":"https://api.github.com/repos/codenvy/che-core/assignees{/user}","branches_url":"https://api.github.com/repos/codenvy/che-core/branches{/branch}","tags_url":"https://api.github.com/repos/codenvy/che-core/tags","blobs_url":"https://api.github.com/repos/codenvy/che-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codenvy/che-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codenvy/che-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/codenvy/che-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codenvy/che-core/statuses/{sha}","languages_url":"https://api.github.com/repos/codenvy/che-core/languages","stargazers_url":"https://api.github.com/repos/codenvy/che-core/stargazers","contributors_url":"https://api.github.com/repos/codenvy/che-core/contributors","subscribers_url":"https://api.github.com/repos/codenvy/che-core/subscribers","subscription_url":"https://api.github.com/repos/codenvy/che-core/subscription","commits_url":"https://api.github.com/repos/codenvy/che-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/codenvy/che-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/codenvy/che-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/codenvy/che-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/codenvy/che-core/contents/{+path}","compare_url":"https://api.github.com/repos/codenvy/che-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codenvy/che-core/merges","archive_url":"https://api.github.com/repos/codenvy/che-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codenvy/che-core/downloads","issues_url":"https://api.github.com/repos/codenvy/che-core/issues{/number}","pulls_url":"https://api.github.com/repos/codenvy/che-core/pulls{/number}","milestones_url":"https://api.github.com/repos/codenvy/che-core/milestones{/number}","notifications_url":"https://api.github.com/repos/codenvy/che-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codenvy/che-core/labels{/name}","releases_url":"https://api.github.com/repos/codenvy/che-core/releases{/id}","created_at":"2015-03-26T15:30:10Z","updated_at":"2015-09-27T11:41:27Z","pushed_at":"2015-10-02T09:00:07Z","git_url":"git://github.com/codenvy/che-core.git","ssh_url":"git@github.com:codenvy/che-core.git","clone_url":"https://github.com/codenvy/che-core.git","svn_url":"https://github.com/codenvy/che-core","homepage":null,"size":12660,"stargazers_count":13,"watchers_count":13,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":7,"forks":22,"open_issues":7,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/300"},"html":{"href":"https://github.com/codenvy/che-core/pull/300"},"issue":{"href":"https://api.github.com/repos/codenvy/che-core/issues/300"},"comments":{"href":"https://api.github.com/repos/codenvy/che-core/issues/300/comments"},"review_comments":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/300/comments"},"review_comment":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codenvy/che-core/pulls/300/commits"},"statuses":{"href":"https://api.github.com/repos/codenvy/che-core/statuses/2bb34b933bf0b2a7a3906d349223500eedcb08a9"}}}}