summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/samples/stock-comet/src/main/java
diff options
context:
space:
mode:
authorfmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68>2010-08-02 20:27:46 +0000
committerfmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68>2010-08-02 20:27:46 +0000
commit76e64f8719a90867fa0f8157c4e66e75ccfc8481 (patch)
tree2a6cbe447c1eaa14d980e2669c4552a36faa31a8 /sca-java-2.x/contrib/samples/stock-comet/src/main/java
parent1491d3d1338236d1dfba96aa2387075c6a74dbb3 (diff)
Updated the stock sample to use the comet binding implementation.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@981678 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java (renamed from sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockService.java)9
-rw-r--r--sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java (renamed from sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockServiceImpl.java)16
-rw-r--r--sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/CometServlet.java116
-rw-r--r--sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/ScriptFilter.java20
4 files changed, 12 insertions, 149 deletions
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockService.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java
index 46f69834ae..767e8f5666 100644
--- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockService.java
+++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockService.java
@@ -16,12 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package org.apache.tuscany.sca.sample.comet;
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
public interface StockService {
- String getSymbol();
+ String getQuotes();
- Double getValue();
-
}
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockServiceImpl.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java
index f6a4d743a1..d70724e90a 100644
--- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/StockServiceImpl.java
+++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/org/apache/tuscany/sca/sample/comet/StockServiceImpl.java
@@ -16,26 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package sample;
+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 getSymbol() {
- return "ASF";
- }
-
- @Override
- public Double getValue() {
+ public String getQuotes() {
Double value = Math.abs(random.nextDouble() * random.nextInt(MAX_VALUE));
- return Double.valueOf(new DecimalFormat("#.##").format(value));
+ return "ASF" + "#" + Double.valueOf(new DecimalFormat("#.##").format(value));
}
-
+
}
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/CometServlet.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/CometServlet.java
deleted file mode 100644
index c93dc144dc..0000000000
--- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/CometServlet.java
+++ /dev/null
@@ -1,116 +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 sample;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.atmosphere.cpr.AtmosphereResourceEvent;
-import org.atmosphere.cpr.AtmosphereResourceEventListener;
-import org.atmosphere.cpr.BroadcastFilter;
-import org.atmosphere.cpr.Broadcaster;
-import org.atmosphere.cpr.Meteor;
-import org.atmosphere.util.XSSHtmlFilter;
-import org.oasisopen.sca.ComponentContext;
-
-@SuppressWarnings("serial")
-public class CometServlet extends HttpServlet {
-
- private static final String COMPONENT_CONTEXT_KEY = "org.oasisopen.sca.ComponentContext";
- private static final String COMET_SCOPE_KEY = "org.apache.tuscany.comet.scope";
- private static final String METEOR_KEY = "org.apache.tuscany.comet.meteor";
-
- // TODO: check if static variables are a good choice here
- private static List<BroadcastFilter> filters;
- private static Broadcaster.SCOPE scope;
-
-
- @Override
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- filters = new LinkedList<BroadcastFilter>();
- filters.add(new XSSHtmlFilter());
- filters.add(new ScriptFilter());
- String cometScope = getInitParameter(COMET_SCOPE_KEY).trim().toUpperCase();
- scope = Broadcaster.SCOPE.valueOf(cometScope);
- }
-
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- Meteor meteor = Meteor.build(request, scope, filters, null);
- meteor.addListener(new CometEventListener());
- request.getSession().setAttribute(METEOR_KEY, meteor);
- response.setContentType("text/html");
- meteor.suspend(-1); // http streaming
- }
-
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
- Meteor meteor = (Meteor)request.getSession().getAttribute(METEOR_KEY);
-
- // TODO: add dynamic call and cast
- // String component = request.getParameter("component");
- // String method = request.getParameter("method");
- // String params = request.getParameter("params");
- // String componentClass = request.getParameter("component.class");
-
- // TODO: check if cc has all the information when servlet is not in
- // web.composite
- ComponentContext cc = (ComponentContext)getServletContext().getAttribute(COMPONENT_CONTEXT_KEY);
- StockService service = cc.getService(StockService.class, "service");
-
- // TODO: add JSON serialization
- meteor.broadcast(service.getSymbol() + "#" + service.getValue());
- }
-
- // ----------------------------------------------
-
- public class CometEventListener implements AtmosphereResourceEventListener {
-
- @Override
- public void onSuspend(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
- System.out.println("onSuspend: " + event);
- }
-
- @Override
- public void onResume(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
- System.out.println("onResume: " + event);
- }
-
- @Override
- public void onDisconnect(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
- System.out.println("onDisconnect: " + event);
- }
-
- @Override
- public void onBroadcast(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
- System.out.println("onBroadcast: " + event);
- }
-
- }
-
-}
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/ScriptFilter.java b/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/ScriptFilter.java
deleted file mode 100644
index 61cf1b79df..0000000000
--- a/sca-java-2.x/contrib/samples/stock-comet/src/main/java/sample/ScriptFilter.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package sample;
-
-import org.atmosphere.cpr.BroadcastFilter;
-
-public class ScriptFilter implements BroadcastFilter {
-
- private static final String BEGIN_SCRIPT_TAG = "<script type='text/javascript'>\n";
- private static final String END_SCRIPT_TAG = "</script>\n";
- // TODO: add dynamic function configuration
- private static final String DEFAULT_FUNCTION = "window.parent.update";
-
- public BroadcastAction filter(Object o) {
- if (o instanceof String) {
- String message = (String)o;
- return new BroadcastAction(BEGIN_SCRIPT_TAG + DEFAULT_FUNCTION + "('" + message + "');\n" + END_SCRIPT_TAG);
- } else {
- return new BroadcastAction(o);
- }
- }
-}