Пример #1
0
  public static SequentialFile writeControlFile(
      final SequentialFileFactory fileFactory,
      final List<JournalFile> files,
      final List<JournalFile> newFiles,
      final List<Pair<String, String>> renames)
      throws Exception {

    SequentialFile controlFile =
        fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL, 1);

    try {
      controlFile.open(1, false);

      JournalImpl.initFileHeader(fileFactory, controlFile, 0, 0);

      HornetQBuffer filesToRename = HornetQBuffers.dynamicBuffer(1);

      // DataFiles first

      if (files == null) {
        filesToRename.writeInt(0);
      } else {
        filesToRename.writeInt(files.size());

        for (JournalFile file : files) {
          filesToRename.writeUTF(file.getFile().getFileName());
        }
      }

      // New Files second

      if (newFiles == null) {
        filesToRename.writeInt(0);
      } else {
        filesToRename.writeInt(newFiles.size());

        for (JournalFile file : newFiles) {
          filesToRename.writeUTF(file.getFile().getFileName());
        }
      }

      // Renames from clean up third
      if (renames == null) {
        filesToRename.writeInt(0);
      } else {
        filesToRename.writeInt(renames.size());
        for (Pair<String, String> rename : renames) {
          filesToRename.writeUTF(rename.getA());
          filesToRename.writeUTF(rename.getB());
        }
      }

      JournalInternalRecord controlRecord =
          new JournalAddRecord(
              true, 1, (byte) 0, new ByteArrayEncoding(filesToRename.toByteBuffer().array()));

      HornetQBuffer renameBuffer = HornetQBuffers.dynamicBuffer(filesToRename.writerIndex());

      controlRecord.setFileID(0);

      controlRecord.encode(renameBuffer);

      ByteBuffer writeBuffer = fileFactory.newBuffer(renameBuffer.writerIndex());

      writeBuffer.put(renameBuffer.toByteBuffer().array(), 0, renameBuffer.writerIndex());

      writeBuffer.rewind();

      controlFile.writeDirect(writeBuffer, true);

      return controlFile;
    } finally {
      controlFile.close();
    }
  }
Пример #2
0
 protected void writeEncoder(final JournalInternalRecord record) throws Exception {
   record.setFileID(currentFile.getRecordID());
   record.encode(getWritingChannel());
 }