summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js
diff options
context:
space:
mode:
authorfmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68>2010-08-14 00:42:53 +0000
committerfmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68>2010-08-14 00:42:53 +0000
commit24bb8d65b5ad54121ce666ee1d805f0f6ec3d713 (patch)
tree916871d9cedcbe799938509341153dd4b40d1be3 /sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js
parenteff7bb9dd439b9d9d74cb54b4cf0733e6b3ca0cf (diff)
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
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js55
1 files changed, 55 insertions, 0 deletions
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