/// <param name="id">should be a unique id across all clients /// </param> /// <param name="lf">the LockFactory that we are testing /// </param> /// <param name="host">host or IP where {@link LockVerifyServer} /// is running /// </param> /// <param name="port">the port {@link LockVerifyServer} is /// listening on /// </param> public VerifyingLockFactory(sbyte id, LockFactory lf, System.String host, int port) { this.id = id; this.lf = lf; this.host = host; this.port = port; }
public LocalTempStorageDirectory( DirectoryInfo tempStorageDir, FSDirectory realDirectory) { if (tempStorageDir == null) throw new ArgumentNullException("tempStorageDir"); if (realDirectory == null) throw new ArgumentNullException("realDirectory"); _tempStorageDir = new SimpleFSDirectory(tempStorageDir); _realDirectory = realDirectory; _lockFactory = new MultiIndexLockFactory(_realDirectory, _tempStorageDir); Enabled = true; }
public static FSDirectory GetDirectory(System.IO.FileInfo file, LockFactory lockFactory) { return(GetDirectory(new System.IO.DirectoryInfo(file.FullName), lockFactory)); }
public SimpleFSDirectory(System.IO.FileInfo path, LockFactory lockFactory):base(new System.IO.DirectoryInfo(path.FullName), lockFactory) { }
/// <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>Just like {@link #Open(File)}, but allows you to /// also specify a custom {@link 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 { //LINUX Issue: NIOFSDirectory implementation in lucene.NET is buggy on Mono (Linux) //Workaround: use SimpleFSDirectory instead //return new NIOFSDirectory(path, lockFactory); return new SimpleFSDirectory(path, lockFactory); } }
// permit subclassing /// <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 /// ({@link 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(); } Init(path, lockFactory); refCount = 1; }
/// <summary>Just like {@link #Open(File)}, but allows you to /// also specify a custom {@link 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); } }
// permit subclassing /// <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 /// ({@link NativeFSLockFactory}); /// </param> /// <throws> IOException </throws> protected internal FSDirectory(System.IO.FileInfo path, LockFactory lockFactory) { path = GetCanonicalPath(path); // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } Init(path, lockFactory); refCount = 1; }
/// <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) { throw new System.NotImplementedException("Use FSDirectory (https://issues.apache.org/jira/browse/LUCENENET-425)"); }
public NIOFSDirectory(System.IO.DirectoryInfo dir, LockFactory lockFactory) { }
public override void SetLockFactory(LockFactory lockFactory) { Debug.Assert(lockFactory != null); this.m_lockFactory = lockFactory; lockFactory.LockPrefix = this.GetLockID(); }
/// <summary> /// Creates a new <see cref="VerifyingLockFactory"/> instance. /// </summary> /// <param name="lf"> the <see cref="LockFactory"/> that we are testing </param> /// <param name="in"> the socket's input to <see cref="LockVerifyServer"/> </param> /// <param name="out"> the socket's output to <see cref="LockVerifyServer"/> </param> public VerifyingLockFactory(LockFactory lf, Stream @in, Stream @out) { this.lf = lf; this.@in = @in; this.@out = @out; }
public override void SetLockFactory(LockFactory lockFactory) { m_input.SetLockFactory(lockFactory); }
/// <summary> /// Just like <see cref="Open(DirectoryInfo, LockFactory)"/>, but /// allows you to specify the directory as a <see cref="string"/>. /// </summary> /// <param name="path">The path (to a directory) to open</param> /// <param name="lockFactory"></param> /// <returns>An open <see cref="FSDirectory"/></returns> public static FSDirectory Open(string path, LockFactory lockFactory) // LUCENENET specific overload for ease of use with .NET { return(Open(new DirectoryInfo(path), lockFactory)); }
public virtual void _testStressLocks(LockFactory lockFactory, DirectoryInfo indexDir) { Directory dir = NewFSDirectory(indexDir, lockFactory); // First create a 1 doc index: IndexWriter w = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE)); AddDoc(w); w.Dispose(); WriterThread writer = new WriterThread(this, 100, dir); SearcherThread searcher = new SearcherThread(this, 100, dir); writer.Start(); searcher.Start(); while (writer.IsAlive || searcher.IsAlive) { Thread.Sleep(1000); } Assert.IsTrue(!writer.HitException, "IndexWriter hit unexpected exceptions"); Assert.IsTrue(!searcher.HitException, "IndexSearcher hit unexpected exceptions"); dir.Dispose(); // Cleanup System.IO.Directory.Delete(indexDir.FullName, true); }
/// <summary> /// Creates a new <see cref="VerifyingLockFactory"/> instance. /// </summary> /// <param name="lf"> the <see cref="LockFactory"/> that we are testing </param> /// <param name="stream"> the socket's stream input/output to <see cref="LockVerifyServer"/> </param> public VerifyingLockFactory(LockFactory lf, Stream stream) { this.lf = lf; this.stream = stream; }
/// <summary> /// Just like <seealso cref="#open(File)"/>, but allows you to /// also specify a custom <seealso cref="LockFactory"/>. /// </summary> public static FSDirectory Open(DirectoryInfo path, LockFactory lockFactory) { if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { return new MMapDirectory(path, lockFactory); } else 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); } }
public MMapDirectory(System.IO.FileInfo path, LockFactory lockFactory) : base(new System.IO.DirectoryInfo(path.FullName), lockFactory) { InitBlock(); }
public static FSDirectory GetDirectory(System.IO.FileInfo file, LockFactory lockFactory) { return GetDirectory(new System.IO.DirectoryInfo(file.FullName), lockFactory); }
public SimpleFSDirectory(System.IO.FileInfo path, LockFactory lockFactory) : base(new System.IO.DirectoryInfo(path.FullName), lockFactory) { }
/// <summary> /// Create a new MMapDirectory for the named location, specifying the /// maximum chunk size used for memory mapping. /// </summary> /// <param name="path"> the path of the directory </param> /// <param name="lockFactory"> the lock factory to use, or null for the default /// (<seealso cref="NativeFSLockFactory"/>); </param> /// <param name="maxChunkSize"> maximum chunk size (default is 1 GiBytes for /// 64 bit JVMs and 256 MiBytes for 32 bit JVMs) used for memory mapping. /// <p> /// Especially on 32 bit platform, the address space can be very fragmented, /// so large index files cannot be mapped. Using a lower chunk size makes /// the directory implementation a little bit slower (as the correct chunk /// may be resolved on lots of seeks) but the chance is higher that mmap /// does not fail. On 64 bit Java platforms, this parameter should always /// be {@code 1 << 30}, as the address space is big enough. /// <p> /// <b>Please note:</b> The chunk size is always rounded down to a power of 2. </param> /// <exception cref="System.IO.IOException"> if there is a low-level I/O error </exception> public MMapDirectory(DirectoryInfo path, LockFactory lockFactory, int maxChunkSize) : base(path, lockFactory) { if (maxChunkSize <= 0) { throw new System.ArgumentException("Maximum chunk size for mmap must be >0"); } this.ChunkSizePower = 31 - Number.NumberOfLeadingZeros(maxChunkSize); Debug.Assert(this.ChunkSizePower >= 0 && this.ChunkSizePower <= 30); }
/// <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>Returns the directory instance for the named location.</summary> /// <param name="file">the path to the directory. /// </param> /// <param name="lockFactory">instance of {@link LockFactory} providing the /// locking implementation. /// </param> /// <returns> the FSDirectory for the named file. /// </returns> public static FSDirectory GetDirectory(System.IO.FileInfo file, LockFactory lockFactory) { file = new System.IO.FileInfo(file.FullName); bool tmpBool; if (System.IO.File.Exists(file.FullName)) { tmpBool = true; } else { tmpBool = System.IO.Directory.Exists(file.FullName); } if (tmpBool && !System.IO.Directory.Exists(file.FullName)) { throw new System.IO.IOException(file + " not a directory"); } bool tmpBool2; if (System.IO.File.Exists(file.FullName)) { tmpBool2 = true; } else { tmpBool2 = System.IO.Directory.Exists(file.FullName); } if (!tmpBool2) { try { System.IO.Directory.CreateDirectory(file.FullName); } catch { throw new System.IO.IOException("Cannot create directory: " + file); } } FSDirectory dir; lock (DIRECTORIES.SyncRoot) { dir = (FSDirectory)DIRECTORIES[file.FullName]; if (dir == null) { try { dir = (FSDirectory)System.Activator.CreateInstance(IMPL); } catch (System.Exception e) { throw new System.SystemException("cannot load FSDirectory class: " + e.ToString(), e); } dir.Init(file, lockFactory); DIRECTORIES[file.FullName] = dir; } else { // Catch the case where a Directory is pulled from the cache, but has a // different LockFactory instance. if (lockFactory != null && lockFactory != dir.GetLockFactory()) { throw new System.IO.IOException("Directory was previously created with a different LockFactory instance; please pass null as the lockFactory instance and use setLockFactory to change it"); } } } lock (dir) { dir.refCount++; } return(dir); }
public NIOFSDirectory(System.IO.DirectoryInfo dir, LockFactory lockFactory) : base(dir, lockFactory) { throw new System.NotImplementedException("Waiting for volunteers to implement this class"); }
// permit subclassing private void Init(System.IO.FileInfo path, LockFactory lockFactory) { // 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: directory = path; bool doClearLockID = false; if (lockFactory == null) { if (disableLocks) { // Locks are disabled: lockFactory = NoLockFactory.GetNoLockFactory(); } else { System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", ""); if (lockClassName != null && !lockClassName.Equals("")) { System.Type c; try { c = System.Type.GetType(lockClassName); } catch (System.Exception) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory)System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException e) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception ex) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName + "\nDetails:" + ex.Message); } if (lockFactory is NativeFSLockFactory) { ((NativeFSLockFactory)lockFactory).SetLockDir(path); } else if (lockFactory is SimpleFSLockFactory) { ((SimpleFSLockFactory)lockFactory).SetLockDir(path); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(path); doClearLockID = true; } } } SetLockFactory(lockFactory); if (doClearLockID) { // Clear the prefix because write.lock will be // stored in our directory: lockFactory.SetLockPrefix(null); } }
/* will move to ctor, when reflection is removed in 3.0 */ private void Init(System.IO.DirectoryInfo path, LockFactory lockFactory) { // 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: directory = path; // due to differences in how Java & .NET refer to files, the checks are a bit different if (!directory.Exists && System.IO.File.Exists(directory.FullName)) { throw new NoSuchDirectoryException("file '" + directory.FullName + "' exists but is not a directory"); } if (lockFactory == null) { if (disableLocks) { // Locks are disabled: lockFactory = NoLockFactory.GetNoLockFactory(); } else { System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", ""); if (lockClassName != null && !lockClassName.Equals("")) { System.Type c; try { c = System.Type.GetType(lockClassName); } catch (System.Exception e) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory)System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException e) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException e) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception e) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(); } } } 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.GetLockDir(); // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.SetLockDir(this.directory); lf.SetLockPrefix(null); } else if (dir.FullName.Equals(this.directory.FullName)) { lf.SetLockPrefix(null); } } }
/// <param name="lf"> the LockFactory that we are testing </param> /// <param name="in"> the socket's input to <seealso cref="LockVerifyServer"/> </param> /// <param name="out"> the socket's output to <seealso cref="LockVerifyServer"/> </param> public VerifyingLockFactory(LockFactory lf, Stream @in, Stream @out) { this.Lf = lf; this.@in = @in; this.@out = @out; }
/// <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 /// (<seealso cref="NativeFSLockFactory"/>); </param> /// <exception cref="System.IO.IOException"> if there is a low-level I/O error </exception> public SimpleFSDirectory(DirectoryInfo path, LockFactory lockFactory) : base(path, lockFactory) { }
/// <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 {@link LockFactory}. /// </param> public virtual void SetLockFactory(LockFactory lockFactory) { this.lockFactory = lockFactory; lockFactory.SetLockPrefix(this.GetLockID()); }
/// <summary>Just like {@link #Open(File)}, but allows you to /// also specify a custom {@link LockFactory}. /// </summary> public static FSDirectory Open(System.IO.FileInfo 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 { return new NIOFSDirectory(path, lockFactory); } }
public override void SetLockFactory(LockFactory lockFactory) { @delegate.SetLockFactory(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; } } }
public virtual void _testStressLocks(LockFactory lockFactory, System.IO.FileInfo indexDir) { FSDirectory fs1 = FSDirectory.Open(new System.IO.DirectoryInfo(indexDir.FullName), lockFactory); // First create a 1 doc index: IndexWriter w = new IndexWriter(fs1, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); AddDoc(w); w.Close(); WriterThread writer = new WriterThread(this, 100, fs1); SearcherThread searcher = new SearcherThread(this, 100, fs1); writer.Start(); searcher.Start(); while (writer.IsAlive || searcher.IsAlive) { System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 1000)); } Assert.IsTrue(!writer.hitException, "IndexWriter hit unexpected exceptions"); Assert.IsTrue(!searcher.hitException, "IndexSearcher hit unexpected exceptions"); // Cleanup _TestUtil.RmDir(indexDir); }
/// <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 /// (<seealso cref="NativeFSLockFactory"/>); </param> /// <exception cref="System.IO.IOException"> if there is a low-level I/O error </exception> protected internal FSDirectory(DirectoryInfo path, LockFactory lockFactory) { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } directory = path; // Lucene.NET doesn't need to call GetCanonicalPath since we already have DirectoryInfo handy if (File.Exists(path.FullName)) { throw new NoSuchDirectoryException("file '" + path.FullName + "' exists but is not a directory"); //should be NoSuchDirectoryException } LockFactory = 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 /// (<seealso cref="NativeFSLockFactory"/>); </param> /// <exception cref="System.IO.IOException"> if there is a low-level I/O error </exception> protected internal FSDirectory(DirectoryInfo path, LockFactory lockFactory) { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } directory = GetCanonicalPath(path); if (File.Exists(path.FullName)) { throw new NoSuchDirectoryException("file '" + path.FullName + "' exists but is not a directory"); //should be NoSuchDirectoryException } LockFactory = lockFactory; }
/// <summary>Create a new NIOFSDirectory 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 NIOFSDirectory(System.IO.FileInfo path, LockFactory lockFactory) : base(path, lockFactory) { }
/// <summary> /// Create a new <see cref="MMapDirectory"/> for the named location. /// <para/> /// LUCENENET specific overload for convenience using string instead of <see cref="DirectoryInfo"/>. /// </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> /// <exception cref="IOException"> if there is a low-level I/O error </exception> public MMapDirectory(string path, LockFactory lockFactory) : this(path, lockFactory, DEFAULT_MAX_BUFF) { }
public static FSDirectory GetDirectory(System.String path, LockFactory lockFactory) { return GetDirectory(new System.IO.DirectoryInfo(path), lockFactory); }
/// <summary> /// Create a new <see cref="MMapDirectory"/> for the named location, specifying the /// maximum chunk size used for memory mapping. /// <para/> /// LUCENENET specific overload for convenience using string instead of <see cref="DirectoryInfo"/>. /// </summary> /// <param name="path"> the path of the directory </param> /// <param name="lockFactory"> the lock factory to use, or <c>null</c> for the default /// (<see cref="NativeFSLockFactory"/>); </param> /// <param name="maxChunkSize"> maximum chunk size (default is 1 GiBytes for /// 64 bit runtimes and 256 MiBytes for 32 bit runtimes) used for memory mapping. /// <para/> /// Especially on 32 bit platform, the address space can be very fragmented, /// so large index files cannot be mapped. Using a lower chunk size makes /// the directory implementation a little bit slower (as the correct chunk /// may be resolved on lots of seeks) but the chance is higher that mmap /// does not fail. On 64 bit platforms, this parameter should always /// be <c>1 << 30</c>, as the address space is big enough. /// <para/> /// <b>Please note:</b> The chunk size is always rounded down to a power of 2. /// </param> /// <exception cref="IOException"> if there is a low-level I/O error </exception> public MMapDirectory(string path, LockFactory lockFactory, int maxChunkSize) : this(new DirectoryInfo(path), lockFactory, maxChunkSize) { }
public static FSDirectory GetDirectory(System.IO.DirectoryInfo file, LockFactory lockFactory) { FSDirectory dir; lock (DIRECTORIES) { if(!DIRECTORIES.TryGetValue(file.FullName, out dir)) { try { dir = (FSDirectory)System.Activator.CreateInstance(IMPL, true); } catch (System.Exception e) { throw new System.SystemException("cannot load FSDirectory class: " + e.ToString(), e); } dir.Init(file, lockFactory); DIRECTORIES.Add(file.FullName, dir); } else { // Catch the case where a Directory is pulled from the cache, but has a // different LockFactory instance. if (lockFactory != null && lockFactory != dir.GetLockFactory()) { throw new System.IO.IOException("Directory was previously created with a different LockFactory instance; please pass null as the lockFactory instance and use setLockFactory to change it"); } dir.checked_Renamed = false; } } lock (dir) { dir.refCount++; } return dir; }
/// <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 /// (<seealso cref="NativeFSLockFactory"/>); </param> /// <exception cref="System.IO.IOException"> if there is a low-level I/O error </exception> public MMapDirectory(DirectoryInfo path, LockFactory lockFactory) : this(path, lockFactory, DEFAULT_MAX_BUFF) { }
/* will move to ctor, when reflection is removed in 3.0 */ private void Init(System.IO.DirectoryInfo path, LockFactory lockFactory) { // 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: directory = path; // due to differences in how Java & .NET refer to files, the checks are a bit different if (!directory.Exists && System.IO.File.Exists(directory.FullName)) { throw new NoSuchDirectoryException("file '" + directory.FullName + "' exists but is not a directory"); } if (lockFactory == null) { if (disableLocks) { // Locks are disabled: lockFactory = NoLockFactory.GetNoLockFactory(); } else { System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", ""); if (lockClassName != null && !lockClassName.Equals("")) { System.Type c; try { c = System.Type.GetType(lockClassName); } catch (System.Exception e) { throw new System.IO.IOException("unable to find LockClass " + lockClassName); } try { lockFactory = (LockFactory) System.Activator.CreateInstance(c, true); } catch (System.UnauthorizedAccessException e) { throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName); } catch (System.InvalidCastException e) { throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory"); } catch (System.Exception e) { throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName); } } else { // Our default lock is SimpleFSLockFactory; // default lockDir is our index directory: lockFactory = new SimpleFSLockFactory(); } } } 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.GetLockDir(); // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.SetLockDir(this.directory); lf.SetLockPrefix(null); } else if (dir.FullName.Equals(this.directory.FullName)) { lf.SetLockPrefix(null); } } }
/// <summary> /// Create a new <see cref="NIOFSDirectory"/> 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 /// (<see cref="NativeFSLockFactory"/>); </param> /// <exception cref="IOException"> if there is a low-level I/O error </exception> public NIOFSDirectory(DirectoryInfo path, LockFactory lockFactory) : base(path, lockFactory) { }
/// <summary> /// Create a new <see cref="NIOFSDirectory"/> for the named location. /// <para/> /// LUCENENET specific overload for convenience using string instead of <see cref="DirectoryInfo"/>. /// </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> /// <exception cref="IOException"> if there is a low-level I/O error </exception> public NIOFSDirectory(string path, LockFactory lockFactory) : this(new DirectoryInfo(path), lockFactory) { }
public MMapDirectory(System.IO.FileInfo path, LockFactory lockFactory):base(new System.IO.DirectoryInfo(path.FullName), lockFactory) { InitBlock(); }
/// <summary> /// Set the <see cref="Store.LockFactory"/> that this <see cref="Directory"/> instance should /// use for its locking implementation. Each * instance of /// <see cref="Store.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="Store.LockFactory"/>. </param> public abstract void SetLockFactory(LockFactory lockFactory);
public static FSDirectory GetDirectory(System.String path, LockFactory lockFactory) { return(GetDirectory(new System.IO.DirectoryInfo(path), lockFactory)); }