public void write(RandomAccessFile raf) throws IOException {
   raf.writeUTF(token);
   raf.writeInt(startRow);
   raf.writeInt(numRows);
   final boolean hasNormalizedForm = !token.equals(normalizedToken);
   raf.writeBoolean(hasNormalizedForm);
   if (hasNormalizedForm) {
     raf.writeUTF(normalizedToken);
   }
   RAFList.write(raf, htmlEntries, index.dict.htmlEntryIndexSerializer);
 }
 @Override
 public void write(final RandomAccessFile raf) throws IOException {
   raf.writeUTF(shortName);
   raf.writeUTF(longName);
   raf.writeUTF(sortLanguage.getIsoCode());
   raf.writeUTF(normalizerRules);
   raf.writeBoolean(swapPairEntries);
   if (dict.dictFileVersion >= 2) {
     raf.writeInt(mainTokenCount);
   }
   RAFList.write(raf, sortedIndexEntries, indexEntrySerializer);
   new SerializableSerializer<Set<String>>().write(raf, stoplist);
   UniformRAFList.write(raf, (Collection<RowBase>) rows, new RowBase.Serializer(this), 5 /*
                                                                                              * bytes
                                                                                              * per
                                                                                              * entry
                                                                                              */);
 }
 private void markDirty() throws IOException {
   lockFileAccess.seek(STATE_REGION_POS);
   lockFileAccess.writeByte(STATE_REGION_PROTOCOL);
   lockFileAccess.writeBoolean(false);
   assert lockFileAccess.getFilePointer() == STATE_REGION_SIZE + STATE_REGION_POS;
 }
    private java.nio.channels.FileLock lock(FileLockManager.LockMode lockMode) throws Throwable {
      LOGGER.debug(
          "Waiting to acquire {} lock on {}.", lockMode.toString().toLowerCase(), displayName);
      long timeout = System.currentTimeMillis() + lockTimeoutMs;

      // Lock the state region, with the requested mode
      java.nio.channels.FileLock stateRegionLock = lockStateRegion(lockMode, timeout);
      if (stateRegionLock == null) {
        // Can't acquire lock, get details of owner to include in the error message
        String ownerPid = "unknown";
        String ownerOperation = "unknown";
        java.nio.channels.FileLock informationRegionLock =
            lockInformationRegion(LockMode.Shared, timeout);
        if (informationRegionLock == null) {
          LOGGER.debug("Could not lock information region for {}. Ignoring.", displayName);
        } else {
          try {
            if (lockFileAccess.length() <= INFORMATION_REGION_POS) {
              LOGGER.debug(
                  "Lock file for {} is too short to contain information region. Ignoring.",
                  displayName);
            } else {
              lockFileAccess.seek(INFORMATION_REGION_POS);
              if (lockFileAccess.readByte() != INFORMATION_REGION_PROTOCOL) {
                throw new IllegalStateException(
                    String.format(
                        "Unexpected lock protocol found in lock file '%s' for %s.",
                        lockFile, displayName));
              }
              ownerPid = lockFileAccess.readUTF();
              ownerOperation = lockFileAccess.readUTF();
            }
          } finally {
            informationRegionLock.release();
          }
        }

        throw new LockTimeoutException(
            String.format(
                "Timeout waiting to lock %s. It is currently in use by another Gradle instance.%nOwner PID: %s%nOur PID: %s%nOwner Operation: %s%nOur operation: %s%nLock file: %s",
                displayName,
                ownerPid,
                metaDataProvider.getProcessIdentifier(),
                ownerOperation,
                operationDisplayName,
                lockFile));
      }

      try {
        if (lockFileAccess.length() > 0) {
          lockFileAccess.seek(STATE_REGION_POS);
          if (lockFileAccess.readByte() != STATE_REGION_PROTOCOL) {
            throw new IllegalStateException(
                String.format(
                    "Unexpected lock protocol found in lock file '%s' for %s.",
                    lockFile, displayName));
          }
        }

        if (!stateRegionLock.isShared()) {
          // We have an exclusive lock (whether we asked for it or not).
          // Update the state region
          if (lockFileAccess.length() < STATE_REGION_SIZE) {
            // File did not exist before locking
            lockFileAccess.seek(STATE_REGION_POS);
            lockFileAccess.writeByte(STATE_REGION_PROTOCOL);
            lockFileAccess.writeBoolean(false);
          }
          // Acquire an exclusive lock on the information region and write our details there
          java.nio.channels.FileLock informationRegionLock =
              lockInformationRegion(LockMode.Exclusive, timeout);
          if (informationRegionLock == null) {
            throw new IllegalStateException(
                String.format(
                    "Timeout waiting to lock the information region for lock %s", displayName));
          }
          // check that the length of the reserved region is enough for storing our content
          try {
            lockFileAccess.seek(INFORMATION_REGION_POS);
            lockFileAccess.writeByte(INFORMATION_REGION_PROTOCOL);
            lockFileAccess.writeUTF(trimIfNecessary(metaDataProvider.getProcessIdentifier()));
            lockFileAccess.writeUTF(trimIfNecessary(operationDisplayName));
            lockFileAccess.setLength(lockFileAccess.getFilePointer());
          } finally {
            informationRegionLock.release();
          }
        }
      } catch (Throwable t) {
        stateRegionLock.release();
        throw t;
      }

      LOGGER.debug("Lock acquired.");
      return stateRegionLock;
    }
Exemplo n.º 5
0
 /* @see java.io.DataOutput.writeBoolean(boolean) */
 public void writeBoolean(boolean v) throws IOException {
   raf.writeBoolean(v);
 }