Esempio n. 1
0
 /**
  * Serialize the Transaction to a ByteBuffer.
  *
  * <ol>
  *   <li><strong>lockSize</strong> - position 0
  *   <li><strong>locks</strong> - position 4
  *   <li><strong>writes</strong> - position 4 + lockSize
  * </ol>
  *
  * @return the ByteBuffer representation
  */
 private ByteBuffer serialize() {
   ByteBuffer _locks = ByteableCollections.toByteBuffer(locks.values());
   ByteBuffer _writes = ByteableCollections.toByteBuffer(((Queue) buffer).getWrites());
   ByteBuffer bytes = ByteBuffer.allocate(4 + _locks.capacity() + _writes.capacity());
   bytes.putInt(_locks.capacity());
   bytes.put(_locks);
   bytes.put(_writes);
   bytes.rewind();
   return bytes;
 }
Esempio n. 2
0
 /**
  * Deserialize the content of this Transaction from {@code bytes}.
  *
  * @param bytes
  */
 private void deserialize(ByteBuffer bytes) {
   locks = Maps.newHashMap();
   Iterator<ByteBuffer> it =
       ByteableCollections.iterator(ByteBuffers.slice(bytes, bytes.getInt()));
   while (it.hasNext()) {
     LockDescription lock =
         LockDescription.fromByteBuffer(it.next(), lockService, rangeLockService);
     locks.put(lock.getToken(), lock);
   }
   it = ByteableCollections.iterator(bytes);
   while (it.hasNext()) {
     Write write = Write.fromByteBuffer(it.next());
     buffer.insert(write);
   }
 }