You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by fm...@apache.org on 2011/05/31 12:46:25 UTC

svn commit: r1129609 - in /tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main: java/org/apache/tuscany/sca/binding/comet/runtime/ java/org/apache/tuscany/sca/binding/comet/runtime/callback/ java/org/apache/tuscany/sca/binding/comet/runti...

Author: fmoga
Date: Tue May 31 10:46:24 2011
New Revision: 1129609

URL: http://svn.apache.org/viewvc?rev=1129609&view=rev
Log:
Code cleanup.

Added:
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometCallbackInvoker.java
      - copied, changed from r1129323, tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometInvoker.java
Removed:
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometInvoker.java
Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometBindingProviderFactory.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometReferenceBindingProvider.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/CometCallback.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/Status.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/handler/CometBindingHandler.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometEndpointManager.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometOperationManager.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometSessionManager.java
    tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometBindingProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometBindingProviderFactory.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometBindingProviderFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometBindingProviderFactory.java Tue May 31 10:46:24 2011
@@ -35,13 +35,10 @@ import org.apache.tuscany.sca.runtime.Ru
 public class CometBindingProviderFactory implements BindingProviderFactory<CometBinding> {
 
     /**
-     * Underlying servlet host. Injected by constructor.
+     * Underlying servlet host.
      */
     private final ServletHost servletHost;
 
-    /**
-     * Constructor.
-     */
     public CometBindingProviderFactory(final ExtensionPointRegistry extensionPoints) {
         this.servletHost = ServletHostHelper.getServletHost(extensionPoints);
     }

Copied: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometCallbackInvoker.java (from r1129323, tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometInvoker.java)
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometCallbackInvoker.java?p2=tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometCallbackInvoker.java&p1=tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometInvoker.java&r1=1129323&r2=1129609&rev=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometCallbackInvoker.java Tue May 31 10:46:24 2011
@@ -32,18 +32,32 @@ import org.atmosphere.cpr.Broadcaster;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
-public class CometInvoker implements Invoker {
-
+/**
+ * Receives callback invocations and sends messages back to the browser.
+ */
+public class CometCallbackInvoker implements Invoker {
+
+    /**
+     * JSON converter
+     */
     private static Gson gson = new GsonBuilder().serializeNulls().create();
 
     protected Operation operation;
     protected EndpointReference endpoint;
 
-    public CometInvoker(final Operation operation, final EndpointReference endpoint) {
+    public CometCallbackInvoker(final Operation operation, final EndpointReference endpoint) {
         this.operation = operation;
         this.endpoint = endpoint;
     }
 
+    /**
+     * Sends message back to the browser client and reports connection status to
+     * the runtime.
+     * 
+     * @param msg
+     *            message to send to the browser
+     * @return the connection status
+     */
     @Override
     public Message invoke(final Message msg) {
         String sessionId = (String) msg.getHeaders().get(Constants.RELATES_TO);
@@ -61,7 +75,6 @@ public class CometInvoker implements Inv
             response.setBody(Status.OK);
         }
         return response;
-
     }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometReferenceBindingProvider.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometReferenceBindingProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometReferenceBindingProvider.java Tue May 31 10:46:24 2011
@@ -26,8 +26,9 @@ import org.apache.tuscany.sca.invocation
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 
 /**
- * Provider for references that have comet binding specified in the scdl. Not
- * used as comet binding references would occur in client browser's Javascript.
+ * Provider for references and callbacks that have comet binding specified in
+ * the scdl. Used by callbacks to create invokers. Not used for comet
+ * references as they are javascript proxies not Java objects.
  */
 public class CometReferenceBindingProvider implements ReferenceBindingProvider {
 
@@ -42,19 +43,13 @@ public class CometReferenceBindingProvid
 
     @Override
     public Invoker createInvoker(final Operation operation) {
-        return new CometInvoker(operation, this.endpoint);
+        return new CometCallbackInvoker(operation, endpoint);
     }
 
-    /**
-     * No behavior.
-     */
     @Override
     public void start() {
     }
 
-    /**
-     * No behavior.
-     */
     @Override
     public void stop() {
     }
@@ -66,7 +61,7 @@ public class CometReferenceBindingProvid
 
     @Override
     public boolean supportsOneWayInvocation() {
-        return true;
+        return false;
     }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java Tue May 31 10:46:24 2011
@@ -36,50 +36,53 @@ import org.apache.tuscany.sca.runtime.Ru
  */
 public class CometServiceBindingProvider implements ServiceBindingProvider {
 
-	private final RuntimeEndpoint endpoint;
-	private final ServletHost servletHost;
+    private RuntimeEndpoint endpoint;
+    private ServletHost servletHost;
 
-	public CometServiceBindingProvider(final RuntimeEndpoint endpoint, final ServletHost servletHost) {
-		this.endpoint = endpoint;
-		this.servletHost = servletHost;
-	}
-
-	@Override
-	public void start() {
-		String deployedURI = ServletFactory.registerServlet(this.servletHost);
-		endpoint.setDeployedURI(deployedURI);
-		final ComponentService service = this.endpoint.getService();
-		final Interface serviceInterface = service.getInterfaceContract().getInterface();
-		JavascriptGenerator.generateServiceProxy(service);
-		for (final Operation operation : serviceInterface.getOperations()) {
-			final String url = "/" + endpoint.getService().getName() + "/" + operation.getName();
-			CometEndpointManager.add(url, endpoint);
-			CometOperationManager.add(url, operation);
-			JavascriptGenerator.generateMethodProxy(service, operation);
-		}
-	}
-
-	/**
-	 * This method is used to stop the provider.
-	 */
-	@Override
-	public void stop() {
-		ServletFactory.unregisterServlet(this.servletHost);
-		CometEndpointManager.clear();
-		CometOperationManager.clear();
-		CometSessionManager.clear();
-	}
-
-	@Override
-	public InterfaceContract getBindingInterfaceContract() {
-		return endpoint.getService().getInterfaceContract();
-	}
-
-	@Override
-	public boolean supportsOneWayInvocation() {
-		// set to false so the runtime will add a nonBlocking interceptor to
-		// handle @OneWay calls
-		return false;
-	}
+    public CometServiceBindingProvider(final RuntimeEndpoint endpoint, final ServletHost servletHost) {
+        this.endpoint = endpoint;
+        this.servletHost = servletHost;
+    }
+
+    /**
+     * Init the comet binding server-side infrastructure.
+     */
+    @Override
+    public void start() {
+        String deployedURI = ServletFactory.registerServlet(this.servletHost);
+        endpoint.setDeployedURI(deployedURI);
+        final ComponentService service = this.endpoint.getService();
+        final Interface serviceInterface = service.getInterfaceContract().getInterface();
+        JavascriptGenerator.generateServiceProxy(service);
+        for (final Operation operation : serviceInterface.getOperations()) {
+            final String url = "/" + endpoint.getService().getName() + "/" + operation.getName();
+            CometEndpointManager.add(url, endpoint);
+            CometOperationManager.add(url, operation);
+            JavascriptGenerator.generateMethodProxy(service, operation);
+        }
+    }
+
+    /**
+     * Stop the comet binding server-side infrastructure.
+     */
+    @Override
+    public void stop() {
+        ServletFactory.unregisterServlet(this.servletHost);
+        CometEndpointManager.clear();
+        CometOperationManager.clear();
+        CometSessionManager.clear();
+    }
+
+    @Override
+    public InterfaceContract getBindingInterfaceContract() {
+        return endpoint.getService().getInterfaceContract();
+    }
+
+    @Override
+    public boolean supportsOneWayInvocation() {
+        // set to false so the runtime will add a nonBlocking interceptor to
+        // handle @OneWay calls
+        return false;
+    }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java Tue May 31 10:46:24 2011
@@ -23,93 +23,106 @@ import org.apache.tuscany.sca.host.http.
 import org.atmosphere.cpr.AtmosphereServlet;
 
 /**
- * This class is used to create two servlets: one exposing all the comet
- * services, the other one exposing the javascript toolkit. Exposing all comet
- * services through a single servlet is needed as the browsers are undergone by
- * the two http connection limit so all comet services should send their
- * responses via the same http connection to the same client. Dispatching to the
- * corresponding endpoint and operation is done internally using Jersey RESTful
- * Web Services integration with the AtmosphereServlet. The Javascript toolkit
- * servlet is unique as it is not tied to any of the services - it offers a
- * global API.
+ * This class adds two servlets to the runtime: one exposing all the comet
+ * services, the other one exposing the javascript toolkit.
+ * 
+ * Exposing all comet services through a single servlet is needed as browsers
+ * are undergone by the two http connection limit per domain so all comet
+ * services should send their responses via the same http connection to a single
+ * client.
+ * 
+ * Dispatching to the corresponding endpoint and operation is done internally
+ * using Jersey RESTful Web Services integration with the AtmosphereServlet.
+ * 
+ * The Javascript toolkit is not tied to any of the services so it is exposed by
+ * a separate servlet.
  */
 public final class ServletFactory {
 
-	/**
-	 * Init-param key for the AtmosphereServlet defining where to look for
-	 * Jersey classes.
-	 */
-	private static final String PACKAGE_KEY = "com.sun.jersey.config.property.packages";
-
-	/**
-	 * Package of the class handling dispatching to endpoints.
-	 */
-	private static final String PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.handler";
-
-	/**
-	 * Package of the class handling Javascript toolkit retrieval.
-	 */
-	private static final String JS_PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.javascript";
-
-	/**
-	 * Key in the ServletContext where the comet component context is stored.
-	 */
-	public static final String COMET_COMPONENT_CONTEXT_KEY = "org.apache.tuscany.sca.binding.comet.operations";
-
-	/**
-	 * Path where services will be exposed.
-	 */
-	public static final String PATH = "/tuscany-comet/*";
-
-	/**
-	 * Path where Javascript toolkit will be exposed.
-	 */
-	public static final String JS_PATH = "/tuscany-comet-js/*";
-
-	/**
-	 * The servlet that is exposing the comet services.
-	 */
-	private static AtmosphereServlet cometServlet = null;
-
-	/**
-	 * The servlet that is exposing the Javascript toolkit.
-	 */
-	private static AtmosphereServlet javascriptServlet = null;
-
-	/**
-	 * Private constructor for the singleton class.
-	 */
-	private ServletFactory() {
-	}
-
-	public static synchronized String registerServlet(final ServletHost servletHost) {
-		String uri = registerCometServlet(servletHost);
-		registerJavascriptServlet(servletHost);
-		return uri;
-	}
-
-	private static String registerCometServlet(ServletHost servletHost) {
-		if (ServletFactory.cometServlet == null) {
-			ServletFactory.cometServlet = new AtmosphereServlet();
-			ServletFactory.cometServlet.addInitParameter(ServletFactory.PACKAGE_KEY, ServletFactory.PACKAGE_VALUE);
-			String uri = servletHost.addServletMapping(ServletFactory.PATH, ServletFactory.cometServlet);
-			return uri;
-		}
-		return null;
-	}
-
-	private static void registerJavascriptServlet(ServletHost servletHost) {
-		if (ServletFactory.javascriptServlet == null) {
-			ServletFactory.javascriptServlet = new AtmosphereServlet();
-			ServletFactory.javascriptServlet.addInitParameter(ServletFactory.PACKAGE_KEY,
-					ServletFactory.JS_PACKAGE_VALUE);
-			servletHost.addServletMapping(ServletFactory.JS_PATH, ServletFactory.javascriptServlet);
-		}
-	}
-
-	public static void unregisterServlet(final ServletHost servletHost) {
-		servletHost.removeServletMapping(ServletFactory.PATH);
-		servletHost.removeServletMapping(ServletFactory.JS_PATH);
-	}
+    /**
+     * Init-param key for the AtmosphereServlet defining where to look for
+     * Jersey classes.
+     */
+    private static final String PACKAGE_KEY = "com.sun.jersey.config.property.packages";
+
+    /**
+     * Package of the class handling dispatching to endpoints.
+     */
+    private static final String HANDLER_PACKAGE = "org.apache.tuscany.sca.binding.comet.runtime.handler";
+
+    /**
+     * Package of the class handling Javascript toolkit retrieval.
+     */
+    private static final String JS_PACKAGE = "org.apache.tuscany.sca.binding.comet.runtime.javascript";
+
+    /**
+     * Path where services will be exposed.
+     */
+    public static final String PATH = "/tuscany-comet/*";
+
+    /**
+     * Path where Javascript toolkit will be exposed.
+     */
+    public static final String JS_PATH = "/tuscany-comet-js/*";
+
+    /**
+     * The servlet that is exposing the comet services.
+     */
+    private static AtmosphereServlet cometServlet = null;
+
+    /**
+     * The servlet that is exposing the Javascript toolkit.
+     */
+    private static AtmosphereServlet javascriptServlet = null;
+
+    /**
+     * Prevent instantiation of singleton class.
+     */
+    private ServletFactory() {
+    }
+
+    /**
+     * Adds servlets to the underlying servlet host. No need for thread safety
+     * as calls to this method are sequentially done for each comet endpoint
+     * found by the runtime.
+     * 
+     * @param servletHost
+     *            underlying servlet host
+     * @return uri where servlet has been mapped
+     */
+    public static String registerServlet(final ServletHost servletHost) {
+        String uri = registerCometServlet(servletHost);
+        registerJavascriptServlet(servletHost);
+        return uri;
+    }
+
+    private static String registerCometServlet(ServletHost servletHost) {
+        if (ServletFactory.cometServlet == null) {
+            ServletFactory.cometServlet = new AtmosphereServlet();
+            ServletFactory.cometServlet.addInitParameter(ServletFactory.PACKAGE_KEY, ServletFactory.HANDLER_PACKAGE);
+            String uri = servletHost.addServletMapping(ServletFactory.PATH, ServletFactory.cometServlet);
+            return uri;
+        }
+        return null;
+    }
+
+    private static void registerJavascriptServlet(ServletHost servletHost) {
+        if (ServletFactory.javascriptServlet == null) {
+            ServletFactory.javascriptServlet = new AtmosphereServlet();
+            ServletFactory.javascriptServlet.addInitParameter(ServletFactory.PACKAGE_KEY, ServletFactory.JS_PACKAGE);
+            servletHost.addServletMapping(ServletFactory.JS_PATH, ServletFactory.javascriptServlet);
+        }
+    }
+
+    /**
+     * Removes servlets from the servlet host.
+     * 
+     * @param servletHost
+     *            the underlying servlet host.
+     */
+    public static void unregisterServlet(final ServletHost servletHost) {
+        servletHost.removeServletMapping(ServletFactory.PATH);
+        servletHost.removeServletMapping(ServletFactory.JS_PATH);
+    }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/CometCallback.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/CometCallback.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/CometCallback.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/CometCallback.java Tue May 31 10:46:24 2011
@@ -21,9 +21,19 @@ package org.apache.tuscany.sca.binding.c
 
 import org.oasisopen.sca.annotation.Remotable;
 
+/**
+ * The comet callback interface.
+ */
 @Remotable
 public interface CometCallback {
 
-	Status sendMessage(Object message);
+    /**
+     * Send message back to the browser client.
+     * 
+     * @param message
+     *            message to send
+     * @return status of the underlying connection with the browser
+     */
+    Status sendMessage(Object message);
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/Status.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/Status.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/Status.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/callback/Status.java Tue May 31 10:46:24 2011
@@ -1,5 +1,27 @@
+/*
+ * 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.binding.comet.runtime.callback;
 
+/**
+ * Status of the connection with the browser client.
+ */
 public enum Status {
-	OK, CLIENT_DISCONNECTED
+    OK, CLIENT_DISCONNECTED
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/handler/CometBindingHandler.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/handler/CometBindingHandler.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/handler/CometBindingHandler.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/handler/CometBindingHandler.java Tue May 31 10:46:24 2011
@@ -49,15 +49,27 @@ import org.atmosphere.jersey.SuspendResp
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
+/**
+ * Handles requests for comet services and for creating a persistent connection.
+ */
 @Path("/")
 public class CometBindingHandler {
 
+    /**
+     * JSON converter
+     */
     private static Gson gson = new GsonBuilder().serializeNulls().create();
 
+    /**
+     * Suspends the current HTTP connection.
+     * 
+     * @param sessionId
+     *            session id to identify client
+     * @return a response that is not committed, just flushed
+     */
     @GET
     @Path("/connect")
     public SuspendResponse<String> connect(@QueryParam("sessionId") String sessionId) {
-        System.out.println("-- connect -- Session Id: " + sessionId);
         Broadcaster broadcaster = CometSessionManager.get(sessionId);
         if (broadcaster == null) {
             broadcaster = new JerseyBroadcaster(sessionId);
@@ -67,12 +79,27 @@ public class CometBindingHandler {
                 .build();
     }
 
+    /**
+     * Handles requests for service operations.
+     * 
+     * @param service
+     *            the service to invoke
+     * @param method
+     *            the method to invoke
+     * @param sessionId
+     *            the client session id
+     * @param callbackMethod
+     *            the callbackMethod to invoke once a response is available
+     * @param jsonData
+     *            method arguments sent by the client in JSON format
+     * @throws InvocationTargetException
+     *             if a problem occurs while invoking the service implementation
+     */
     @POST
     @Path("/{service}/{method}")
     public void handleRequest(@PathParam("service") String service, @PathParam("method") String method,
             @FormParam("sessionId") String sessionId, @FormParam("callbackMethod") String callbackMethod,
             @FormParam("params") String jsonData) throws InvocationTargetException {
-        System.out.println("-- handleRequest -- Session Id: " + sessionId);
         String url = "/" + service + "/" + method;
         RuntimeEndpoint wire = CometEndpointManager.get(url);
         Operation operation = CometOperationManager.get(url);
@@ -93,32 +120,18 @@ public class CometBindingHandler {
     }
 
     /**
-     * Convert request parameters from JSON to operation parameter types.
-     * 
-     * @param jsonData
-     * @param operation
-     * @return
-     */
-    private Object[] decodeJsonDataForOperation(String jsonData, Operation operation) {
-        Object[] args = new Object[operation.getInputType().getLogical().size()];
-        final String[] json = this.parseArray(jsonData);
-        int index = 0;
-        // convert each argument to the corresponding class
-        for (final DataType<?> dataType : operation.getInputType().getLogical()) {
-            args[index] = gson.fromJson(json[index], dataType.getPhysical());
-            index++;
-        }
-        return args;
-    }
-
-    /**
-     * Creates the message to be sent with a mocked EndpointReference in the
-     * 'from' field as the request comes from a browser (there is no actual
-     * comet reference running in a controlled environment).
+     * Creates a message with a mocked EndpointReference in the 'from' field to
+     * simulate a comet reference (because requests are coming from browsers).
+     * This is needed by the callback mechanism to have a source for the
+     * request.
      * 
      * @param args
+     *            arguments for the method invocation
+     * @param sessionId
+     *            the session id of the client
      * @param callbackMethod
-     * @return
+     *            method to call once a response is available
+     * @return an invocation message
      */
     private Message createMessageWithMockedCometReference(Object[] args, String sessionId, String callbackMethod) {
         Message msg = new MessageImpl();
@@ -133,17 +146,37 @@ public class CometBindingHandler {
     }
 
     /**
-     * Parse the JSON array containing the arguments for the method call in
+     * Convert request parameters from JSON to operation parameter types.
+     * 
+     * @param jsonData
+     *            parameters in JSON array format
+     * @param operation
+     *            the operation to invoke
+     * @return an array of objects
+     */
+    private Object[] decodeJsonDataForOperation(String jsonData, Operation operation) {
+        Object[] args = new Object[operation.getInputType().getLogical().size()];
+        final String[] json = this.parseArray(jsonData);
+        int index = 0;
+        for (final DataType<?> dataType : operation.getInputType().getLogical()) {
+            args[index] = gson.fromJson(json[index], dataType.getPhysical());
+            index++;
+        }
+        return args;
+    }
+
+    /**
+     * Split the JSON array containing the arguments for the method call in
      * order to avoid converting JSON to Object[]. Converting each object
      * separately to it's corresponding type avoids type mismatch problems at
      * service invocation.
      * 
      * @param jsonArray
      *            the JSON array
-     * @return an array of JSON formatted objects
+     * @return an array of JSON formatted strings
      */
-    private String[] parseArray(final String jsonArray) {
-        final List<String> objects = new ArrayList<String>();
+    private String[] parseArray(String jsonArray) {
+        List<String> objects = new ArrayList<String>();
         int bracketNum = 0;
         int parNum = 0;
         int startPos = 1;
@@ -168,7 +201,6 @@ public class CometBindingHandler {
                 }
             }
         }
-        // add last object
         objects.add(jsonArray.substring(startPos, jsonArray.length() - 1));
         return objects.toArray(new String[] {});
     }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java Tue May 31 10:46:24 2011
@@ -23,7 +23,7 @@ import org.apache.tuscany.sca.assembly.C
 import org.apache.tuscany.sca.interfacedef.Operation;
 
 /**
- * This class generates proxies for the comet services.
+ * Generates javascript proxies for the comet services.
  */
 public class JavascriptGenerator {
 
@@ -42,50 +42,38 @@ public class JavascriptGenerator {
      */
     private static final String TUSCANY_COMET = "SCA.TuscanyComet";
 
-    /**
-     * Generated Javascript.
-     */
     private static StringBuffer javascript = new StringBuffer();
 
-    /**
-     * Default constructor for utility class.
-     */
     private JavascriptGenerator() {
     }
 
-    /**
-     * Getter for the generated Javascript.
-     * 
-     * @return the generated Javascript
-     */
     public static StringBuffer getJavascript() {
         return JavascriptGenerator.javascript;
     }
 
     /**
-     * Generates the proxy for a service.
+     * Generates the javascript proxy for a service.
      * 
-     * @param service the service for which generation is performed
+     * @param service
+     *            the service for which generation is performed
      */
     public static void generateServiceProxy(final ComponentService service) {
-        JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "."
-            + service.getName()
-            + " = new Object();\n");
+        JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "." + service.getName()
+                + " = new Object();\n");
     }
 
     /**
      * Generates the method inside the service proxy for the specified
      * operation.
      * 
-     * @param service the service containing the operation
-     * @param operation the operation
+     * @param service
+     *            the service containing the operation
+     * @param operation
+     *            the operation
      */
     public static void generateMethodProxy(final ComponentService service, final Operation operation) {
-        JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "."
-            + service.getName()
-            + "."
-            + operation.getName()
-            + " = function(");
+        JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "." + service.getName() + "."
+                + operation.getName() + " = function(");
         for (int i = 0; i < operation.getInputType().getLogical().size(); i++) {
             JavascriptGenerator.javascript.append("p" + i + ", ");
         }
@@ -95,12 +83,8 @@ public class JavascriptGenerator {
         for (int i = 0; i < operation.getInputType().getLogical().size(); i++) {
             JavascriptGenerator.javascript.append("  params.push(p" + i + ");\n");
         }
-        JavascriptGenerator.javascript.append("  " + JavascriptGenerator.TUSCANY_COMET
-            + ".callAsync('"
-            + service.getName()
-            + "/"
-            + operation.getName()
-            + "', $.toJSON(params), callbackMethod);\n");
+        JavascriptGenerator.javascript.append("  " + JavascriptGenerator.TUSCANY_COMET + ".callAsync('"
+                + service.getName() + "/" + operation.getName() + "', $.toJSON(params), callbackMethod);\n");
         JavascriptGenerator.javascript.append("}\n");
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java Tue May 31 10:46:24 2011
@@ -28,7 +28,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
 /**
- * Class serving the calls performed to retrieve the Javascript toolkit.
+ * Handles calls for the retrieving the Javascript toolkit.
  */
 @Path("/")
 @Produces("text/javascript")
@@ -49,15 +49,13 @@ public class JavascriptResource {
     @Path("/org.apache.tuscany.sca.CometComponentContext.js")
     public InputStream getJavascript() {
         InputStream stream = null;
-        // add dependencies in the specified order
-        for (final String dependency : JavascriptResource.DEPENDENCIES) {
+        for (String dependency : JavascriptResource.DEPENDENCIES) {
             if (stream == null) {
                 stream = this.getClass().getResourceAsStream(dependency);
             } else {
                 stream = new SequenceInputStream(stream, this.getClass().getResourceAsStream(dependency));
             }
         }
-        // add generated proxies
         final String generatedJs = JavascriptGenerator.getJavascript().toString() + "\n}";
         return new SequenceInputStream(stream, new ByteArrayInputStream(generatedJs.getBytes()));
     }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometEndpointManager.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometEndpointManager.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometEndpointManager.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometEndpointManager.java Tue May 31 10:46:24 2011
@@ -1,3 +1,21 @@
+/*
+ * 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.binding.comet.runtime.manager;
 
 import java.util.concurrent.ConcurrentHashMap;
@@ -5,26 +23,29 @@ import java.util.concurrent.ConcurrentMa
 
 import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
 
+/**
+ * Manager for Tuscany comet endpoints. This is a thread-safe singleton class.
+ */
 public class CometEndpointManager {
 
-	private static final ConcurrentMap<String, RuntimeEndpoint> endpoints = new ConcurrentHashMap<String, RuntimeEndpoint>();
+    private static final ConcurrentMap<String, RuntimeEndpoint> endpoints = new ConcurrentHashMap<String, RuntimeEndpoint>();
 
-	private CometEndpointManager() {
-	}
+    private CometEndpointManager() {
+    }
 
-	public static void add(String url, RuntimeEndpoint endpoint) {
-		endpoints.put(url, endpoint);
-	}
-
-	public static RuntimeEndpoint get(String url) {
-		return endpoints.get(url);
-	}
-
-	public static void remove(String url) {
-		endpoints.remove(url);
-	}
-
-	public static void clear() {
-		endpoints.clear();
-	}
+    public static void add(String url, RuntimeEndpoint endpoint) {
+        endpoints.put(url, endpoint);
+    }
+
+    public static RuntimeEndpoint get(String url) {
+        return endpoints.get(url);
+    }
+
+    public static void remove(String url) {
+        endpoints.remove(url);
+    }
+
+    public static void clear() {
+        endpoints.clear();
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometOperationManager.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometOperationManager.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometOperationManager.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometOperationManager.java Tue May 31 10:46:24 2011
@@ -1,3 +1,21 @@
+/*
+ * 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.binding.comet.runtime.manager;
 
 import java.util.concurrent.ConcurrentHashMap;
@@ -5,26 +23,29 @@ import java.util.concurrent.ConcurrentMa
 
 import org.apache.tuscany.sca.interfacedef.Operation;
 
+/**
+ * Manager for Tuscany comet operations. This is a thread-safe singleton class.
+ */
 public class CometOperationManager {
 
-	private static final ConcurrentMap<String, Operation> operations = new ConcurrentHashMap<String, Operation>();
+    private static final ConcurrentMap<String, Operation> operations = new ConcurrentHashMap<String, Operation>();
 
-	private CometOperationManager() {
-	}
+    private CometOperationManager() {
+    }
 
-	public static void add(String url, Operation operation) {
-		operations.put(url, operation);
-	}
-
-	public static Operation get(String url) {
-		return operations.get(url);
-	}
-
-	public static void remove(String url) {
-		operations.remove(url);
-	}
-
-	public static void clear() {
-		operations.clear();
-	}
+    public static void add(String url, Operation operation) {
+        operations.put(url, operation);
+    }
+
+    public static Operation get(String url) {
+        return operations.get(url);
+    }
+
+    public static void remove(String url) {
+        operations.remove(url);
+    }
+
+    public static void clear() {
+        operations.clear();
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometSessionManager.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometSessionManager.java?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometSessionManager.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/manager/CometSessionManager.java Tue May 31 10:46:24 2011
@@ -1,3 +1,21 @@
+/*
+ * 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.binding.comet.runtime.manager;
 
 import java.util.concurrent.ConcurrentHashMap;
@@ -5,6 +23,9 @@ import java.util.concurrent.ConcurrentMa
 
 import org.atmosphere.cpr.Broadcaster;
 
+/**
+ * Manager for Tuscany comet sessions. This is a thread-safe singleton class.
+ */
 public class CometSessionManager {
 
     private static final ConcurrentMap<String, Broadcaster> broadcasters = new ConcurrentHashMap<String, Broadcaster>();

Modified: tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js?rev=1129609&r1=1129608&r2=1129609&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js Tue May 31 10:46:24 2011
@@ -1,4 +1,18 @@
-
+/*
+ * jQuery JSON Plugin
+ * version: 2.1 (2009-08-14)
+ *
+ * This document is licensed as free software under the terms of the
+ * MIT License: http://www.opensource.org/licenses/mit-license.php
+ *
+ * Brantley Harris wrote this plugin. It is based somewhat on the JSON.org 
+ * website's http://www.json.org/json2.js, which proclaims:
+ * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
+ * I uphold.
+ *
+ * It is also influenced heavily by MochiKit's serializeJSON, which is 
+ * copyrighted 2005 by Bob Ippolito.
+ */
 (function($){$.toJSON=function(o)
 {if(typeof(JSON)=='object'&&JSON.stringify)
 return JSON.stringify(o);var type=typeof(o);if(o===null)