Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2009 Mort Bay Consulting Pty. Ltd.
 // ------------------------------------------------------------------------
 // Licensed 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 
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package org.cometd.client.ext;

This client-side extension enables the client to acknowledge to the server the messages that the client has received. For the acknowledgement to work, the server must be configured with the correspondent server-side ack extension. If both client and server support the ack extension, then the ack functionality will take place automatically. By enabling this extension, all messages arriving from the server will arrive via the long poll, so the comet communication will be slightly chattier. The fact that all messages will return via long poll means also that the messages will arrive with total order, which is not guaranteed if messages can arrive via both long poll and normal response. Messages are not acknowledged one by one, but instead a group of messages is acknowledged when long poll returns.

public class AckExtension implements Extension {
    public static final String EXT_FIELD = "ack";
    private volatile boolean _serverSupportsAcks = false;
    private volatile int _ackId = -1;
    public AckExtension() {
    public Message send(Client fromMessage message) {
        return message;
    public Message rcv(Client fromMessage message) {
        return message;
    public Message sendMeta(Client fromMessage message) {
        if (..equals(message.getChannel())) {
             = -1;
        } else if ( && ..equals(message.getChannel())) {
        return message;
    public Message rcvMeta(Client fromMessage message) {
        if (..equals(message.getChannel())) {
            Map<StringObjectext = message.getExt(false);
             = ext != null && ..equals(ext.get());
        } else if ( && ..equals(message.get(.))
                && ..equals(message.getChannel())) {
            Map<StringObjectext = message.getExt(false);
            if (ext != null) {
                Object ack = ext.get();
                if (ack instanceof Number)
                     = ((Numberack).intValue();
        return message;
New to GrepCode? Check out our FAQ X