summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample')
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Client.java7
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/ClientImpl.java36
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeService.java10
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeServiceImpl.java20
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Launcher.java38
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessService.java10
-rw-r--r--sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessServiceImpl.java19
7 files changed, 140 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Client.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Client.java
new file mode 100644
index 0000000000..78f65f07ee
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Client.java
@@ -0,0 +1,7 @@
+package sample;
+
+public interface Client {
+
+ void run();
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/ClientImpl.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/ClientImpl.java
new file mode 100644
index 0000000000..e2271e3184
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/ClientImpl.java
@@ -0,0 +1,36 @@
+package sample;
+
+import org.oasisopen.sca.annotation.Reference;
+
+public class ClientImpl implements Client {
+
+ private static final int TIMES = 5;
+
+ @Reference
+ private CompositeService compositeService;
+
+ @Reference
+ private StatelessService statelessService;
+
+ public void setCompositeService(CompositeService compositeService) {
+ this.compositeService = compositeService;
+ }
+
+ public void setStatelessService(StatelessService statelessService) {
+ this.statelessService = statelessService;
+ }
+
+ @Override
+ public void run() {
+ System.out.println("Calling CompositeService " + TIMES + " times...");
+ for (int i = 0 ; i < TIMES; i++) {
+ compositeService.hello();
+ }
+ System.out.println("Calling StatelessService " + TIMES + " times...");
+ for (int i = 0 ; i < TIMES; i++) {
+ statelessService.hello();
+ }
+ }
+
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeService.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeService.java
new file mode 100644
index 0000000000..935c1ec4c5
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeService.java
@@ -0,0 +1,10 @@
+package sample;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface CompositeService {
+
+ void hello();
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeServiceImpl.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeServiceImpl.java
new file mode 100644
index 0000000000..293692b597
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/CompositeServiceImpl.java
@@ -0,0 +1,20 @@
+package sample;
+
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+@Scope("COMPOSITE")
+@Service(CompositeService.class)
+public class CompositeServiceImpl implements CompositeService {
+
+ public CompositeServiceImpl() {
+ super();
+ System.out.println("Constructing CompositeServiceImpl instance.");
+ }
+
+ @Override
+ public void hello() {
+ System.out.println("Saying hello to CompositeServiceImpl instance.");
+ }
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Launcher.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Launcher.java
new file mode 100644
index 0000000000..9c8614d18f
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/Launcher.java
@@ -0,0 +1,38 @@
+package sample;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+public class Launcher {
+
+ public static void main(String[] args) {
+ Node node = startRuntime();
+ Client client = node.getService(Client.class, "Client");
+ client.run();
+ stopRuntime(node);
+ }
+
+ /**
+ * Starts a Tuscany node with the predefined contribution.
+ *
+ * @return the running node
+ */
+ private static Node startRuntime() {
+ String location = ContributionLocationHelper.getContributionLocation("scopes.composite");
+ Node node = NodeFactory.newInstance().createNode("scopes.composite", new Contribution("c1", location));
+ node.start();
+ return node;
+ }
+
+ /**
+ * Stops a Tuscany node.
+ *
+ * @param node the node to stop
+ */
+ private static void stopRuntime(Node node) {
+ node.stop();
+ }
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessService.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessService.java
new file mode 100644
index 0000000000..133cac03c2
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessService.java
@@ -0,0 +1,10 @@
+package sample;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface StatelessService {
+
+ void hello();
+
+}
diff --git a/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessServiceImpl.java b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessServiceImpl.java
new file mode 100644
index 0000000000..9f113903cc
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/getting-started/sca-scopes/src/main/java/sample/StatelessServiceImpl.java
@@ -0,0 +1,19 @@
+package sample;
+
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+@Scope("STATELESS")
+@Service(StatelessService.class)
+public class StatelessServiceImpl implements StatelessService {
+
+ public StatelessServiceImpl() {
+ super();
+ System.out.println("Constructing StatelessServiceImpl instance.");
+ }
+
+ @Override
+ public void hello() {
+ System.out.println("Saying hello to StatelessServiceImpl.");
+ }
+}