Package net.timewalker.ffmq3.transport.packet.query

Source Code of net.timewalker.ffmq3.transport.packet.query.CommitQuery

/*
* This file is part of FFMQ.
*
* FFMQ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* FFMQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFMQ; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
package net.timewalker.ffmq3.transport.packet.query;

import java.util.ArrayList;
import java.util.List;

import net.timewalker.ffmq3.common.message.AbstractMessage;
import net.timewalker.ffmq3.common.message.MessageSerializer;
import net.timewalker.ffmq3.transport.packet.PacketType;
import net.timewalker.ffmq3.utils.RawDataBuffer;

/**
* CommitQuery
*/
public final class CommitQuery extends AbstractTransactionDemarcationQuery
{
    private List messages;
   
    /* (non-Javadoc)
     * @see net.timewalker.ffmq3.network.packet.AbstractPacket#getType()
     */
    public byte getType()
    {
        return PacketType.Q_COMMIT;
    }
   
    /* (non-Javadoc)
     * @see net.timewalker.ffmq3.network.packet.AbstractPacket#serializeTo(net.timewalker.ffmq3.utils.RawDataOutputStream)
     */
    protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
        if (messages != null)
        {
            int len = messages.size();
            out.writeInt(len);
            for (int i = 0; i < len; i++)
                MessageSerializer.serializeTo((AbstractMessage)messages.get(i), out);
        }
        else
            out.writeInt(0);
    }

    /* (non-Javadoc)
     * @see net.timewalker.ffmq3.network.packet.AbstractPacket#unserializeFrom(net.timewalker.ffmq3.utils.RawDataInputStream)
     */
    protected void unserializeFrom(RawDataBuffer in)
    {
        super.unserializeFrom(in);
        int msgCount = in.readInt();
        for (int i = 0; i < msgCount; i++)
        {
            AbstractMessage message = MessageSerializer.unserializeFrom(in, true);
            addMessage(message);
        }
    }

    /**
     * @param message The message to set.
     */
    public void addMessage(AbstractMessage message)
    {
        if (messages == null)
            messages = new ArrayList();
        messages.add(message);
    }
   
    public List getMessages()
    {
        return messages;
    }
   
    /**
     * @param messages the messages to set
     */
    public void setMessages(List messages)
    {
        this.messages = messages;
    }
   
    /*
     *  (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString()
    {
       StringBuffer sb = new StringBuffer();
      
       sb.append(super.toString());
       sb.append(" messages=");
       sb.append(messages != null ? messages.size() : 0);
      
       return sb.toString();
    }
}
TOP

Related Classes of net.timewalker.ffmq3.transport.packet.query.CommitQuery

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.