summaryrefslogtreecommitdiff
path: root/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java')
-rw-r--r--platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java98
1 files changed, 96 insertions, 2 deletions
diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java
index 89bd2179404a..65bd9066ca3b 100644
--- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java
+++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java
@@ -15,14 +15,108 @@
*/
package com.intellij.remoteServer.util;
+import com.intellij.openapi.util.Computable;
+import com.intellij.remoteServer.agent.RemoteAgentManager;
+import com.intellij.remoteServer.agent.util.CloudAgent;
+import com.intellij.remoteServer.agent.util.CloudAgentConfigBase;
+import com.intellij.remoteServer.agent.util.CloudRemoteApplication;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration;
import com.intellij.remoteServer.runtime.ServerTaskExecutor;
import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance;
+import com.intellij.util.ThrowableRunnable;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author michael.golubev
*/
-public abstract class CloudServerRuntimeInstance<DC extends DeploymentConfiguration> extends ServerRuntimeInstance<DC> {
+public abstract class CloudServerRuntimeInstance
+ <DC extends DeploymentConfiguration,
+ A extends CloudAgent,
+ SC extends CloudAgentConfigBase>
+ extends ServerRuntimeInstance<DC> {
+
+ private final A myAgent;
+ private final SC myConfiguration;
+ private final ServerTaskExecutor myTasksExecutor;
+
+ private final AgentTaskExecutor myAgentTaskExecutor;
+
+ public CloudServerRuntimeInstance(SC configuration,
+ ServerTaskExecutor tasksExecutor,
+ List<File> libraries,
+ List<Class<?>> commonJarClasses,
+ String specificsModuleName,
+ String specificJarPath,
+ Class<A> agentInterface,
+ String agentClassName) throws Exception {
+ myConfiguration = configuration;
+ myTasksExecutor = tasksExecutor;
+
+ RemoteAgentManager agentManager = RemoteAgentManager.getInstance();
+ myAgent = agentManager.createAgent(agentManager.createReflectiveThreadProxyFactory(getClass().getClassLoader()),
+ libraries,
+ commonJarClasses,
+ specificsModuleName,
+ specificJarPath,
+ agentInterface,
+ agentClassName,
+ getClass());
+
+ myAgentTaskExecutor = new AgentTaskExecutor();
+ }
+
+ public SC getConfiguration() {
+ return myConfiguration;
+ }
+
+ public ServerTaskExecutor getTaskExecutor() {
+ return myTasksExecutor;
+ }
+
+ public A getAgent() {
+ return myAgent;
+ }
+
+ protected final AgentTaskExecutor getAgentTaskExecutor() {
+ return myAgentTaskExecutor;
+ }
+
+ @Override
+ public void computeDeployments(@NotNull final ServerRuntimeInstance.ComputeDeploymentsCallback callback) {
+ getTaskExecutor().submit(new ThrowableRunnable<Exception>() {
+
+ @Override
+ public void run() throws Exception {
+ try {
+ for (CloudApplicationRuntime application : getApplications()) {
+ callback.addDeployment(application.getApplicationName(), application);
+ }
+ callback.succeeded();
+ }
+ catch (ServerRuntimeException e) {
+ callback.errorOccurred(e.getMessage());
+ }
+ }
+ }, callback);
+ }
+
+ private List<CloudApplicationRuntime> getApplications() throws ServerRuntimeException {
+ return getAgentTaskExecutor().execute(new Computable<List<CloudApplicationRuntime>>() {
+
+ @Override
+ public List<CloudApplicationRuntime> compute() {
+ List<CloudApplicationRuntime> result = new ArrayList<CloudApplicationRuntime>();
+ for (CloudRemoteApplication application : getAgent().getApplications()) {
+ result.add(createApplicationRuntime(application.getName()));
+ }
+ return result;
+ }
+ });
+ }
- public abstract ServerTaskExecutor getTaskExecutor();
+ protected abstract CloudApplicationRuntime createApplicationRuntime(String applicationName);
}