diff options
author | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-11 20:09:34 +0000 |
---|---|---|
committer | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-11 20:09:34 +0000 |
commit | 5f6f915b67998984955846e5c752e0ebfeeb1054 (patch) | |
tree | 07ddd70605298353c0307954a2e95ffb4f313f0b /sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp | |
parent | 9ea0c9346ce3d4ecdb617a81b28dfd6e2ed6174e (diff) |
Update comet binding sample to demonstrate server push.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1069940 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp')
8 files changed, 110 insertions, 48 deletions
diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/pom.xml b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/pom.xml index cb538d02a0..af69d0b1bb 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/pom.xml +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/pom.xml @@ -35,11 +35,6 @@ <dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-base-runtime</artifactId>
- <version>2.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-comet-runtime</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
@@ -49,6 +44,13 @@ <version>6.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-base-runtime-pom</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java index 00cbe73e82..1eae6802cd 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java @@ -19,13 +19,15 @@ package org.apache.tuscany.sca.sample.comet; +import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; import org.apache.tuscany.sca.sample.comet.model.Location; -import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Callback; import org.oasisopen.sca.annotation.Remotable; @Remotable +@Callback(CometCallback.class) public interface HumidityService { - Response getHumidity(Location location); + void getHumidity(Location location); -} +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java index afbdcbc8d7..a53fac5ed1 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java @@ -19,13 +19,17 @@ package org.apache.tuscany.sca.sample.comet; +import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; import org.apache.tuscany.sca.sample.comet.model.Location; -import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Callback; +import org.oasisopen.sca.annotation.OneWay; import org.oasisopen.sca.annotation.Remotable; @Remotable +@Callback(CometCallback.class) public interface PrecipitationService { - Response getPrecipitation(Location location); + @OneWay + void getPrecipitation(Location location); } diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java index 4278ef975b..4798a3457e 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java @@ -21,19 +21,32 @@ package org.apache.tuscany.sca.sample.comet; import java.util.Date; +import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; import org.apache.tuscany.sca.sample.comet.model.Location; import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Callback; import org.oasisopen.sca.annotation.Service; @Service(PrecipitationService.class) public class PrecipitationServiceImpl implements PrecipitationService { - @Override - public Response getPrecipitation(final Location location) { - final Response response = new Response(); - response.setDate(new Date()); - response.setData(Helper.randomInt(100) + "%"); - return response; - } + @Callback + protected CometCallback callback; + + @Override + public void getPrecipitation(final Location location) { + while (callback.isClientConnected()) { + Response response = new Response(); + response.setDate(new Date()); + response.setData(Helper.randomInt(100) + "%"); + + callback.sendResponse(response); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } } diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java index 55f935fa9f..41654a417b 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java @@ -21,28 +21,50 @@ package org.apache.tuscany.sca.sample.comet; import java.util.Date; +import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; import org.apache.tuscany.sca.sample.comet.model.Location; import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Callback; import org.oasisopen.sca.annotation.Service; -@Service({TemperatureService.class, HumidityService.class}) -public class TemperatureHumidityServiceImpl implements TemperatureService, HumidityService { - - @Override - public Response getHumidity(final Location location) { - final Response response = new Response(); - response.setDate(new Date()); - response.setData(Helper.randomInt(90) + "%"); - return response; - } - - @Override - public Response getTemperature(final Location location, final int scale) { - final Response response = new Response(); - response.setDate(new Date()); - final String data = "" + Helper.randomInt(scale == TemperatureService.CELSIUS ? 40 : 150); - response.setData(data); - return response; - } - -} +@Service({ TemperatureService.class, HumidityService.class }) +public class TemperatureHumidityServiceImpl implements TemperatureService, + HumidityService { + + @Callback + protected CometCallback callback; + + @Override + public void getHumidity(final Location location) { + while (callback.isClientConnected()) { + final Response response = new Response(); + response.setDate(new Date()); + response.setData(Helper.randomInt(90) + "%"); + callback.sendResponse(response); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + @Override + public void getTemperature(final Location location, final int scale) { + while (callback.isClientConnected()) { + final Response response = new Response(); + response.setDate(new Date()); + final String data = "" + + Helper.randomInt(scale == TemperatureService.CELSIUS ? 40 + : 150); + response.setData(data); + callback.sendResponse(response); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java index 092988213b..385107c6ac 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java @@ -19,16 +19,18 @@ package org.apache.tuscany.sca.sample.comet; +import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; import org.apache.tuscany.sca.sample.comet.model.Location; -import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Callback; import org.oasisopen.sca.annotation.Remotable; @Remotable +@Callback(CometCallback.class) public interface TemperatureService { - public static final int CELSIUS = 1; - public static final int FAHRENHEIT = 2; + public static final int CELSIUS = 1; + public static final int FAHRENHEIT = 2; - Response getTemperature(Location location, int scale); + void getTemperature(Location location, int scale); -} +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/WEB-INF/web.composite b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/WEB-INF/web.composite index 05b2ddd0d7..20d25fe527 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/WEB-INF/web.composite +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/WEB-INF/web.composite @@ -20,25 +20,38 @@ <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" targetNamespace="http://samples" - name="Stock"> + name="Weather"> <component name="c1"> <implementation.java class="org.apache.tuscany.sca.sample.comet.TemperatureHumidityServiceImpl"/> <service name="TemperatureService"> - <interface.java interface="org.apache.tuscany.sca.sample.comet.TemperatureService"/> + <interface.java interface="org.apache.tuscany.sca.sample.comet.TemperatureService" + callbackInterface="org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback"/> <tuscany:binding.comet/> + <callback> + <tuscany:binding.comet/> + </callback> </service> <service name="HumidityService"> - <interface.java interface="org.apache.tuscany.sca.sample.comet.HumidityService"/> + <interface.java interface="org.apache.tuscany.sca.sample.comet.HumidityService" + callbackInterface="org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback"/> <tuscany:binding.comet/> + <callback> + <tuscany:binding.comet/> + </callback> </service> </component> + <component name="c2"> <implementation.java class="org.apache.tuscany.sca.sample.comet.PrecipitationServiceImpl"/> <service name="PrecipitationService"> - <interface.java interface="org.apache.tuscany.sca.sample.comet.PrecipitationService"/> + <interface.java interface="org.apache.tuscany.sca.sample.comet.PrecipitationService" + callbackInterface="org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback"/> <tuscany:binding.comet/> + <callback> + <tuscany:binding.comet/> + </callback> </service> </component> diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/index.html b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/index.html index 0387e67adb..43dcb607a2 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/index.html +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/webapp/index.html @@ -20,7 +20,7 @@ <head> <title>Apache Tuscany Comet Sample</title> <!-- Tuscany Comet Javascript Toolkit is dependent on jQuery --> - <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> + <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript" src="org.apache.tuscany.sca.cometComponentContext.js"></script> <script type="text/javascript"> $(document).ready(function() @@ -67,18 +67,22 @@ document.getElementById('tempCButton').onclick = function(event) { SCA.CometComponentContext.TemperatureService.getTemperature(location, 1, updateTempC); + document.getElementById('tempCButton').disabled = true; } document.getElementById('tempFButton').onclick = function(event) { SCA.CometComponentContext.TemperatureService.getTemperature(location, 2, updateTempF); + document.getElementById('tempFButton').disabled = true; } document.getElementById('humButton').onclick = function(event) { SCA.CometComponentContext.HumidityService.getHumidity(location, updateHum); + document.getElementById('humButton').disabled = true; } document.getElementById('precipButton').onclick = function(event) { SCA.CometComponentContext.PrecipitationService.getPrecipitation(location, updatePrecip); + document.getElementById('precipButton').disabled = true; } }); |