[826] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[1377] | 22 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[826] | 23 | using HeuristicLab.PluginInfrastructure;
|
---|
[925] | 24 | using System.Runtime.CompilerServices;
|
---|
[948] | 25 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
[1099] | 26 | using HeuristicLab.Hive.Server.Core;
|
---|
[1272] | 27 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
[1377] | 28 | using HeuristicLab.DataAccess.Interfaces;
|
---|
[1468] | 29 | using System.Data.SqlClient;
|
---|
[826] | 30 |
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// The service locator for the server core
|
---|
| 33 | /// </summary>
|
---|
[925] | 34 | public class ServiceLocator {
|
---|
[826] | 35 | private static DiscoveryService discoveryService =
|
---|
| 36 | new DiscoveryService();
|
---|
| 37 |
|
---|
[1099] | 38 | private static IClientManager clientManager = null;
|
---|
| 39 |
|
---|
| 40 | private static IJobManager jobManager = null;
|
---|
| 41 |
|
---|
| 42 | private static IClientCommunicator clientCommunicator = null;
|
---|
| 43 |
|
---|
| 44 | private static ILifecycleManager lifecycleManager = null;
|
---|
| 45 |
|
---|
[1468] | 46 | private static ISessionFactory sessionFactory = null;
|
---|
[899] | 47 |
|
---|
[1272] | 48 | private static IScheduler scheduler = null;
|
---|
[1088] | 49 |
|
---|
[826] | 50 | /// <summary>
|
---|
[1099] | 51 | /// Gets the client manager
|
---|
| 52 | /// </summary>
|
---|
| 53 | /// <returns></returns>
|
---|
| 54 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 55 | public static IClientManager GetClientManager() {
|
---|
| 56 | if (clientManager == null)
|
---|
| 57 | clientManager = new ClientManager();
|
---|
| 58 |
|
---|
| 59 | return clientManager;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /// <summary>
|
---|
| 63 | /// Gets the job manager
|
---|
| 64 | /// </summary>
|
---|
| 65 | /// <returns></returns>
|
---|
| 66 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 67 | public static IJobManager GetJobManager() {
|
---|
| 68 | if (jobManager == null)
|
---|
| 69 | jobManager = new JobManager();
|
---|
| 70 |
|
---|
| 71 | return jobManager;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | /// <summary>
|
---|
| 75 | /// Gets the client Communicator
|
---|
| 76 | /// </summary>
|
---|
| 77 | /// <returns></returns>
|
---|
| 78 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 79 | public static IClientCommunicator GetClientCommunicator() {
|
---|
| 80 | if (clientCommunicator == null)
|
---|
| 81 | clientCommunicator = new ClientCommunicator();
|
---|
| 82 |
|
---|
| 83 | return clientCommunicator;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /// <summary>
|
---|
| 87 | /// Gets the lifecycle manager
|
---|
| 88 | /// </summary>
|
---|
| 89 | /// <returns></returns>
|
---|
| 90 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 91 | public static ILifecycleManager GetLifecycleManager() {
|
---|
| 92 | if (lifecycleManager == null) {
|
---|
| 93 | lifecycleManager = new LifecycleManager();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | return lifecycleManager;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /// <summary>
|
---|
[1468] | 100 | /// Gets the db session factory
|
---|
[826] | 101 | /// </summary>
|
---|
| 102 | /// <returns></returns>
|
---|
[925] | 103 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[1468] | 104 | public static ISessionFactory GetSessionFactory() {
|
---|
| 105 | if (sessionFactory == null) {
|
---|
| 106 | sessionFactory =
|
---|
| 107 | discoveryService.GetInstances<ISessionFactory>()[0];
|
---|
[826] | 108 |
|
---|
[1468] | 109 | sessionFactory.DbConnectionType =
|
---|
| 110 | typeof(SqlConnection);
|
---|
| 111 |
|
---|
| 112 | sessionFactory.DbConnectionString =
|
---|
| 113 | HeuristicLab.Hive.Server.Core.Properties.Settings.Default.HiveServerConnectionString;
|
---|
[910] | 114 | }
|
---|
| 115 |
|
---|
[1468] | 116 | return sessionFactory;
|
---|
[910] | 117 | }
|
---|
| 118 |
|
---|
| 119 | /// <summary>
|
---|
[1272] | 120 | /// Gets the scheduler
|
---|
| 121 | /// </summary>
|
---|
| 122 | /// <returns></returns>
|
---|
| 123 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 124 | public static IScheduler GetScheduler() {
|
---|
| 125 | if (scheduler == null) {
|
---|
| 126 | scheduler = discoveryService.GetInstances<IScheduler>()[0];
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | return scheduler;
|
---|
| 130 | }
|
---|
[826] | 131 | } |
---|