/// <summary> Set the LockFactory that this Directory instance should /// use for its locking implementation. Each * instance of /// LockFactory should only be used for one directory (ie, /// do not share a single instance across multiple /// Directories). /// /// </summary> /// <param name="lockFactory">instance of <see cref="LockFactory" />. /// </param> public virtual void SetLockFactory(LockFactory lockFactory) { System.Diagnostics.Debug.Assert(lockFactory != null); this.interalLockFactory = lockFactory; lockFactory.LockPrefix = this.GetLockId(); }
/// <summary>Create a new SimpleFSDirectory for the named location. /// /// </summary> /// <param name="path">the path of the directory /// </param> /// <param name="lockFactory">the lock factory to use, or null for the default. /// </param> /// <throws> IOException </throws> public SimpleFSDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory) : base(path, lockFactory) { }
/// <summary>Create a new MMapDirectory for the named location. /// /// </summary> /// <param name="path">the path of the directory /// </param> /// <param name="lockFactory">the lock factory to use, or null for the default. /// </param> /// <throws> IOException </throws> public MMapDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory) : base(path, lockFactory) { InitBlock(); }
/// <summary>Just like <see cref="Open(System.IO.DirectoryInfo)" />, but allows you to /// also specify a custom <see cref="LockFactory" />. /// </summary> public static FSDirectory Open(System.IO.DirectoryInfo path, LockFactory lockFactory) { /* For testing: MMapDirectory dir=new MMapDirectory(path, lockFactory); dir.setUseUnmap(true); return dir; */ if (Constants.WINDOWS) { return new SimpleFSDirectory(path, lockFactory); } else { //NIOFSDirectory is not implemented in Lucene.Net //return new NIOFSDirectory(path, lockFactory); return new SimpleFSDirectory(path, lockFactory); } }
/// <summary>Create a new FSDirectory for the named location (ctor for subclasses).</summary> /// <param name="path">the path of the directory /// </param> /// <param name="lockFactory">the lock factory to use, or null for the default /// (<see cref="NativeFSLockFactory" />); /// </param> /// <throws> IOException </throws> protected internal FSDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory) { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } // Set up lockFactory with cascaded defaults: if an instance was passed in, // use that; else if locks are disabled, use NoLockFactory; else if the // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set, // instantiate that; else, use SimpleFSLockFactory: internalDirectory = path; // due to differences in how Java & .NET refer to files, the checks are a bit different if (!internalDirectory.Exists && System.IO.File.Exists(internalDirectory.FullName)) { throw new NoSuchDirectoryException("file '" + internalDirectory.FullName + "' exists but is not a directory"); } SetLockFactory(lockFactory); // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves if (lockFactory is FSLockFactory) { FSLockFactory lf = (FSLockFactory)lockFactory; System.IO.DirectoryInfo dir = lf.LockDir; // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.LockDir = this.internalDirectory; lf.LockPrefix = null; } else if (dir.FullName.Equals(this.internalDirectory.FullName)) { lf.LockPrefix = null; } } }