dev@grizzly.java.net

[cometd] Reviewing the changes

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 12 Dec 2007 15:33:08 +0100

Hi Shinq Wai,

inline comments. This is great works! Comments until the end of the message.

oleksiys_at_dev.java.net wrote:
> Author: oleksiys
> Date: 2007-12-11 17:36:12+0000
> New Revision: 661
>
> Added:
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectResponse.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectResponse.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeResponse.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectResponse.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeResponse.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeRequest.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeResponse.java
> Modified:
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java
> trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java
>
> Log:
> cometd updates provided by Shing-Wai Chan
>
> Changes:
> -------------
> * The diff for existing files are in cometd.diff.
> * The new files are in the jar file (see 3).
> 1. changes to compilance to Bayeux 1.0 Draft
> 2. change CometdServlet for double-checked locking issue
> 3. split the Request and Response objects
> 4. add validation
> 5. use enum in Verb
>
> Notes/issues:
> -------------------
> 1. the validation for supportedConnectionTypes is "not"
> done as the client side javascript does not send it now.
> Where do we get those javascript?

It is available at the dojotoolkit web site.


> This has been discussed in comet email alias, too.
> 2. In Disconnect/Reconnect, there is no connectionType
> in current spec. But this is used in VerbUtils.java.
> Since I do not know the history, I have added this
> extra fields to those objects temporary.

Those fields where mandatory before the 1.0 release...so they are left
over from previous version. I think we can safely removed them.

> If you want me to remove it, then please let me know.

+1

> 3. there is no split request/response for Ping/Status as
> it is not in spec. (There is only empty impl in handler in
> current code.)

OK I'm fine letting it like that right now as the spec might define them
  in the future.

>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandler.java 2007-12-11 17:36:12+0000
> @@ -38,13 +38,20 @@
>
> import com.sun.grizzly.comet.CometContext;
> import com.sun.grizzly.comet.CometEvent;
> -import com.sun.grizzly.cometd.bayeux.Connect;
> +import com.sun.grizzly.cometd.bayeux.ConnectRequest;
> +import com.sun.grizzly.cometd.bayeux.ConnectResponse;
> +import com.sun.grizzly.cometd.bayeux.Advice;
> import com.sun.grizzly.cometd.bayeux.Data;
> -import com.sun.grizzly.cometd.bayeux.Disconnect;
> -import com.sun.grizzly.cometd.bayeux.Handshake;
> -import com.sun.grizzly.cometd.bayeux.Reconnect;
> -import com.sun.grizzly.cometd.bayeux.Subscribe;
> -import com.sun.grizzly.cometd.bayeux.Unsubscribe;
> +import com.sun.grizzly.cometd.bayeux.DisconnectRequest;
> +import com.sun.grizzly.cometd.bayeux.DisconnectResponse;
> +import com.sun.grizzly.cometd.bayeux.HandshakeRequest;
> +import com.sun.grizzly.cometd.bayeux.HandshakeResponse;
> +import com.sun.grizzly.cometd.bayeux.ReconnectRequest;
> +import com.sun.grizzly.cometd.bayeux.ReconnectResponse;
> +import com.sun.grizzly.cometd.bayeux.SubscribeRequest;
> +import com.sun.grizzly.cometd.bayeux.SubscribeResponse;
> +import com.sun.grizzly.cometd.bayeux.UnsubscribeRequest;
> +import com.sun.grizzly.cometd.bayeux.UnsubscribeResponse;
> import com.sun.grizzly.cometd.bayeux.Verb;
> import java.io.IOException;
> import java.util.Random;
> @@ -81,21 +88,24 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Handshake handshake = (Handshake)cometdContext.getVerb();
> -
> - boolean handshakeOK = true;
> - String clientId = "";
> - synchronized(random){
> - clientId = String.valueOf(Long.toHexString(random.nextLong()));
> - }
> -
> - // XXX Why do we need to cache the ID. Memory leak right now
> - if (handshakeOK){
> - handshake.setClientId(clientId);
> + HandshakeRequest handshakeReq = (HandshakeRequest)cometdContext.getVerb();
> + HandshakeResponse handshakeRes = new HandshakeResponse(handshakeReq);

Here as an optimization we should recycle the HandshakeResponse and
cache instance inside a pool (instead of doing a new instance on every
requests). Pooling was missing before your change so I think we should
work on some simple caching mechanism to use all over cometd
implementation, to improve the performance under load. This apply to any
Verb Requests/Responses objects.


> + handshakeRes.setAdvice(new Advice());
> + if (handshakeReq.isValid()) {
> + String clientId = null;
> + synchronized(random){
> + clientId = String.valueOf(Long.toHexString(random.nextLong()));
> + }
> +
> + // XXX Why do we need to cache the ID. Memory leak right now
> + handshakeRes.setClientId(clientId);
> + } else {
> + handshakeRes.setSuccessful(false);
> + handshakeRes.setError("501::invalid handshake");
> }
>
> res.setContentType(DEFAULT_CONTENT_TYPE);
> - res.write(handshake.toJSON());
> + res.write(handshakeRes.toJSON());
> res.flush();
> }
>
> @@ -105,21 +115,26 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Connect connect = (Connect)cometdContext.getVerb();
> + ConnectRequest connectReq = (ConnectRequest)cometdContext.getVerb();
>
> - String subscribedChannel = activeChannels.get(connect.getClientId());
> + ConnectResponse connectRes = new ConnectResponse(connectReq);
> + connectRes.setAdvice(new Advice());
> + if (!connectReq.isValid()) {
> + connectRes.setError("501::invalid connect");
> + }
> + String subscribedChannel = activeChannels.get(connectReq.getClientId());

if the connectReq.isValid return null, does it automatically means the
subscribedChannel will be null?


