WindowsHpcSchedulerFactory.cs 2.03 KB
Newer Older
Vaclav Svaton's avatar
Vaclav Svaton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
using System.Collections.Generic;
using HaaSMiddleware.ConnectionPool;
using HaaSMiddleware.DomainObjects.ClusterInformation;
using HaaSMiddleware.HpcConnectionFramework.WindowsHpc.ConversionAdapter;

namespace HaaSMiddleware.HpcConnectionFramework.WindowsHpc {
	public class WindowsHpcSchedulerFactory : SchedulerFactory {
		#region SchedulerFactory Members
		public override IRexScheduler CreateScheduler(Cluster configuration) {
			if (!windowsHpcSchedulerSingletons.ContainsKey(configuration.MasterNodeName))
				windowsHpcSchedulerSingletons[configuration.MasterNodeName] = new RexSchedulerWrapper(
					GetSchedulerConnectionPool(configuration), CreateSchedulerAdapter());
			return windowsHpcSchedulerSingletons[configuration.MasterNodeName];
		}

		protected override ISchedulerAdapter CreateSchedulerAdapter() {
			if (windowsHpcSchedulerAdapterInstance == null)
				windowsHpcSchedulerAdapterInstance = new WindowsHpcSchedulerAdapter(CreateDataConvertor());
			return windowsHpcSchedulerAdapterInstance;
		}

		protected override ISchedulerDataConvertor CreateDataConvertor() {
			if (windowsHpcConvertorSingleton == null)
				windowsHpcConvertorSingleton = new WindowsHpcDataConvertor(new WindowsHpcConversionAdapterFactory());
			return windowsHpcConvertorSingleton;
		}

		protected override IPoolableAdapter CreateSchedulerConnector(Cluster configuration) {
			if (!windowsHpcConnectorSingletons.ContainsKey(configuration.MasterNodeName))
				windowsHpcConnectorSingletons[configuration.MasterNodeName] = new WindowsHpcAPIConnector();
			return windowsHpcConnectorSingletons[configuration.MasterNodeName];
		}
		#endregion

		#region Instance Fields
		private readonly Dictionary<string, IPoolableAdapter> windowsHpcConnectorSingletons =
			new Dictionary<string, IPoolableAdapter>();

		private readonly Dictionary<string, IRexScheduler> windowsHpcSchedulerSingletons = new Dictionary<string, IRexScheduler>();
		private ISchedulerDataConvertor windowsHpcConvertorSingleton;
		private ISchedulerAdapter windowsHpcSchedulerAdapterInstance;
		#endregion
	}
}