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 |
|
---|
22 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
23 | using HeuristicLab.PluginInfrastructure;
|
---|
24 | using System.Runtime.CompilerServices;
|
---|
25 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
26 | using HeuristicLab.Hive.Server.Core;
|
---|
27 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
28 | using HeuristicLab.DataAccess.Interfaces;
|
---|
29 |
|
---|
30 | /// <summary>
|
---|
31 | /// The service locator for the server core
|
---|
32 | /// </summary>
|
---|
33 | public class ServiceLocator {
|
---|
34 | private static DiscoveryService discoveryService =
|
---|
35 | new DiscoveryService();
|
---|
36 |
|
---|
37 | private static IDBSynchronizer transManager = null;
|
---|
38 |
|
---|
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 |
|
---|
47 | private static IClientAdapter clientAdapter = null;
|
---|
48 |
|
---|
49 | private static IClientGroupAdapter clientGroupAdapter = null;
|
---|
50 |
|
---|
51 | private static IResourceAdapter resourceAdapter = null;
|
---|
52 |
|
---|
53 | private static IJobAdapter jobAdapter = null;
|
---|
54 |
|
---|
55 | private static IJobResultsAdapter jobResultsAdapter = null;
|
---|
56 |
|
---|
57 | private static IScheduler scheduler = null;
|
---|
58 |
|
---|
59 |
|
---|
60 | /// <summary>
|
---|
61 | /// Gets the db transaction manager
|
---|
62 | /// </summary>
|
---|
63 | /// <returns></returns>
|
---|
64 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
65 | public static IDBSynchronizer GetDBSynchronizer() {
|
---|
66 | if (transManager == null) {
|
---|
67 | transManager = discoveryService.GetInstances<IDBSynchronizer>()[0];
|
---|
68 | }
|
---|
69 |
|
---|
70 | return transManager;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /// <summary>
|
---|
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>
|
---|
123 | /// Gets the client database adapter
|
---|
124 | /// </summary>
|
---|
125 | /// <returns></returns>
|
---|
126 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
127 | public static IClientAdapter GetClientAdapter() {
|
---|
128 | if (clientAdapter == null) {
|
---|
129 | clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
|
---|
130 | }
|
---|
131 |
|
---|
132 | return clientAdapter;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /// <summary>
|
---|
136 | /// Gets the client group database adapter
|
---|
137 | /// </summary>
|
---|
138 | /// <returns></returns>
|
---|
139 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
140 | public static IClientGroupAdapter GetClientGroupAdapter() {
|
---|
141 | if (clientGroupAdapter == null) {
|
---|
142 | clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
|
---|
143 | }
|
---|
144 |
|
---|
145 | return clientGroupAdapter;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /// <summary>
|
---|
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>
|
---|
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 | }
|
---|
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 | }
|
---|
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 | }
|
---|
199 | } |
---|