/*
* Copyright (c) 2005 Your Corporation. All Rights Reserved.
*/
package org.activemq.transport.stomp;
import org.activemq.message.TransactionInfo;
import org.activemq.message.KeepAlive;
import org.activemq.message.TransactionType;
import java.io.DataInput;
import java.io.IOException;
import java.util.Properties;
public class Begin implements Command
{
private StompWireFormat format;
private static final HeaderParser parser = new HeaderParser();
public Begin(StompWireFormat format)
{
this.format = format;
}
public PacketEnvelope build(String commandLine, DataInput in) throws IOException
{
Properties headers = parser.parse(in);
while (in.readByte() != 0) {}
if (format.isInTransaction())
{
return new PacketEnvelope(new KeepAlive(), headers);
}
TransactionInfo tx = new TransactionInfo();
String tx_id = StompWireFormat.clientIds.generateId();
format.setTransactionId(tx_id);
tx.setTransactionId(tx_id);
tx.setType(TransactionType.START);
return new PacketEnvelope(tx, headers);
}
}