[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;
|
---|
[826] | 29 |
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// The service locator for the server core
|
---|
| 32 | /// </summary>
|
---|
[925] | 33 | public class ServiceLocator {
|
---|
[826] | 34 | private static DiscoveryService discoveryService =
|
---|
| 35 | new DiscoveryService();
|
---|
| 36 |
|
---|
[1377] | 37 | private static IDBSynchronizer transManager = null;
|
---|
[925] | 38 |
|
---|
[1099] | 39 | private static IClientManager clientManager = null;
|
---|
| 40 |
|
---|
| 41 | private static IJobManager jobManager = null;
|
---|
| 42 |
|
---|
| 43 | private static IClientCommunicator clientCommunicator = null;
|
---|
| 44 |
|
---|
| 45 | private static ILifecycleManager lifecycleManager = null;
|
---|
| 46 |
|
---|
[826] | 47 | private static IClientAdapter clientAdapter = null;
|
---|
[899] | 48 |
|
---|
[910] | 49 | private static IClientGroupAdapter clientGroupAdapter = null;
|
---|
| 50 |
|
---|
[925] | 51 | private static IResourceAdapter resourceAdapter = null;
|
---|
| 52 |
|
---|
[962] | 53 | private static IJobAdapter jobAdapter = null;
|
---|
| 54 |
|
---|
[1005] | 55 | private static IJobResultsAdapter jobResultsAdapter = null;
|
---|
| 56 |
|
---|
[1272] | 57 | private static IScheduler scheduler = null;
|
---|
[1088] | 58 |
|
---|
[1272] | 59 |
|
---|
[826] | 60 | /// <summary>
|
---|
[925] | 61 | /// Gets the db transaction manager
|
---|
| 62 | /// </summary>
|
---|
| 63 | /// <returns></returns>
|
---|
| 64 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[1377] | 65 | public static IDBSynchronizer GetDBSynchronizer() {
|
---|
[925] | 66 | if (transManager == null) {
|
---|
[1377] | 67 | transManager = discoveryService.GetInstances<IDBSynchronizer>()[0];
|
---|
[925] | 68 | }
|
---|
| 69 |
|
---|
| 70 | return transManager;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /// <summary>
|
---|
[1099] | 74 | /// Gets the client manager
|
---|
| 75 | /// </summary>
|
---|
| 76 | /// <returns></returns>
|
---|
| 77 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 78 | public static IClientManager GetClientManager() {
|
---|
| 79 | if (clientManager == null)
|
---|
| 80 | clientManager = new ClientManager();
|
---|
| 81 |
|
---|
| 82 | return clientManager;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /// <summary>
|
---|
| 86 | /// Gets the job manager
|
---|
| 87 | /// </summary>
|
---|
| 88 | /// <returns></returns>
|
---|
| 89 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 90 | public static IJobManager GetJobManager() {
|
---|
| 91 | if (jobManager == null)
|
---|
| 92 | jobManager = new JobManager();
|
---|
| 93 |
|
---|
| 94 | return jobManager;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /// <summary>
|
---|
| 98 | /// Gets the client Communicator
|
---|
| 99 | /// </summary>
|
---|
| 100 | /// <returns></returns>
|
---|
| 101 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 102 | public static IClientCommunicator GetClientCommunicator() {
|
---|
| 103 | if (clientCommunicator == null)
|
---|
| 104 | clientCommunicator = new ClientCommunicator();
|
---|
| 105 |
|
---|
| 106 | return clientCommunicator;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /// <summary>
|
---|
| 110 | /// Gets the lifecycle manager
|
---|
| 111 | /// </summary>
|
---|
| 112 | /// <returns></returns>
|
---|
| 113 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 114 | public static ILifecycleManager GetLifecycleManager() {
|
---|
| 115 | if (lifecycleManager == null) {
|
---|
| 116 | lifecycleManager = new LifecycleManager();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | return lifecycleManager;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /// <summary>
|
---|
[826] | 123 | /// Gets the client database adapter
|
---|
| 124 | /// </summary>
|
---|
| 125 | /// <returns></returns>
|
---|
[925] | 126 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 127 | public static IClientAdapter GetClientAdapter() {
|
---|
[826] | 128 | if (clientAdapter == null) {
|
---|
| 129 | clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | return clientAdapter;
|
---|
| 133 | }
|
---|
[899] | 134 |
|
---|
| 135 | /// <summary>
|
---|
[910] | 136 | /// Gets the client group database adapter
|
---|
| 137 | /// </summary>
|
---|
| 138 | /// <returns></returns>
|
---|
[925] | 139 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 140 | public static IClientGroupAdapter GetClientGroupAdapter() {
|
---|
[910] | 141 | if (clientGroupAdapter == null) {
|
---|
| 142 | clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | return clientGroupAdapter;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /// <summary>
|
---|
[925] | 149 | /// Gets the resource database adapter
|
---|
| 150 | /// </summary>
|
---|
| 151 | /// <returns></returns>
|
---|
| 152 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 153 | public static IResourceAdapter GetResourceAdapter() {
|
---|
| 154 | if (resourceAdapter == null) {
|
---|
| 155 | resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | return resourceAdapter;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /// <summary>
|
---|
[962] | 162 | /// Gets the job database adapter
|
---|
| 163 | /// </summary>
|
---|
| 164 | /// <returns></returns>
|
---|
| 165 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 166 | public static IJobAdapter GetJobAdapter() {
|
---|
| 167 | if (jobAdapter == null) {
|
---|
| 168 | jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0];
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | return jobAdapter;
|
---|
| 172 | }
|
---|
[1005] | 173 |
|
---|
| 174 | /// <summary>
|
---|
| 175 | /// Gets the job results database adapter
|
---|
| 176 | /// </summary>
|
---|
| 177 | /// <returns></returns>
|
---|
| 178 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 179 | public static IJobResultsAdapter GetJobResultsAdapter() {
|
---|
| 180 | if (jobResultsAdapter == null) {
|
---|
| 181 | jobResultsAdapter = discoveryService.GetInstances<IJobResultsAdapter>()[0];
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | return jobResultsAdapter;
|
---|
| 185 | }
|
---|
[1272] | 186 |
|
---|
| 187 | /// <summary>
|
---|
| 188 | /// Gets the scheduler
|
---|
| 189 | /// </summary>
|
---|
| 190 | /// <returns></returns>
|
---|
| 191 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
| 192 | public static IScheduler GetScheduler() {
|
---|
| 193 | if (scheduler == null) {
|
---|
| 194 | scheduler = discoveryService.GetInstances<IScheduler>()[0];
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | return scheduler;
|
---|
| 198 | }
|
---|
[826] | 199 | } |
---|