public static Message createMessage(
      String keyspace, byte[] key, String columnFamily, List<ColumnFamily> columnFamilies) {
    ColumnFamily baseColumnFamily;
    DataOutputBuffer bufOut = new DataOutputBuffer();
    RowMutation rm;
    Message message;
    Column column;

    /* Get the first column family from list, this is just to get past validation */
    baseColumnFamily =
        new ColumnFamily(
            ColumnFamilyType.Standard,
            DatabaseDescriptor.getComparator(keyspace, columnFamily),
            DatabaseDescriptor.getSubComparator(keyspace, columnFamily),
            CFMetaData.getId(keyspace, columnFamily));

    for (ColumnFamily cf : columnFamilies) {
      bufOut.reset();
      ColumnFamily.serializer().serializeWithIndexes(cf, bufOut);
      byte[] data = new byte[bufOut.getLength()];
      System.arraycopy(bufOut.getData(), 0, data, 0, bufOut.getLength());

      column = new Column(FBUtilities.toByteBuffer(cf.id()), ByteBuffer.wrap(data), 0);
      baseColumnFamily.addColumn(column);
    }
    rm = new RowMutation(keyspace, ByteBuffer.wrap(key));
    rm.add(baseColumnFamily);

    try {
      /* Make message */
      message = rm.makeRowMutationMessage(StorageService.Verb.BINARY, MessagingService.version_);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    return message;
  }
Beispiel #2
0
 private static byte[] pair(BytesWritable a, BytesWritable b) {
   byte[] pairData = new byte[a.getLength() + b.getLength()];
   System.arraycopy(a.getBytes(), 0, pairData, 0, a.getLength());
   System.arraycopy(b.getBytes(), 0, pairData, a.getLength(), b.getLength());
   return pairData;
 }