Skip to content
Snippets Groups Projects
FileSystemFactory.cs 2.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Vaclav Svaton's avatar
    Vaclav Svaton committed
    using System;
    using System.Collections.Generic;
    using HaaSMiddleware.ConnectionPool;
    using HaaSMiddleware.DomainObjects.ClusterInformation;
    using HaaSMiddleware.DomainObjects.FileTransfer;
    using HaaSMiddleware.FileTransferFramework.NetworkShare;
    using HaaSMiddleware.FileTransferFramework.Sftp;
    
    namespace HaaSMiddleware.FileTransferFramework {
    	public abstract class FileSystemFactory {
    		#region Instantiation
    		private static FileSystemFactory windowsSharedFactorySingleton;
    		private static FileSystemFactory sftpFactorySingleton;
    
    		public static FileSystemFactory GetInstance(FileTransferProtocol type) {
    			switch (type) {
    				case FileTransferProtocol.NetworkShare:
    					if (windowsSharedFactorySingleton == null)
    						windowsSharedFactorySingleton = new NetworkShareFileSystemFactory();
    					return windowsSharedFactorySingleton;
    				case FileTransferProtocol.SftpScp:
    					if (sftpFactorySingleton == null)
    						sftpFactorySingleton = new SftpFileSystemFactory();
    					return sftpFactorySingleton;
    			}
    			throw new ApplicationException("File system manager factory with type \"" + type + "\" does not exist.");
    		}
    		#endregion
    
    		#region Abstract Methods
    		public abstract IRexFileSystemManager CreateFileSystemManager(FileTransferMethod configuration);
    		internal abstract IFileSynchronizer CreateFileSynchronizer(FullFileSpecification syncFile, ClusterAuthenticationCredentials credentials);
    		protected abstract IPoolableAdapter CreateFileSystemConnector(FileTransferMethod configuration);
    		#endregion
    
    		#region Local Methods
    		protected IConnectionPool GetSchedulerConnectionPool(FileTransferMethod configuration) {
    			if (!schedulerConnectionPoolSingletons.ContainsKey(configuration)) {
    				schedulerConnectionPoolSingletons[configuration] = new ConnectionPool.ConnectionPool(
    					configuration.ServerHostname,
    					FileTransferFrameworkSettings.Default.ConnectionPoolMinSize,
    					FileTransferFrameworkSettings.Default.ConnectionPoolMaxSize,
    					FileTransferFrameworkSettings.Default.ConnectionPoolCleaningInterval,
    					FileTransferFrameworkSettings.Default.ConnectionPoolMaxUnusedInterval,
    					CreateFileSystemConnector(configuration));
    			}
    			return schedulerConnectionPoolSingletons[configuration];
    		}
    		#endregion
    
    		#region Instance Fields
    		private readonly Dictionary<FileTransferMethod, IConnectionPool> schedulerConnectionPoolSingletons =
    			new Dictionary<FileTransferMethod, IConnectionPool>();
    		#endregion
    	}
    }