From ce178b299f1098c72ef6c5ead574943ae28febf1 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Thu, 6 Nov 2008 16:38:56 +0000 Subject: 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 --- .../java/weather/WeatherPublisherComponent.java | 5 +- .../java/weather/WeatherPublisherComponent2.java | 54 ++++++++++++++++++++++ .../src/main/resources/weatherPublisher.composite | 18 ++++++++ .../src/test/java/weather/WeatherTestCase.java | 4 +- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 sandbox/event/samples/event-jms/src/main/java/weather/WeatherPublisherComponent2.java (limited to 'sandbox/event') 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 @@ + + + + + + + + + + + + + + + + + + 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(); } -- cgit v1.2.3