summaryrefslogtreecommitdiffstats
path: root/sandbox/event/samples
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2008-11-06 16:38:56 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2008-11-06 16:38:56 +0000
commitce178b299f1098c72ef6c5ead574943ae28febf1 (patch)
tree824320a1bf2241318159cf5efd11c91185470b80 /sandbox/event/samples
parentff3b544e097687169d9108a00cc64a36a680184c (diff)
Added a second pair of components with producer / consumer relationship, this time connected by binding.sca within one composite.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@711900 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/event/samples')
-rw-r--r--sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent.java5
-rw-r--r--sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent2.java54
-rw-r--r--sandbox/event/samples/event-jms/src/main/resources/weatherPublisher.composite18
-rw-r--r--sandbox/event/samples/event-jms/src/test/java/weather/WeatherTestCase.java4
4 files changed, 78 insertions, 3 deletions
diff --git a/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent.java b/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent.java
index 23c52400e8..d976454cb9 100644
--- a/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent.java
+++ b/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent.java
@@ -34,10 +34,11 @@ public class WeatherPublisherComponent implements WeatherService {
public WeatherPublisher weatherPublisher;
public void start() {
+ System.out.println("weatherPublisher code - start() called");
try {
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < 1; i++) {
generateWeatherReport();
- Thread.sleep(1000);
+ Thread.sleep(500);
}
} catch (InterruptedException e) {
}
diff --git a/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent2.java b/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent2.java
new file mode 100644
index 0000000000..cf674ff6f3
--- /dev/null
+++ b/sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent2.java
@@ -0,0 +1,54 @@
+/*
+ * 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 weather;
+
+import java.util.Date;
+import java.util.Random;
+
+import org.osoa.sca.annotations.Producer;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This class implements the Weather service and publishes weather reports.
+ */
+@Service(WeatherService.class)
+public class WeatherPublisherComponent2 implements WeatherService {
+
+ @Producer
+ public WeatherPublisher weatherPublisher2;
+
+ public void start() {
+ System.out.println("weatherPublisher2 code - start() called");
+ try {
+ for (int i = 0; i < 1; i++) {
+ generateWeatherReport();
+ Thread.sleep(500);
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public void generateWeatherReport() {
+ int temperature = new Random().nextInt(20);
+ String report = "Location: New York, Time: " + new Date() + ", Temperature " + temperature;
+
+ weatherPublisher2.publishWeatherReport(report);
+ }
+
+}
diff --git a/sandbox/event/samples/event-jms/src/main/resources/weatherPublisher.composite b/sandbox/event/samples/event-jms/src/main/resources/weatherPublisher.composite
index 9eb7e6c880..89064a7f0d 100644
--- a/sandbox/event/samples/event-jms/src/main/resources/weatherPublisher.composite
+++ b/sandbox/event/samples/event-jms/src/main/resources/weatherPublisher.composite
@@ -39,4 +39,22 @@
</component>
+ <!-- Additional components added by Mike Edwards, 31/10/2008 -->
+
+ <component name="WeatherPublisherComponent2">
+ <implementation.java class="weather.WeatherPublisherComponent2" />
+ <service name="WeatherService">
+ <interface.java interface="weather.WeatherService"/>
+ </service>
+ <producer name="weatherPublisher2" target="WeatherSubscriberComponent2/weatherSubscriber"/>
+ </component>
+
+ <component name="WeatherSubscriberComponent2">
+ <implementation.java class="weather.WeatherSubscriberComponent"/>
+
+ <consumer name="weatherSubscriber"/>
+ </component>
+
+ <!-- end of additions -->
+
</composite>
diff --git a/sandbox/event/samples/event-jms/src/test/java/weather/WeatherTestCase.java b/sandbox/event/samples/event-jms/src/test/java/weather/WeatherTestCase.java
index dfff7cc666..71162c7538 100644
--- a/sandbox/event/samples/event-jms/src/test/java/weather/WeatherTestCase.java
+++ b/sandbox/event/samples/event-jms/src/test/java/weather/WeatherTestCase.java
@@ -37,6 +37,7 @@ public class WeatherTestCase {
private BrokerService jmsBroker;
private WeatherService weatherService;
+ private WeatherService weatherService2;
private SCADomain weatherSubscriberDomain;
private SCADomain weatherPublisherDomain;
@@ -50,7 +51,7 @@ public class WeatherTestCase {
weatherPublisherDomain = SCADomain.newInstance("weatherPublisher.composite");
weatherSubscriberDomain = SCADomain.newInstance("weatherSubscriber.composite");
weatherService = weatherPublisherDomain.getService(WeatherService.class, "WeatherPublisherComponent");
-
+ weatherService2 = weatherPublisherDomain.getService(WeatherService.class, "WeatherPublisherComponent2");
} catch (Throwable e) {
e.printStackTrace();
}
@@ -59,6 +60,7 @@ public class WeatherTestCase {
@Test
public void runWeatherTest() throws Exception {
weatherService.start();
+ weatherService2.start();
}