> if (subscribedChannel != null){
> CometContext cometContext = event.getCometContext();
> DataHandler dataHandler = new DataHandler();
> dataHandler.attach(new Object[]{req,res});
> - dataHandler.setChannel(activeChannels.get(connect.getClientId()));
> - dataHandler.setClientId(connect.getClientId());
> - activeCometHandlers.put(connect.getClientId(),dataHandler);
> + dataHandler.setChannel(subscribedChannel);
> + dataHandler.setClientId(connectReq.getClientId());
> + activeCometHandlers.put(connectReq.getClientId(),dataHandler);
> event.getCometContext().addCometHandler(dataHandler);
> - connect.setAdvice(null);
> + connectRes.setAdvice(null);
> }
> String jsonMessage = (subscribedChannel != null ?
> - connect.toLongPolledJSON() : connect.toJSON());
> + connectRes.toLongPolledJSON() : connectRes.toJSON());
>
> res.setContentType(DEFAULT_CONTENT_TYPE);
> res.write(jsonMessage);
> @@ -132,9 +147,13 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Disconnect disconnect = (Disconnect)cometdContext.getVerb();
> + DisconnectRequest disconnectReq = (DisconnectRequest)cometdContext.getVerb();
> + DisconnectResponse disconnectRes = new DisconnectResponse(disconnectReq);
> + if (!disconnectReq.isValid()) {
> + disconnectRes.setError("501::invalid disonnect");
> + }
> DataHandler dataHandler =
> - activeCometHandlers.remove(disconnect.getClientId());
> + activeCometHandlers.remove(disconnectReq.getClientId());
>
> if (dataHandler != null){
> event.getCometContext().notify("disconnecting",
> @@ -142,7 +161,7 @@
> }
>
> res.setContentType(DEFAULT_CONTENT_TYPE);
> - res.write(disconnect.toJSON());
> + res.write(disconnectRes.toJSON());
> res.flush();
> }
>
> @@ -152,10 +171,14 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Reconnect reconnect = (Reconnect)cometdContext.getVerb();
> + ReconnectRequest reconnectReq = (ReconnectRequest)cometdContext.getVerb();
> + ReconnectResponse reconnectRes = new ReconnectResponse(reconnectReq);
> + if (!reconnectReq.isValid()) {
> + reconnectRes.setError("501::invalid reconnect");
> + }
>
> res.setContentType(DEFAULT_CONTENT_TYPE);
> - res.write(reconnect.toJSON());
> + res.write(reconnectRes.toJSON());
> res.flush();
> }
>
> @@ -165,15 +188,20 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Subscribe subscribe = (Subscribe)cometdContext.getVerb();
> - Data data = subscribe.getData();
> + SubscribeRequest subscribeReq = (SubscribeRequest)cometdContext.getVerb();
> + SubscribeResponse subscribeRes = new SubscribeResponse(subscribeReq);
> + if (!subscribeReq.isValid()) {
> + subscribeRes.setError("501::invalid subscribe");
> + }
> + Data data = subscribeReq.getData();
> if (data != null){
> - subscribe.setDataId(data.getId());
> - activeChannels.put(subscribe.getClientId(),data.getChannel());
> + subscribeRes.setData(data);
> + subscribeReq.setDataId(data.getId());
> + activeChannels.put(subscribeReq.getClientId(),data.getChannel());
> event.getCometContext().notify(data);
> }
> res.setContentType(DEFAULT_CONTENT_TYPE);
> - res.write(subscribe.toJSON());
> + res.write(subscribeRes.toJSON());
> res.flush();
> }
>
> @@ -183,15 +211,20 @@
>
> CometdRequest req = cometdContext.getRequest();
> CometdResponse res = cometdContext.getResponse();
> - Unsubscribe unsubscribe = (Unsubscribe)cometdContext.getVerb();
> - Data data = unsubscribe.getData();
> + UnsubscribeRequest unsubscribeReq = (UnsubscribeRequest)cometdContext.getVerb();
> + UnsubscribeResponse unsubscribeRes = new UnsubscribeResponse(unsubscribeReq);
> + if (!unsubscribeReq.isValid()) {
> + unsubscribeRes.setError("501::invalid unsubscribe");
> + }
> + Data data = unsubscribeReq.getData();
> if (data != null){
> - unsubscribe.setDataId(data.getId());
> - activeChannels.remove(unsubscribe.getClientId());
> + unsubscribeRes.setData(data);
> + unsubscribeRes.setDataId(data.getId());
> + activeChannels.remove(unsubscribeReq.getClientId());
> event.getCometContext().notify(data);
> }
> res.setContentType(DEFAULT_CONTENT_TYPE);
> - res.write(unsubscribe.toJSON());
> + res.write(unsubscribeRes.toJSON());
> res.flush();
> }
>
> @@ -258,4 +291,4 @@
> // Not supported
> }
>
> -}
> \ No newline at end of file
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/BayeuxCometHandlerBase.java 2007-12-11 17:36:12+0000
> @@ -37,7 +37,8 @@
> package com.sun.grizzly.cometd;
>
> import com.sun.grizzly.comet.CometEvent;
> -import com.sun.grizzly.cometd.bayeux.Verb;
> +import com.sun.grizzly.cometd.bayeux.Verb.Type;
> +import com.sun.grizzly.cometd.bayeux.Verb.Type.*;
> import java.io.IOException;
>
> /**
> @@ -53,27 +54,39 @@
>
> Object object = event.attachment();
> if (object instanceof CometdContext){
> - Verb verb = ((CometdContext)object).getVerb();
> + Type type = ((CometdContext)object).getVerb().getType();
>
> - if (verb.getType() == Verb.HANDSHAKE){
> - onHandshake(event);
> - } else if (verb.getType() == Verb.CONNECT){
> - onConnect(event);
> - } else if (verb.getType() == Verb.DISCONNECT){
> - onDisconnect(event);
> - } else if (verb.getType() == Verb.RECONNECT){
> - onReconnect(event);
> - } else if (verb.getType() == Verb.SUBSCRIBE){
> - onSubscribe(event);
> - } else if (verb.getType() == Verb.UNSUBSCRIBE){
> - onUnsubscribe(event);
> - } else if (verb.getType() == Verb.DATA){
> - onData(event);
> - } else if (verb.getType() == Verb.PING){
> - onPing(event);
> - } else if (verb.getType() == Verb.STATUS){
> - onStatus(event);
> - }
> + switch(type) {
> + case HANDSHAKE:
> + onHandshake(event);
> + break;
> + case CONNECT:
> + onConnect(event);
> + break;
> + case DISCONNECT:
> + onDisconnect(event);
> + break;
> + case RECONNECT:
> + onReconnect(event);
> + break;
> + case SUBSCRIBE:
> + onSubscribe(event);
> + break;
> + case UNSUBSCRIBE:
> + onUnsubscribe(event);
> + break;
> + case DATA:
> + onData(event);
> + break;
> + case PING:
> + onPing(event);
> + break;
> + case STATUS:
> + onStatus(event);
> + break;
> + default:
> + break;
> + }
> }
> }
>
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Advice.java 2007-12-11 17:36:12+0000
> @@ -54,18 +54,24 @@
> */
> public class Advice extends VerbBase{
>
> - // "none", "retry", "handshake", "recover"
> + // "none", "retry", "handshake", "recover" (deprecated)
> private String reconnect = "retry";
>
>
> private Integer interval = 0;
> +
> +
> + private Boolean multipleClients = Boolean.FALSE;
> +
> +
> + private String[] hosts = null;
>
> -
> +
> private String transport = "\"long-polling\":\t{\n";
>
>
> public Advice() {
> - type = Verb.ADVISE;
> + type = Verb.Type.ADVICE;
> }
>
> public String getReconnect() {
> @@ -83,15 +89,52 @@
> public void setInterval(Integer interval) {
> this.interval = interval;
> }
> +
> + public Boolean getMultipleClients() {
> + return multipleClients;
> + }
> +
> + public void setMultipleClients(Boolean multipleClients) {
> + this.multipleClients = multipleClients;
> + }
> +
> + public String[] getHosts() {
> + return hosts;
> + }
> +
> + public void setHosts(String[] hosts) {
> + this.hosts = hosts;
> + }
>
> public String toString(){
> return toJSON();
> }
>
> public String toJSON() {
> - return "\"advice\":{"
> + StringBuilder jsonSb = new StringBuilder(
> + "\"advice\":{"
> + "\"reconnect\":\"" + reconnect + "\","
> - + "\"interval\":" + interval + "}";
> + + "\"interval\":" + interval + ","
> + + "\"multiple-clients\":" + multipleClients
> + );
> +
> + if (hosts != null && hosts.length > 0) {
> + jsonSb.append("\"hosts\":[");
> + boolean first = true;
> + for (String host : hosts) {
> + if (first) {
> + first = false;
> + } else {
> + jsonSb.append(",");
> + }
> +
> + jsonSb.append("\"" + host + "\"");
> + }
> + jsonSb.append("]");
> + }
> +
> + jsonSb.append("}");
> + return jsonSb.toString();
> }
>
> public String getTransport() {
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Connect.java 2007-12-11 17:36:12+0000
> @@ -135,7 +135,7 @@
> *
> * @author Jeanfrancois Arcand
> */
> -public class Connect extends VerbBase{
> +abstract class Connect extends VerbBase{
>
> public final static String HTML_HEADER =
> "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" +
> @@ -155,17 +155,16 @@
>
>
>
> - public final static String META_CONNECTIONS="/meta/connections/";
> -
> + public final static String META_CONNECT ="/meta/connect";
> +
>
> protected String clientId;
> -
> +
> protected String connectionType;
>
> - protected String timestamp = FastHttpDateFormat.getCurrentDate();
>
> public Connect() {
> - type = Verb.CONNECT;
> + type = Verb.Type.CONNECT;
> }
>
> public String getClientId() {
> @@ -176,34 +175,14 @@
> this.clientId = clientId;
> }
>
> - public String getConnectionType() {
> - return connectionType;
> + public boolean isValid() {
> + return (clientId != null && getMetaChannel().equals(getChannel()));
> }
>
> - public void setConnectionType(String connectionType) {
> - this.connectionType = connectionType;
> - }
> -
> -
> - public String toJSON() {
> - String adviseString = (advice == null ? "" : advice.toJSON() + ",");
> - return getBody()
> - + "}]*/\n" ;
> + /**
> + * To be overriden by subclass used in isValid().
> + */
> + protected String getMetaChannel() {
> + return META_CONNECT;
> }
> -
> - private String getBody(){
> - String adviseString = (advice == null ? "" : advice.toJSON() + ",");
> - return "/*[{"
> - + "\"channel\":\"" + channel + "\","
> - + "\"successful\":" + successful + ","
> - + "\"timestamp\":\"" + FastHttpDateFormat.getCurrentDate() + "\","
> - + adviseString
> - + "\"id\":\"" + id + "\"";
> - }
> -
> -
> - public String toLongPolledJSON(){
> - return getBody() + "}";
> - }
> -
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,77 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class ConnectRequest extends Connect {
> +
> + public ConnectRequest() {
> + super();
> + }
> +
> + public String getConnectionType() {
> + return connectionType;
> + }
> +
> + public void setConnectionType(String connectionType) {
> + this.connectionType = connectionType;
> + }
> +
> + public boolean isValid() {
> + return (connectionType != null && super.isValid());
> + }
> +
> + public String toJSON() {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"clientId\":\"" + clientId + "\""
> + + ",\"connectionType\":\"" + connectionType + "\""
> + );
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> + sb.append("}]*/\n");
> + return sb.toString();
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ConnectResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,104 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +import com.sun.grizzly.util.http.FastHttpDateFormat;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class ConnectResponse extends Connect {
> +
> + public ConnectResponse() {
> + super();
> + }
> +
> + public ConnectResponse(ConnectRequest req) {
> + super();
> + channel = req.getChannel();
> + clientId = req.getClientId();
> + id = req.getId();
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +
> + public String toJSON() {
> + return getBody().append("}]*/\n").toString();
> + }
> +
> + public String toLongPolledJSON() {
> + return getBody().append("}").toString();
> + }
> +
> + private StringBuilder getBody() {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"clientId\":\"" + clientId + "\""
> + + ",\"successful\":" + successful
> + );
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> + if (error != null) {
> + sb.append(",\"error\":\"" + error + "\"");
> + }
> + if (advice != null) {
> + sb.append("," + advice.toJSON());
> + }
> + sb.append(",\"timestamp\":\"" + FastHttpDateFormat.getCurrentDate() + "\"");
> + return sb;
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Data.java 2007-12-11 17:36:12+0000
> @@ -87,7 +87,7 @@
> private String timestamp;
>
> public Data() {
> - type = Verb.DATA;
> + type = Verb.Type.DATA;
> }
>
> public String toData() {
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Disconnect.java 2007-12-11 17:36:12+0000
> @@ -36,26 +36,19 @@
>
> package com.sun.grizzly.cometd.bayeux;
>
> -import com.sun.grizzly.util.http.FastHttpDateFormat;
> -
> /**
> - * Reserved Verb not yet defined.
> *
> * @author Jeanfrancois Arcand
> */
> -public class Disconnect extends Connect{
> -
> +abstract class Disconnect extends Connect {
> +
> + public final static String META_DISCONNECT ="/meta/disconnect";
> +
> public Disconnect() {
> - type = Verb.DISCONNECT;
> + type = Verb.Type.DISCONNECT;
> }
> -
> -
> - public String toJSON() {
> - return "/*[{"
> - + "\"id\":\"" + id + "\","
> - + "\"timestamp\":\"" + FastHttpDateFormat.getCurrentDate() + "\","
> - + "\"successful\":" + successful + ","
> - + "\"channel\":\"" + channel + "\""
> - + "}]*/\n" ;
> +
> + protected String getMetaChannel() {
> + return META_DISCONNECT;
> }
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,72 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class DisconnectRequest extends Disconnect {
> +
> + public DisconnectRequest() {
> + super();
> + }
> +
> + public String getConnectionType() {
> + return connectionType;
> + }
> +
> + public void setConnectionType(String connectionType) {
> + this.connectionType = connectionType;
> + }
> +
> + public String toJSON() {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"clientId\":\"" + clientId + "\""
> + );
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> + sb.append("}]*/\n");
> + return sb.toString();
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/DisconnectResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,92 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively
> + * The contents of this file are subject to the te, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class DisconnectResponse extends Disconnect {
> +
> + public DisconnectResponse() {
> + super();
> + }
> +
> + public DisconnectResponse(DisconnectRequest req) {
> + super();
> + channel = req.getChannel();
> + clientId = req.getClientId();
> + id = req.getId();
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +
> + public String toJSON() {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"clientId\":\"" + clientId + "\""
> + + ",\"successful\":\"" + successful + "\""
> + );
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> + if (error != null) {
> + sb.append(",\"error\":\"" + error + "\"");
> + }
> + sb.append("}]*/\n");
> + return sb.toString();
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ext.java 2007-12-11 17:36:12+0000
> @@ -36,6 +36,7 @@
> private Map<String,Object> extensionMap;
>
> public Ext() {
> + type = Verb.Type.EXT;
> }
>
>
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Handshake.java 2007-12-11 17:36:12+0000
> @@ -101,27 +101,26 @@
> *
> * @author Jeanfrancois Arcand
> */
> -public class Handshake extends VerbBase{
> +abstract class Handshake extends VerbBase{
> + public static final String META_HANDSHAKE = "/meta/handshake";
>
> private String version = "1.0";
>
> private String minimumVersion = "0.9";
>
> - private String supportedConnectionTypes
> - = "[\"long-polling\",\"callback-polling\"]";
> + private String[] supportedConnectionTypes
> + = new String[] {"long-polling", "callback-polling"};
>
> private String authScheme="";
>
> private String authUser="";
> -
> - private String clientId;
> -
> - private Boolean authSuccessful = Boolean.TRUE;
>
> - private boolean successfull = true;
> + protected String clientId = null;
>
> - public Handshake() {
> - type = Verb.HANDSHAKE;
> + protected Boolean authSuccessful = Boolean.TRUE;
> +
> + protected Handshake() {
> + type = Verb.Type.HANDSHAKE;
> }
>
> public String getVersion() {
> @@ -140,11 +139,11 @@
> this.minimumVersion = minimumVersion;
> }
>
> - public String getSupportedConnectionTypes() {
> + public String[] getSupportedConnectionTypes() {
> return supportedConnectionTypes;
> }
>
> - public void setSupportedConnectionTypes(String supportedConnectionTypes) {
> + public void setSupportedConnectionTypes(String[] supportedConnectionTypes) {
> this.supportedConnectionTypes = supportedConnectionTypes;
> }
>
> @@ -164,43 +163,106 @@
> this.authUser = authUser;
> }
>
> - public String getClientId() {
> - return clientId;
> - }
> + public boolean isValid() {
> + float ver;
>
> - public void setClientId(String clientId) {
> - this.clientId = clientId;
> - }
> + try {
> + ver = Float.parseFloat(getVersion());
> + } catch(Exception ex) {
> + return false;
> + }
> +
> + //XXX need to check supportedConnectionTypes later
> +
> + return (ver <= 1.0) && (ver >= 0.9) &&
> + META_HANDSHAKE.equals(getChannel());
> + }
> +
> + protected String toJSON(boolean isResponse) {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"version\":\"" + version + "\""
> + );
> + if (supportedConnectionTypes != null) {
> + sb.append(",\"supportedConnectionTypes\":[");
> + boolean first = true;
> + for (String connType : supportedConnectionTypes) {
> + if (!first) {
> + sb.append(",");
> + } else {
> + first = false;
> + }
> + sb.append("\"" + connType + "\"");
> + }
> + sb.append("]");
> + }
> +
> + if (minimumVersion != null) {
> + sb.append(",\"minimumVersion\":\"" + minimumVersion + "\"");
> + }
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> +
> + if (isResponse) {
> + sb.append(",\"clientId\":\"" + clientId + "\"");
> + sb.append(",\"successful\":" + successful);
> + if (advice != null) {
> + sb.append("," + advice.toJSON());
> + }
> + if (authSuccessful != null) {
> + sb.append(",\"authSuccessful\":" + authSuccessful);
> + }
> + }
>
> - public Boolean getAuthSuccessful() {
> - return authSuccessful;
> - }
> + sb.append("}]*/\n");
> + return sb.toString();
> + }
>
> - public void setAuthSuccessful(Boolean authSuccessful) {
> - this.authSuccessful = authSuccessful;
> - }
> + protected String toErrorResponseJSON() {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + + ",\"successful\":" + successful
> + + ",\"error\":\"" + error + "\""
> + );
> +
> + if (version != null) {
> + sb.append(",\"version\":\"" + version + "\"");
> + }
> + if (supportedConnectionTypes != null) {
> + sb.append(",\"supportedConnectionTypes\":[");
> + boolean first = true;
> + for (String connType : supportedConnectionTypes) {
> + if (!first) {
> + sb.append(",");
> + } else {
> + first = false;
> + }
> + sb.append("\"" + connType + "\"");
> + }
> + sb.append("]");
> + }
> +
> + if (minimumVersion != null) {
> + sb.append(",\"minimumVersion\":\"" + minimumVersion + "\"");
> + }
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> +
> + if (authSuccessful != null) {
> + sb.append(",\"authSuccessful\":" + authSuccessful);
> + }
>
> -
> - public String toString(){
> - return toJSON();
> + sb.append("}]*/\n");
> + return sb.toString();
> }
> -
> - public String toJSON() {
> - String extension = "";
> - if (ext != null){
> - extension = ext.toJSON();
> - }
> - return "/*[{"
> - + "\"id\":\"" + id + "\","
> - + "\"minimumVersion\":" + minimumVersion + ","
> - + "\"supportedConnectionTypes\":" + supportedConnectionTypes + ","
> - + "\"successful\":" + successful + ","
> - + advice.toJSON() + ","
> - + "\"channel\":\"" + channel + "\","
> - + "\"clientId\":\"" + clientId + "\","
> - + extension + ","
> - + "\"version\":" + version
> - + "}]*/\n";
> - }
> -
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,56 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Headerthe Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +import java.io.IOException;
> +
> +import com.sun.grizzly.cometd.CometdContext;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +
> +public class HandshakeRequest extends Handshake {
> + public HandshakeRequest() {
> + super();
> + }
> +
> + public String toJSON() {
> + return toJSON(false);
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/HandshakeResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,99 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Headerthe Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +import java.io.IOException;
> +
> +import com.sun.grizzly.cometd.CometdContext;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +
> +public class HandshakeResponse extends Handshake {
> +
> + public HandshakeResponse() {
> + super();
> + }
> +
> + public HandshakeResponse(HandshakeRequest req) {
> + super();
> + channel = req.getChannel();
> + id = req.getId();
> + }
> +
> + public String getClientId() {
> + return clientId;
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +
> + public void setClientId(String clientId) {
> + this.clientId = clientId;
> + }
> +
> + public Boolean getAuthSuccessful() {
> + return authSuccessful;
> + }
> +
> + public void setAuthSuccessful(Boolean authSuccessful) {
> + this.authSuccessful = authSuccessful;
> + }
> +
> + public boolean isValid() {
> + return (clientId != null || error != null) && super.isValid();
> + }
> +
> + public String toJSON() {
> + return (error != null) ? toErrorResponseJSON() : toJSON(true);
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Ping.java 2007-12-11 17:36:12+0000
> @@ -44,7 +44,7 @@
> public class Ping extends VerbBase{
>
> public Ping() {
> - type = Verb.PING;
> + type = Verb.Type.PING;
> }
>
> public String toJSON() {
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Reconnect.java 2007-12-11 17:36:12+0000
> @@ -91,22 +91,14 @@
> * ]
> * @author Jeanfrancois Arcand
> */
> -public class Reconnect extends Connect{
> +abstract class Reconnect extends Connect{
>
> - private Advice advise;
> -
> - public Reconnect() {
> - type = Verb.RECONNECT;
> - }
> + public final static String META_RECONNECT ="/meta/reconnect";
>
> - public Advice getAdvise() {
> - return advise;
> + public Reconnect() {
> + type = Verb.Type.RECONNECT;
> }
>
> - public void setAdvise(Advice advise) {
> - this.advise = advise;
> - }
> -
> public String toJSON() {
> return "/*[{"
> + "\"timestamp\":\"" + FastHttpDateFormat.getCurrentDate() + "\","
> @@ -115,4 +107,8 @@
> + "\"channel\":\"" + channel + "\""
> + "}]*/\n" ;
> }
> +
> + protected String getMetaChannel() {
> + return META_RECONNECT;
> + }
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,58 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +import com.sun.grizzly.util.http.FastHttpDateFormat;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class ReconnectRequest extends Reconnect {
> +
> + public ReconnectRequest() {
> + type = Verb.Type.RECONNECT;
> + }
> +
> + public String getConnectionType() {
> + return connectionType;
> + }
> +
> + public void setConnectionType(String connectionType) {
> + this.connectionType = connectionType;
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/ReconnectResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,71 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class ReconnectResponse extends Reconnect {
> +
> + public ReconnectResponse() {
> + super();
> + }
> +
> + public ReconnectResponse(ReconnectRequest req) {
> + super();
> + channel = req.getChannel();
> + clientId = req.getClientId();
> + id = req.getId();
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Status.java 2007-12-11 17:36:12+0000
> @@ -44,7 +44,7 @@
> public class Status extends VerbBase {
>
> public Status() {
> - type = Verb.STATUS;
> + type = Verb.Type.STATUS;
> }
>
> public String toJSON() {
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Subscribe.java 2007-12-11 17:36:12+0000
> @@ -83,18 +83,15 @@
> * ]
> * @author Jeanfrancois Arcand
> */
> -public class Subscribe extends VerbBase{
> +abstract class Subscribe extends VerbBase{
> + public static final String META_SUBSCRIBE = "/meta/subscribe";
>
> protected String subscription;
>
> - protected Advice advise;
> -
> protected String clientId;
>
> - protected String error = "";
> -
> public Subscribe() {
> - type = Verb.SUBSCRIBE;
> + type = Verb.Type.SUBSCRIBE;
> }
>
> public String getSubscription() {
> @@ -105,30 +102,6 @@
> this.subscription = subscription;
> }
>
> -
> - public String toJSON() {
> - String timeStamp = FastHttpDateFormat.getCurrentDate();
> - return "/*[{"
> - + "\"id\":\"" + id + "\","
> - + "\"subscription\":\"" + subscription + "\","
> - + "\"successful\":" + successful + ","
> - + "\"channel\":\"" + channel + "\"},{"
> - + "\"successful\":" + successful + ","
> - + "\"channel\":\"" + subscription + "\","
> - + "\"timestamp\":\"" + timeStamp + "\","
> - + "\"id\":\"" + dataId + "\"},"
> - + data.toData()
> - + "]*/";
> - }
> -
> - public Advice getAdvise() {
> - return advise;
> - }
> -
> - public void setAdvise(Advice advise) {
> - this.advise = advise;
> - }
> -
> public String getClientId() {
> return clientId;
> }
> @@ -137,12 +110,49 @@
> this.clientId = clientId;
> }
>
> - public String getError() {
> - return error;
> + public boolean isValid() {
> + return (clientId != null && subscription != null &&
> + getMetaChannel().equals(getChannel()));
> + }
> +
> + protected String getMetaChannel() {
> + return META_SUBSCRIBE;
> + }
> +
> + /**
> + * @param isResponse
> + * @param printTimestamp for UnsubscribeResponse
> + */
> + protected String getBody(boolean isResponse, boolean printTimestamp) {
> + StringBuilder sb = new StringBuilder(
> + "/*[{"
> + + "\"channel\":\"" + channel + "\""
> + );
> + if (isResponse) {
> + sb.append(",\"successful\":" + successful);
> + }
> + sb.append(",\"clientId\":\"" + clientId + "\"");
> + sb.append(",\"subscription\":\"" + subscription + "\"");
> + if (isResponse && error != null) {
> + sb.append(",\"error\":\"" + error + "\"");
> + }
> + if (isResponse && advice != null) {
> + sb.append("," + advice.toJSON());
> + }
> + if (ext != null) {
> + sb.append("," + ext.toJSON());
> + }
> + if (id != null) {
> + sb.append(",\"id\":\"" + id + "\"");
> + }
> + if (printTimestamp) {
> + sb.append(",\"timestamp\":\"" + FastHttpDateFormat.getCurrentDate() + "\"");
> + }
> + sb.append("}");
> + if (data != null) {
> + sb.append("," + data.toData());
> + }
> + sb.append("]*/\n");
> + return sb.toString();
> }
> -
> - public void setError(String error) {
> - this.error = error;
> - }
> -
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,52 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class SubscribeRequest extends Subscribe {
> +
> + public SubscribeRequest() {
> + super();
> + }
> +
> + public String toJSON() {
> + return getBody(false, false);
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/SubscribeResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,76 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class SubscribeResponse extends Subscribe {
> +
> + public SubscribeResponse() {
> + super();
> + }
> +
> + public SubscribeResponse(SubscribeRequest req) {
> + super();
> + channel = req.getChannel();
> + subscription = req.getSubscription();
> + clientId = req.getClientId();
> + id = req.getId();
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +
> + public String toJSON() {
> + return getBody(true, false);
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Unsubscribe.java 2007-12-11 17:36:12+0000
> @@ -79,22 +79,14 @@
> *
> * @author Jeanfrancois Arcand
> */
> -public class Unsubscribe extends Subscribe{
> +abstract class Unsubscribe extends Subscribe {
> + public static final String META_UNSUBSCRIBE = "/meta/unsubscribe";
>
> public Unsubscribe() {
> - type = Verb.UNSUBSCRIBE;
> + type = Verb.Type.UNSUBSCRIBE;
> }
>
> - public String toJSON() {
> - String timeStamp = FastHttpDateFormat.getCurrentDate();
> - return "/*[{"
> - + "\"id\":\"" + id + "\","
> - + "\"subscription\":\"" + subscription + "\","
> - + "\"successful\":" + successful + ","
> - + "\"channel\":\"" + channel + "\"},{"
> - + "\"successful\":" + successful + ","
> - + "\"channel\":\"" + subscription + "\","
> - + "\"timestamp\":\"" + timeStamp + "\","
> - + "\"id\":\"" + dataId + "\"}]*/";
> - }
> + protected String getMetaChannel() {
> + return META_UNSUBSCRIBE;
> + }
> }
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeRequest.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeRequest.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeRequest.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,90 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * Bayeux Unsubscribe implementation.
> + * See http://svn.xantus.org/shortbus/trunk/bayeux/protocol.txt for the technical
> + * details.
> + *
> + * // unsubscription for same:
> + *
> + * //-----------------
> + * // CLIENT -> SERVER
> + * //-----------------
> + *
> + * [
> + * {
> + * "channel": "/meta/unsubscribe",
> + * "subscription": "/some/other/channel",
> + * // optional
> + * "authToken": "SOME_NONCE_PREVIOUSLY_PROVIDED_BY_SERVER"
> + * }
> + * // , ...
> + * ]
> + *
> + * // and the server response:
> + *
> + * //-----------------
> + * // SERVER -> CLIENT
> + * //-----------------
> + *
> + * [
> + * {
> + * "channel": "/meta/unsubscribe",
> + * "subscription": "/some/other/channel",
> + * "successful": true,
> + * "clientId": "SOME_UNIQUE_CLIENT_ID",
> + * "error": "",
> + * // optional
> + * "authToken": "SOME_NONCE"
> + * }
> + * // , ...
> + * ]
> + *
> + * @author Jeanfrancois Arcand
> + */
> +public class UnsubscribeRequest extends Unsubscribe {
> +
> + public UnsubscribeRequest() {
> + super();
> + }
> +
> + public String toJSON() {
> + return getBody(false, false);
> + }
> +}
>
> Added: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeResponse.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeResponse.java?view=auto&rev=661
> ==============================================================================
> --- (empty file)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/UnsubscribeResponse.java 2007-12-11 17:36:12+0000
> @@ -0,0 +1,76 @@
> +/*
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
> + *
> + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
> + *
> + * The contents of this file are subject to the terms of either the GNU
> + * General Public License Version 2 only ("GPL") or the Common Development
> + * and Distribution License("CDDL") (collectively, the "License"). You
> + * may not use this file except in compliance with the License. You can obtain
> + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
> + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
> + * language governing permissions and limitations under the License.
> + *
> + * When distributing the software, include this License Header Notice in each
> + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
> + * Sun designates this particular file as subject to the "Classpath" exception
> + * as provided by Sun in the GPL Version 2 section of the License file that
> + * accompanied this code. If applicable, add the following below the License
> + * Header, with the fields enclosed by brackets [] replaced by your own
> + * identifying information: "Portions Copyrighted [year]
> + * [name of copyright owner]"
> + *
> + * Contributor(s):
> + *
> + * If you wish your version of this file to be governed by only the CDDL or
> + * only the GPL Version 2, indicate your decision by adding "[Contributor]
> + * elects to include this software in this distribution under the [CDDL or GPL
> + * Version 2] license." If you don't indicate a single choice of license, a
> + * recipient has the option to distribute your version of this file under
> + * either the CDDL, the GPL Version 2 or to extend the choice of license to
> + * its licensees as provided above. However, if you add GPL Version 2 code
> + * and therefore, elected the GPL Version 2 license, then the option applies
> + * only if the new code is made subject to such option by the copyright
> + * holder.
> + */
> +
> +package com.sun.grizzly.cometd.bayeux;
> +
> +/**
> + * @author Jeanfrancois Arcand
> + * @author Shing Wai Chan
> + */
> +public class UnsubscribeResponse extends Unsubscribe {
> +
> + public UnsubscribeResponse() {
> + super();
> + }
> +
> + public UnsubscribeResponse(UnsubscribeRequest req) {
> + super();
> + channel = req.getChannel();
> + subscription = req.getSubscription();
> + clientId = req.getClientId();
> + id = req.getId();
> + }
> +
> + public Boolean getSuccessful() {
> + return successful;
> + }
> +
> + public void setSuccessful(Boolean successful) {
> + this.successful = successful;
> + }
> +
> + public String getError() {
> + return error;
> + }
> +
> + public void setError(String error) {
> + this.error = error;
> + }
> +
> + public String toJSON() {
> + return getBody(false, true);
> + }
> +}
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/Verb.java 2007-12-11 17:36:12+0000
> @@ -51,18 +51,22 @@
> * @author Jeanfrancois Arcand
> */
> public interface Verb {
> -
> - //XXX Use enum
> - public static int HANDSHAKE = 0;
> - public static int CONNECT = 1;
> - public static int DISCONNECT = 2;
> - public static int RECONNECT = 3;
> - public static int SUBSCRIBE = 4;
> - public static int UNSUBSCRIBE = 5;
> - public static int STATUS = 6;
> - public static int PING = 7;
> - public static int DATA = 8;
> - public static int ADVISE = 9;
> +
> + public static enum Type {
> + HANDSHAKE,
> + CONNECT,
> + DISCONNECT,
> + RECONNECT, // deprecated
> + SUBSCRIBE,
> + UNSUBSCRIBE,
> + STATUS, // deprecated
> + PING, // deprecated
> +
> + // the following are fields, not channels
> + DATA,
> + ADVICE,
> + EXT
> + }


Here I didn't used enum because I've read in more than one place than
the performance was bad. We probably needs to measure it by yourself.


>
>
> /**
> @@ -74,5 +78,11 @@
> /**
> * Return the Verb's type.
> */
> - public int getType();
> + public Type getType();
> +
> +
> + /**
> + * Check whether the Verb is valid.
> + */
> + public boolean isValid();
> }
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbBase.java 2007-12-11 17:36:12+0000
> @@ -57,17 +57,15 @@
> protected String channel;
>
> protected Data data;
> -
> - protected int type;
> -
> -
> +
> + protected Type type;
> +
> protected String authToken;
>
> -
> protected Boolean successful = Boolean.TRUE;
>
>
> - protected String error ="";
> + protected String error = null;
>
>
> protected Ext ext;
> @@ -96,12 +94,12 @@
> this.authToken = autheToken;
> }
>
> -
> - public int getType(){
> +
> + public Type getType() {
> return type;
> - }
> -
> + }
>
> +
> public Ext getExt() {
> return ext;
> }
> @@ -149,4 +147,8 @@
> public void setDataId(String dataId) {
> this.dataId = dataId;
> }
> +
> + public boolean isValid() {
> + return true;
> + }
> }
>
> Modified: trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java
> Url: https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java?view=diff&rev=661&p1=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java&p2=trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java&r1=660&r2=661
> ==============================================================================
> --- trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java (original)
> +++ trunk/modules/cometd/src/main/java/com/sun/grizzly/cometd/bayeux/VerbUtils.java 2007-12-11 17:36:12+0000
> @@ -46,13 +46,12 @@
> */
> public class VerbUtils {
>
> - private final static String META = "/meta";
> - private final static String HANDSHAKE = "/handshake";
> - private final static String CONNECT = "/connect";
> - private final static String DISCONNECT = "/disconnect";
> - private final static String RECONNECT = "/reconnect";
> - private final static String SUBSCRIBE = "/subscribe";
> - private final static String UNSUBSCRIBE = "/unsubscribe";
> + private final static String HANDSHAKE = Handshake.META_HANDSHAKE;
> + private final static String CONNECT = Connect.META_CONNECT;
> + private final static String DISCONNECT = Disconnect.META_DISCONNECT;
> + private final static String RECONNECT = Reconnect.META_RECONNECT;
> + private final static String SUBSCRIBE = Subscribe.META_SUBSCRIBE;
> + private final static String UNSUBSCRIBE = Unsubscribe.META_UNSUBSCRIBE;
> private final static String STATUS = "/status";
> private final static String PING = "/ping";
> private final static String DATA = "data";
> @@ -116,8 +115,8 @@
> }
>
>
> - private final static Handshake newHandshake(Map map){
> - Handshake handshake = new Handshake();
> + private final static HandshakeRequest newHandshake(Map map){
> + HandshakeRequest handshake = new HandshakeRequest();
>
> handshake.setAuthScheme((String)map.get("authScheme"));
> handshake.setAuthUser((String)map.get("authUser"));
> @@ -126,14 +125,15 @@
> handshake.setVersion((String)map.get("version"));
> handshake.setMinimumVersion((String)map.get("minimumVersion"));
> handshake.setId((String)map.get("id"));
> + handshake.setSupportedConnectionTypes((String[])map.get("supportedConnectionTypes"));
> handshake.setAdvice(new Advice());
>
> return handshake;
> }
>
>
> - private final static Connect newConnect(Map map){
> - Connect connect = new Connect();
> + private final static ConnectRequest newConnect(Map map){
> + ConnectRequest connect = new ConnectRequest();
>
> connect.setAuthToken((String)map.get("authToken"));
> connect.setChannel((String)map.get("channel"));
> @@ -146,8 +146,8 @@
> }
>
>
> - private final static Disconnect newDisconnect(Map map){
> - Disconnect disconnect = new Disconnect();
> + private final static DisconnectRequest newDisconnect(Map map){
> + DisconnectRequest disconnect = new DisconnectRequest();
>
> disconnect.setAuthToken((String)map.get("authToken"));
> disconnect.setChannel((String)map.get("channel"));
> @@ -159,8 +159,8 @@
> }
>
>
> - private final static Reconnect newReconnect(Map map){
> - Reconnect reconnect = new Reconnect();
> + private final static ReconnectRequest newReconnect(Map map){
> + ReconnectRequest reconnect = new ReconnectRequest();
>
> reconnect.setAuthToken((String)map.get("authToken"));
> reconnect.setChannel((String)map.get("channel"));
> @@ -184,8 +184,8 @@
> }
>
>
> - private final static Subscribe newSubscribe(Map map){
> - Subscribe subscribe = new Subscribe();
> + private final static SubscribeRequest newSubscribe(Map map){
> + SubscribeRequest subscribe = new SubscribeRequest();
>
> subscribe.setChannel((String)map.get("channel"));
> subscribe.setAuthToken((String)map.get("authToken"));
> @@ -197,8 +197,8 @@
> }
>
>
> - private final static Unsubscribe newUnsubscribe(Map map){
> - Unsubscribe unsubscribe = new Unsubscribe();
> + private final static UnsubscribeRequest newUnsubscribe(Map map){
> + UnsubscribeRequest unsubscribe = new UnsubscribeRequest();
>
> unsubscribe.setChannel((String)map.get("channel"));
> unsubscribe.setAuthToken((String)map.get("authToken"));

Great works! Next thing we need to improve (from my original code) is
the CometdNotificationhandler:

> if (o instanceof Data){
> activeChannel = ((Data)o).getChannel();
> } else if (o instanceof DataHandler){
> activeChannel = ((DataHandler)o).getChannel();
> }
> while(iteratorHandlers.hasNext()){
> try{
> handler = (CometHandler)iteratorHandlers.next();
>
> if (handler instanceof CometdHandler){
> channel = ((CometdHandler)handler).getChannel();
> } else if (handler instanceof DataHandler){
> channel = ((DataHandler)handler).getChannel();
> }
>
> if (channel != null
> && channel.equals(BayeuxCometHandler.BAYEUX_COMET_HANDLER)
> || channel.equalsIgnoreCase(activeChannel)){
> notify0(cometEvent,handler);
> } else if (channel == null){
> CometEngine.logger().log(Level.WARNING,"Channel was null");
> }
> } catch (Throwable ex){
> if (exceptions == null){
> exceptions = new ArrayList<Throwable>();
> }
> exceptions.add(ex);
> }
> }

I really don't like calling instanceof and also calling this condition
when executing a push:

> if (channel != null
> && channel.equals(BayeuxCometHandler.BAYEUX_COMET_HANDLER)
> || channel.equalsIgnoreCase(activeChannel)){
> notify0(cometEvent,handler);

This is a performance killer I'm sure. If you have some ideas about how
to improve it, feel free :-) It's on my todo list, but seems the list is
growing instead of shrinking.....

Thanks!

-- Jeanfrancois




-- Jeanfrancois




>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commits-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: commits-help_at_grizzly.dev.java.net
>