Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » store » kahadaptor » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.store.kahadaptor;
   18   
   19   import java.io.DataInput;
   20   import java.io.DataOutput;
   21   import java.io.IOException;
   22   import java.util.ArrayList;
   23   import java.util.List;
   24   import org.apache.activemq.kaha.Marshaller;
   25   import org.apache.activemq.kaha.impl.async.Location;
   26   import org.apache.activemq.store.amq.AMQTx;
   27   import org.apache.activemq.store.amq.AMQTxOperation;
   28   import org.apache.activemq.wireformat.WireFormat;
   29   
   30   /**
   31    * Marshall an AMQTx
   32    * 
   33    * @version $Revision: 1.10 $
   34    */
   35   public class AMQTxMarshaller implements Marshaller<AMQTx> {
   36   
   37       private WireFormat wireFormat;
   38   
   39       public AMQTxMarshaller(WireFormat wireFormat) {
   40           this.wireFormat = wireFormat;
   41       }
   42   
   43       public AMQTx readPayload(DataInput dataIn) throws IOException {
   44           Location location = new Location();
   45           location.readExternal(dataIn);
   46           AMQTx result = new AMQTx(location);
   47           int size = dataIn.readInt();
   48           for (int i = 0; i < size; i++) {
   49               AMQTxOperation op = new AMQTxOperation();
   50               op.readExternal(wireFormat, dataIn);
   51               result.getOperations().add(op);
   52           }
   53           return result;
   54       }
   55   
   56       public void writePayload(AMQTx amqtx, DataOutput dataOut) throws IOException {
   57           amqtx.getLocation().writeExternal(dataOut);
   58           List<AMQTxOperation> list = amqtx.getOperations();
   59           List<AMQTxOperation> ops = new ArrayList<AMQTxOperation>();
   60           
   61           for (AMQTxOperation op : list) {
   62               if (op.getOperationType() == op.ADD_OPERATION_TYPE) {
   63                   ops.add(op);
   64               }
   65           }
   66           dataOut.writeInt(ops.size());
   67           for (AMQTxOperation op : ops) {
   68               op.writeExternal(wireFormat, dataOut);
   69           }
   70       }
   71   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » store » kahadaptor » [javadoc | source]