From 24bb8d65b5ad54121ce666ee1d805f0f6ec3d713 Mon Sep 17 00:00:00 2001 From: fmoga Date: Sat, 14 Aug 2010 00:42:53 +0000 Subject: Modified the sample in order to illustrate how the binding handles multiple comet services through the same persisted http connection. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@985415 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-2.x/contrib/samples/stock-comet/pom.xml | 10 +-- .../tuscany/sca/sample/comet/HumidityService.java | 10 +++ .../sca/sample/comet/PrecipitationService.java | 10 +++ .../sca/sample/comet/PrecipitationServiceImpl.java | 16 ++++ .../tuscany/sca/sample/comet/StockService.java | 28 ------- .../tuscany/sca/sample/comet/StockServiceImpl.java | 39 ---------- .../comet/TemperatureHumidityServiceImpl.java | 26 +++++++ .../sca/sample/comet/TemperatureService.java | 12 +++ .../src/main/webapp/WEB-INF/web.composite | 20 ++++- .../stock-comet/src/main/webapp/WEB-INF/web.xml | 38 ++++------ .../samples/stock-comet/src/main/webapp/index.html | 86 ++++++++++++++-------- ...org.apache.tuscany.sca.cometComponentContext.js | 55 ++++++++++++++ 12 files changed, 222 insertions(+), 128 deletions(-) create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java delete mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java delete mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java create mode 100644 sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js (limited to 'sca-java-2.x') diff --git a/sca-java-2.x/contrib/samples/stock-comet/pom.xml b/sca-java-2.x/contrib/samples/stock-comet/pom.xml index f6f68d1e66..a329c2bdaf 100644 --- a/sca-java-2.x/contrib/samples/stock-comet/pom.xml +++ b/sca-java-2.x/contrib/samples/stock-comet/pom.xml @@ -23,10 +23,10 @@ org.apache.tuscany.sca - sample-stock-comet-webapp + sample-comet-weather-monitor-webapp war 1.0 - stock-comet + weather-monitor @@ -37,12 +37,12 @@ org.atmosphere atmosphere-commons - 0.7-SNAPSHOT + 0.6.1 org.atmosphere atmosphere-runtime - 0.7-SNAPSHOT + 0.6.1 javax @@ -67,7 +67,7 @@ - stock-comet + weather-monitor diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java new file mode 100644 index 0000000000..faf80f02e0 --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java @@ -0,0 +1,10 @@ +package org.apache.tuscany.sca.sample.comet; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HumidityService { + + String getHumidity(); + +} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java new file mode 100644 index 0000000000..f40b2eb772 --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java @@ -0,0 +1,10 @@ +package org.apache.tuscany.sca.sample.comet; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface PrecipitationService { + + String getPrecipitation(); + +} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java new file mode 100644 index 0000000000..df24a74080 --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java @@ -0,0 +1,16 @@ +package org.apache.tuscany.sca.sample.comet; + +import java.util.Date; +import java.util.Random; + +import org.oasisopen.sca.annotation.Service; + +@Service(PrecipitationService.class) +public class PrecipitationServiceImpl implements PrecipitationService { + + @Override + public String getPrecipitation() { + return (new Random(new Date().getTime()).nextInt(100)) + "%"; + } + +} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java deleted file mode 100644 index 767e8f5666..0000000000 --- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.sample.comet; - -import org.oasisopen.sca.annotation.Remotable; - -@Remotable -public interface StockService { - - String getQuotes(); - -} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java deleted file mode 100644 index d70724e90a..0000000000 --- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.sample.comet; - -import java.text.DecimalFormat; -import java.util.Date; -import java.util.Random; - -import org.oasisopen.sca.annotation.Service; - -@Service(StockService.class) -public class StockServiceImpl implements StockService { - - public static final int MAX_VALUE = 1000; - private Random random = new Random(new Date().getTime()); - - @Override - public String getQuotes() { - Double value = Math.abs(random.nextDouble() * random.nextInt(MAX_VALUE)); - return "ASF" + "#" + Double.valueOf(new DecimalFormat("#.##").format(value)); - } - -} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java new file mode 100644 index 0000000000..1fff4b1dea --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java @@ -0,0 +1,26 @@ +package org.apache.tuscany.sca.sample.comet; + +import java.util.Date; +import java.util.Random; + +import org.oasisopen.sca.annotation.Service; + +@Service({TemperatureService.class, HumidityService.class}) +public class TemperatureHumidityServiceImpl implements TemperatureService, HumidityService { + + @Override + public String getHumidity() { + return (new Random(new Date().getTime()).nextInt(100)) + "%"; + } + + @Override + public String getTemperatureCelsius() { + return "" + (new Random(new Date().getTime()).nextInt(40)); + } + + @Override + public String getTemperatureFahrenheit() { + return "" + (new Random(new Date().getTime()).nextInt(200)); + } + +} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java new file mode 100644 index 0000000000..6a9e30b051 --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java @@ -0,0 +1,12 @@ +package org.apache.tuscany.sca.sample.comet; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface TemperatureService { + + String getTemperatureCelsius(); + + String getTemperatureFahrenheit(); + +} diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.composite b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.composite index 5a1d2bb21b..05b2ddd0d7 100644 --- a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.composite +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.composite @@ -22,10 +22,22 @@ targetNamespace="http://samples" name="Stock"> - - - - + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.xml b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.xml index cf792265da..047fd5e21d 100644 --- a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.xml +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/WEB-INF/web.xml @@ -10,26 +10,18 @@ WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. --> - - - Apache Tuscany Stock Comet Sample - - - tuscany - org.apache.tuscany.sca.host.webapp.TuscanyServletFilter - true - - - - tuscany - /* - - - - index.html - - - + + Apache Tuscany Stock Comet Sample + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + true + + + tuscany + /* + + + index.html + + \ No newline at end of file diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/index.html b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/index.html index 816038d0e9..71c9b03960 100644 --- a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/index.html +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/index.html @@ -20,38 +20,51 @@ Apache Tuscany Comet Sample - + + @@ -63,14 +76,29 @@ -

Stock Monitor

- +

Weather Monitor

-

- - N/A - - N/A -
+ + + + + + + + + + + + + + + + + + + + + +
Temperature (Celsius):N/A
Temperature (Fahrenheit):N/A
Humidity:N/A
Precipitation probability:N/A
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js new file mode 100644 index 0000000000..c8dc19d15a --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js @@ -0,0 +1,55 @@ +// TODO: Try isolating functional code one piece at a time by using it like in the inital version +var tuscanyComet = { + connectedEndpoint : null, + connect : function(transport) { + $.atmosphere.subscribe(document.location.toString() + 'tuscany-comet', + this.callback, + $.atmosphere.request = { + transport : transport + }); + this.connectedEndpoint = $.atmosphere.response; + }, + callAsync : function(url, callbackMethod) { + this.connectedEndpoint.push(document.location.toString() + + 'tuscany-comet/' + url, + null, + $.atmosphere.request = { + method : 'POST', + data : 'callback=' + callbackMethod.name + }); + }, + callback : function(response) { + var data = response.responseBody; + if (data.indexOf('#') != -1) { + var callbackMethod = data.substring(0, data.indexOf('#')); + data = data.substring(data.indexOf('#') + 1); + eval(callbackMethod + '("' + data + '");'); + } + } +}; + +// To be generated +var cometComponentContext = { + c1 : { + TemperatureService : { + getTemperatureCelsius : function(callbackMethod) { + tuscanyComet.callAsync('c1/TemperatureService/getTemperatureCelsius', callbackMethod); + }, + getTemperatureFahrenheit : function(callbackMethod) { + tuscanyComet.callAsync('c1/TemperatureService/getTemperatureFahrenheit', callbackMethod); + } + }, + HumidityService : { + getHumidity : function(callbackMethod) { + tuscanyComet.callAsync('c1/HumidityService/getHumidity', callbackMethod); + } + } + }, + c2 : { + PrecipitationService : { + getPrecipitation : function(callbackMethod) { + tuscanyComet.callAsync('c2/PrecipitationService/getPrecipitation', callbackMethod); + } + } + } +} \ No newline at end of file -- cgit v1.2.3