Exemplo n.º 1
0
		/// <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 Mono.Lucene.Net
				//return new NIOFSDirectory(path, lockFactory);
                return new SimpleFSDirectory(path, lockFactory);
			}
        }
Exemplo n.º 2
0
		/* 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 Mono.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("Mono.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);
				}
			}
		}
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
		 // 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;
		}
Exemplo n.º 5
0
 /// <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();
 }
Exemplo n.º 6
0
		/// <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());
		}
Exemplo n.º 7
0
 public SimpleFSDirectory(System.IO.FileInfo path, LockFactory lockFactory) : base(new System.IO.DirectoryInfo(path.FullName), lockFactory)
 {
 }
Exemplo n.º 8
0
 public NIOFSDirectory(System.IO.DirectoryInfo dir, LockFactory lockFactory)
 {
 }
Exemplo n.º 9
0
 public static FSDirectory GetDirectory(System.IO.FileInfo file, LockFactory lockFactory)
 {
     return(GetDirectory(new System.IO.DirectoryInfo(file.FullName), lockFactory));
 }
Exemplo n.º 10
0
        /* 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 Mono.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("Mono.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);
                }
            }
        }
Exemplo n.º 11
0
 public static FSDirectory GetDirectory(System.String path, LockFactory lockFactory)
 {
     return(GetDirectory(new System.IO.DirectoryInfo(path), lockFactory));
 }
Exemplo n.º 12
0
 /// <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)
 {
 }
Exemplo n.º 13
0
		public SimpleFSDirectory(System.IO.FileInfo path, LockFactory lockFactory):base(new System.IO.DirectoryInfo(path.FullName), lockFactory)
		{
		}
Exemplo n.º 14
0
 public MMapDirectory(System.IO.FileInfo path, LockFactory lockFactory) : base(new System.IO.DirectoryInfo(path.FullName), lockFactory)
 {
     InitBlock();
 }
Exemplo n.º 15
0
 /// <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)
 {
 }
Exemplo n.º 16
0
 /// <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();
 }
Exemplo n.º 17
0
		public static FSDirectory GetDirectory(System.String path, LockFactory lockFactory)
		{
			return GetDirectory(new System.IO.DirectoryInfo(path), lockFactory);
		}
Exemplo n.º 18
0
		public MMapDirectory(System.IO.FileInfo path, LockFactory lockFactory):base(new System.IO.DirectoryInfo(path.FullName), lockFactory)
		{
			InitBlock();
		}
Exemplo n.º 19
0
		public static FSDirectory GetDirectory(System.IO.FileInfo file, LockFactory lockFactory)
		{
            return GetDirectory(new System.IO.DirectoryInfo(file.FullName), lockFactory);
		}
Exemplo n.º 20
0
		/// <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;
		}
Exemplo n.º 21
0
 public NIOFSDirectory(System.IO.DirectoryInfo dir,LockFactory lockFactory)
 {
 }