/* This file is part of VoltDB.
 * Copyright (C) 2008-2012 VoltDB Inc.
 *
 * VoltDB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VoltDB 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.voltdb.messaging;

import org.voltcore.messaging.TransactionInfoBaseMessage;
import org.voltdb.utils.DBBPool;

public class MultiPartitionParticipantMessage extends TransactionInfoBaseMessage {

    MultiPartitionParticipantMessage() {
        super();
    }

    public MultiPartitionParticipantMessage(int initiatorSiteId,
                                           int coordinatorSiteId,
                                           long txnId,
                                           boolean isReadOnly) {
        super(initiatorSiteId, coordinatorSiteId, txnId, isReadOnly);
    }

    @Override
    protected void flattenToBuffer(DBBPool pool) {
        int msgsize = super.getMessageByteCount();

        if (m_buffer == null) {
            m_container = pool.acquire(msgsize + 1 + HEADER_SIZE);
            m_buffer = m_container.b;
        }
        setBufferSize(msgsize + 1, pool);

        m_buffer.position(HEADER_SIZE);
        m_buffer.put(PARTICIPANT_NOTICE_ID);

        super.writeToBuffer();

        m_buffer.limit(m_buffer.position());
    }

    @Override
    protected void initFromBuffer() {
        m_buffer.position(HEADER_SIZE + 1); // skip the msg id
        super.readFromBuffer();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("MULTI_PARTITION_PARTICIPANT (FROM ");
        sb.append(m_coordinatorSiteId);
        sb.append(" TO ");
        sb.append(receivedFromSiteId);
        sb.append(") FOR TXN ");
        sb.append(m_txnId);

        return sb.toString();
    }
}

@@ -731,16 +731,73 @@
 aging;%0A%0A
+import java.io.IOException;%0Aimport java.nio.ByteBuffer;%0A%0A
 import o
@@ -865,24 +865,28 @@
 volt
-db
+core
 .utils.
-DBBPool
+MiscUtils
 ;%0A%0Ap
@@ -1077,19 +1077,20 @@
 Message(
-int
+long
  initiat
@@ -1087,28 +1087,26 @@
 ng initiator
+H
 S
-ite
 Id,%0A        
@@ -1140,19 +1140,21 @@
         
-int
+ long
  coordin
@@ -1161,16 +1161,15 @@
 ator
+H
 S
-ite
 Id,%0A
+ 
     
@@ -1262,16 +1262,17 @@
         
+ 
 boolean 
@@ -1304,28 +1304,26 @@
 er(initiator
+H
 S
-ite
 Id, coordina
@@ -1325,20 +1325,18 @@
 rdinator
+H
 S
-ite
 Id, txnI
@@ -1381,51 +1381,41 @@
    p
-rotected void flattenToBuffer(DBBPool pool)
+ublic int getSerializedSize()%0A   
  %7B%0A 
@@ -1448,37 +1448,34 @@
 .get
-MessageByteCount
+SerializedSize
 ();%0A
-%0A
         
 if (
@@ -1474,251 +1474,155 @@
     
-if (m_buffer == null) %7B%0A            m_container = pool.acquire(msgsize + 1 + HEADER_SIZE);%0A  
+return msgsize;%0A
     
-  
+%7D%0A%0A
     
-m_buffer = m_container.b;%0A        %7D%0A        setBufferSize(msgsize + 1, pool);%0A%0A        m_buffer.position(HEADER_SIZE);
+@Override%0A    public void flattenToBuffer(ByteBuffer buf) throws IOException
 %0A    
+%7B%0A
     
-m_buffer.put(
+    buf.put(VoltDbMessageFactory.
 PART
@@ -1641,17 +1641,16 @@
 CE_ID);%0A
-%0A
         
@@ -1659,13 +1659,15 @@
 per.
-wri
+flat
 te
+n
 ToBu
@@ -1671,28 +1671,30 @@
 oBuffer(
+buf
 );%0A
-%0A
         
 m_buffer
@@ -1689,31 +1689,71 @@
     
-m_buffer
+assert(buf.capacity() == buf.position());%0A        buf
 .limit(
-m_
 buf
-fer
 .pos
@@ -1792,16 +1792,13 @@
    p
-rotected
+ublic
  voi
@@ -1818,74 +1818,44 @@
 fer(
-) %7B%0A        m_buffer.position(HEADER_SIZE + 1); // skip the msg id
+ByteBuffer buf) throws IOException %7B
 %0A   
@@ -1869,12 +1869,12 @@
 per.
-read
+init
 From
@@ -1880,16 +1880,19 @@
 mBuffer(
+buf
 );%0A    %7D
@@ -2066,93 +2066,52 @@
 end(
-m_coordinatorSiteId);%0A        sb.append(%22 TO %22);%0A        sb.append(receivedFromSiteId
+MiscUtils.hsIdToString(getCoordinatorHSId())
 );%0A 

Rework MultiPartitionParticipantMessage to conform to new messaging patterns.