summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java32
-rw-r--r--sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java3
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java7
-rw-r--r--sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java7
-rw-r--r--sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java19
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java3
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java17
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java83
-rw-r--r--sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java7
-rw-r--r--sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java25
10 files changed, 201 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
new file mode 100644
index 0000000000..c3b6527181
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ActiveNodes {
+
+ List<Object> activeNodes = new ArrayList<Object>();
+
+ public List<Object> getActiveNodes() {
+ return activeNodes;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
index 08c7a5131f..08fbb62f0d 100644
--- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
+++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.runtime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.Endpoint;
@@ -96,4 +97,6 @@ public interface DomainRegistry {
List<String> getMembers();
String getLocalMember();
String getRunningMember(String contributionURI, String compositeURI);
+
+ String remoteCommand(String memberName, Callable<String> command);
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
index c3ffd9091f..1af82d2272 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/DomainRegistryImpl.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -243,4 +244,10 @@ public class DomainRegistryImpl extends BaseDomainRegistry implements DomainRegi
public String getRunningMember(String contributionURI, String compositeURI) {
return LOCAL_MEMBER_NAME;
}
+
+ @Override
+ public String remoteCommand(String memberName, Callable<String> command) {
+ // TODO or should it just ensure the member name is LocalOnly and the run the command locally?
+ throw new IllegalStateException("not supportted for " + LOCAL_MEMBER_NAME);
+ }
}
diff --git a/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java b/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
index 40561ade0c..d724eaf4b0 100644
--- a/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
+++ b/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
@@ -30,6 +30,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Callable;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
@@ -894,5 +895,11 @@ public class DeployerImpl implements Deployer {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public String remoteCommand(String memberName, Callable<String> command) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
}
diff --git a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
index c0687cd13f..ad13ba4bd3 100644
--- a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
+++ b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
@@ -30,7 +30,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -72,6 +74,7 @@ import com.hazelcast.config.Config;
import com.hazelcast.config.NearCacheConfig;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.config.XmlConfigBuilder;
+import com.hazelcast.core.DistributedTask;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.Hazelcast;
@@ -679,4 +682,20 @@ public class HazelcastDomainRegistry extends BaseDomainRegistry implements Domai
}
return null;
}
+
+ @Override
+ public String remoteCommand(String memberName, Callable<String> command) {
+ for (Member member : hazelcastInstance.getCluster().getMembers()) {
+ if (member.getInetSocketAddress().toString().equals(memberName)) {
+ FutureTask<String> task = new DistributedTask<String>(command, member);
+ hazelcastInstance.getExecutorService().execute(task);
+ try {
+ return task.get();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ }
+ throw new IllegalArgumentException("member not found: " + memberName);
+ }
}
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
index 89eeb09c2c..8889e369bf 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/Node.java
@@ -243,6 +243,9 @@ public interface Node {
List<String> getMembers();
String getLocalMember();
String getRunningMember(String contributionURI, String compositeURI);
+
+ String remoteStart(String member, String contributionURI, String compositeURI);
+ String remoteStop(String member, String contributionURI, String compositeURI);
// TODO: Add methods to get:
// start and stop composites on remote members
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
index 2c15a4464b..7cfe60a543 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
@@ -46,10 +46,12 @@ import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.deployment.Deployer;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.ValidationException;
import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ActiveNodes;
import org.apache.tuscany.sca.runtime.CompositeActivator;
import org.apache.tuscany.sca.runtime.ContributionListener;
import org.apache.tuscany.sca.runtime.DomainRegistry;
@@ -82,7 +84,9 @@ public class NodeImpl implements Node {
this.domainRegistry = domainRegistry;
this.extensionPointRegistry = extensionPointRegistry;
this.tuscanyRuntime = tuscanyRuntime;
-
+
+ extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class).getActiveNodes().add(this);
+
domainRegistry.addContributionListener(new ContributionListener() {
public void contributionUpdated(String uri) {
loadedContributions.remove(uri);
@@ -384,6 +388,7 @@ public class NodeImpl implements Node {
}
startedComposites.clear();
stoppedComposites.clear();
+ extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class).getActiveNodes().remove(this);
if (tuscanyRuntime != null) {
tuscanyRuntime.stop();
}
@@ -404,4 +409,14 @@ public class NodeImpl implements Node {
return domainRegistry.getRunningMember(contributionURI, compositeURI);
}
+ @Override
+ public String remoteStart(String memberName, String contributionURI, String compositeURI) {
+ return domainRegistry.remoteCommand(memberName, new RemoteCommand(domainName, "start", contributionURI, compositeURI));
+ }
+
+ @Override
+ public String remoteStop(String memberName, String contributionURI, String compositeURI) {
+ return domainRegistry.remoteCommand(memberName, new RemoteCommand(domainName, "stop", contributionURI, compositeURI));
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
new file mode 100644
index 0000000000..5e150dba02
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/RemoteCommand.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.impl;
+
+import java.io.Serializable;
+import java.util.concurrent.Callable;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistryLocator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.runtime.ActiveNodes;
+
+public class RemoteCommand implements Callable<String>, Serializable {
+ private static final long serialVersionUID = 1L;
+
+ // all fields MUST be Serializable
+ private String domainName;
+ private String command;
+ private String contributionURI;
+ private String compositeURI;
+
+ public RemoteCommand(String domainName, String command, String contributionURI, String compositeURI) {
+ this.domainName = domainName;
+ this.command = command;
+ this.contributionURI = contributionURI;
+ this.compositeURI = compositeURI;
+ }
+
+ public String call() throws Exception {
+ String response;
+ try {
+ Node node = getNode();
+
+ if ("start".equals(command)) {
+ node.startComposite(contributionURI, compositeURI);
+ response = "Started.";
+ } else if ("stop".equals(command)) {
+ node.stopComposite(contributionURI, compositeURI);
+ response = "Stopped.";
+ } else {
+ response = "Unknown command: " + command;
+ }
+ } catch (Exception e) {
+ response = "REMOTE EXCEPTION: " + e.getClass() + ":" + e.getMessage();
+ }
+ return response;
+ }
+
+ private Node getNode() {
+ // TODO Several places in Tuscany need to do this type of thing, for example, processing
+ // async responses, so we need to design a "proper" way to do it
+
+ for (ExtensionPointRegistry xpr : ExtensionPointRegistryLocator.getExtensionPointRegistries()) {
+ ActiveNodes activeNodes = xpr.getExtensionPoint(UtilityExtensionPoint.class).getUtility(ActiveNodes.class);
+ for (Object o : activeNodes.getActiveNodes()) {
+ Node node = (Node)o;
+ if (node.getDomainName().equals(domainName)) {
+ return node;
+ }
+ }
+ }
+ throw new IllegalStateException("No remote Node found for domain: " + domainName);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
index 246072afc3..ddf428b7bf 100644
--- a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
+++ b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedDomainRegistry.java
@@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -493,4 +494,10 @@ public class ReplicatedDomainRegistry extends BaseDomainRegistry implements Doma
return null;
}
+ @Override
+ public String remoteCommand(String memberName, Callable<String> command) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
index 2403cab294..a407f3e105 100644
--- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
+++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
@@ -73,7 +73,7 @@ public class Shell {
private Map<String, Node> nodes = new HashMap<String, Node>();
public static final String[] COMMANDS = new String[] {"bye", "domain", "domains", "domainComposite", "help", "install", "installed", "invoke",
- "load", "members", "remove", "run", "save", "services", "start", "started", "stop"};
+ "load", "members", "remoteStart", "remoteStop", "remove", "run", "save", "services", "start", "started", "stop"};
public static void main(final String[] args) throws Exception {
boolean useJline = true;
@@ -444,6 +444,17 @@ public class Shell {
return true;
}
+ boolean remoteStart(final List<String> toks) {
+ String response = getNode().remoteStart(toks.get(1), toks.get(2), toks.get(3));
+ out.println(response);
+ return true;
+ }
+ boolean remoteStop(final List<String> toks) {
+ String response = getNode().remoteStop(toks.get(1), toks.get(2), toks.get(3));
+ out.println(response);
+ return true;
+ }
+
boolean started(final List<String> toks) {
if (standaloneNodes.size() > 0) {
out.println("Standalone Nodes:");
@@ -662,6 +673,18 @@ public class Shell {
return bye();
}
};
+ if (op.equalsIgnoreCase("remoteStart"))
+ return new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return remoteStart(toks);
+ }
+ };
+ if (op.equalsIgnoreCase("remoteStop"))
+ return new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return remoteStop(toks);
+ }
+ };
if (op.equalsIgnoreCase("start"))
return new Callable<Boolean>() {
public Boolean call() throws Exception {