org.apache.lucene.store

## Class LockValidatingDirectoryWrapper

- java.lang.Object
- - org.apache.lucene.store.Directory
  - - org.apache.lucene.store.FilterDirectory
    - - org.apache.lucene.store.LockValidatingDirectoryWrapper

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public final class LockValidatingDirectoryWrapper
      extends FilterDirectory

  This class makes a best-effort check that a provided `Lock` is valid before any destructive filesystem operation.

- - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.store.FilterDirectory

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LockValidatingDirectoryWrapper(Directory in, Lock writeLock)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `copyFrom(Directory from, String src, String dest, IOContext context)` Copies the file src in from to this directory under the new file name dest.
    `IndexOutput` | `createOutput(String name, IOContext context)` Creates a new, empty file in the directory with the given name.
    `void` | `deleteFile(String name)` Removes an existing file in the directory.
    `void` | `rename(String source, String dest)` Renames `source` to `dest` as an atomic operation, where `dest` does not yet exist in the directory.
    `void` | `sync(Collection<String> names)` Ensure that any writes to these files are moved to stable storage.
    `void` | `syncMetaData()` Ensure that directory metadata, such as recent file renames, are made durable.

    - ### Methods inherited from class org.apache.lucene.store.FilterDirectory

      `close, createTempOutput, fileLength, getDelegate, listAll, obtainLock, openInput, toString, unwrap`

    - ### Methods inherited from class org.apache.lucene.store.Directory

      `ensureOpen, openChecksumInput, renameFile`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LockValidatingDirectoryWrapper

          public LockValidatingDirectoryWrapper(Directory in,
                                                Lock writeLock)

  - ### Method Detail

    - #### deleteFile

          public void deleteFile(String name)
                          throws IOException

      Description copied from class: `Directory`
      Removes an existing file in the directory.
      Overrides:
        `deleteFile` in class `FilterDirectory`
      Throws:
        `IOException`

    - #### createOutput

          public IndexOutput createOutput(String name,
                                          IOContext context)
                                   throws IOException

      Description copied from class: `Directory`
      Creates a new, empty file in the directory with the given name. Returns a stream writing this file.
      Overrides:
        `createOutput` in class `FilterDirectory`
      Throws:
        `IOException`

    - #### copyFrom

          public void copyFrom(Directory from,
                               String src,
                               String dest,
                               IOContext context)
                        throws IOException

      Description copied from class: `Directory`
      Copies the file src in from to this directory under the new file name dest.

      If you want to copy the entire source directory to the destination one, you can do so like this:

           Directory to; // the directory to copy to
           for (String file : dir.listAll()) {
             to.copyFrom(dir, file, newFile, IOContext.DEFAULT); // newFile can be either file, or a new name
           }

      NOTE: this method does not check whether dest exist and will overwrite it if it does.

      Overrides:
        `copyFrom` in class `Directory`
      Throws:
        `IOException`

    - #### rename

          public void rename(String source,
                             String dest)
                      throws IOException

      Description copied from class: `Directory`
      Renames `source` to `dest` as an atomic operation, where `dest` does not yet exist in the directory.

      Notes: This method is used by IndexWriter to publish commits. It is ok if this operation is not truly atomic, for example both `source` and `dest` can be visible temporarily. It is just important that the contents of `dest` appear atomically, or an exception is thrown.

      Overrides:
        `rename` in class `FilterDirectory`
      Throws:
        `IOException`

    - #### syncMetaData

          public void syncMetaData()
                            throws IOException

      Description copied from class: `Directory`
      Ensure that directory metadata, such as recent file renames, are made durable.
      Overrides:
        `syncMetaData` in class `FilterDirectory`
      Throws:
        `IOException`

    - #### sync

          public void sync(Collection<String> names)
                    throws IOException

      Description copied from class: `Directory`
      Ensure that any writes to these files are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.
      NOTE: Clients may call this method for same files over and over again, so some impls might optimize for that. For other impls the operation can be a noop, for various reasons.
      Overrides:
        `sync` in class `FilterDirectory`
      Throws:
        `IOException`

Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.