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.Core.InternalInterfaces.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 |
|
---|
29 | /// <summary>
|
---|
30 | /// The service locator for the server core
|
---|
31 | /// </summary>
|
---|
32 | public class ServiceLocator {
|
---|
33 | private static DiscoveryService discoveryService =
|
---|
34 | new DiscoveryService();
|
---|
35 |
|
---|
36 | private static ITransactionManager transManager = null;
|
---|
37 |
|
---|
38 | private static IClientManager clientManager = null;
|
---|
39 |
|
---|
40 | private static IJobManager jobManager = null;
|
---|
41 |
|
---|
42 | private static IUserRoleManager userRoleManager = null;
|
---|
43 |
|
---|
44 | private static IClientCommunicator clientCommunicator = null;
|
---|
45 |
|
---|
46 | private static ILifecycleManager lifecycleManager = null;
|
---|
47 |
|
---|
48 | private static IClientAdapter clientAdapter = null;
|
---|
49 |
|
---|
50 | private static IClientGroupAdapter clientGroupAdapter = null;
|
---|
51 |
|
---|
52 | private static IResourceAdapter resourceAdapter = null;
|
---|
53 |
|
---|
54 | private static IUserAdapter userAdapter = null;
|
---|
55 |
|
---|
56 | private static IUserGroupAdapter userGroupAdapter = null;
|
---|
57 |
|
---|
58 | private static IPermissionOwnerAdapter permOwnerAdapter = null;
|
---|
59 |
|
---|
60 | private static IJobAdapter jobAdapter = null;
|
---|
61 |
|
---|
62 | private static IJobResultsAdapter jobResultsAdapter = null;
|
---|
63 |
|
---|
64 | private static IScheduler scheduler = null;
|
---|
65 |
|
---|
66 |
|
---|
67 | /// <summary>
|
---|
68 | /// Gets the db transaction manager
|
---|
69 | /// </summary>
|
---|
70 | /// <returns></returns>
|
---|
71 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
72 | public static ITransactionManager GetTransactionManager() {
|
---|
73 | if (transManager == null) {
|
---|
74 | transManager = discoveryService.GetInstances<ITransactionManager>()[0];
|
---|
75 | }
|
---|
76 |
|
---|
77 | return transManager;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /// <summary>
|
---|
81 | /// Gets the client manager
|
---|
82 | /// </summary>
|
---|
83 | /// <returns></returns>
|
---|
84 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
85 | public static IClientManager GetClientManager() {
|
---|
86 | if (clientManager == null)
|
---|
87 | clientManager = new ClientManager();
|
---|
88 |
|
---|
89 | return clientManager;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /// <summary>
|
---|
93 | /// Gets the job manager
|
---|
94 | /// </summary>
|
---|
95 | /// <returns></returns>
|
---|
96 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
97 | public static IJobManager GetJobManager() {
|
---|
98 | if (jobManager == null)
|
---|
99 | jobManager = new JobManager();
|
---|
100 |
|
---|
101 | return jobManager;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /// <summary>
|
---|
105 | /// Gets the user role manager
|
---|
106 | /// </summary>
|
---|
107 | /// <returns></returns>
|
---|
108 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
109 | public static IUserRoleManager GetUserRoleManager() {
|
---|
110 | if (userRoleManager == null)
|
---|
111 | userRoleManager = new UserRoleManager();
|
---|
112 |
|
---|
113 | return userRoleManager;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /// <summary>
|
---|
117 | /// Gets the client Communicator
|
---|
118 | /// </summary>
|
---|
119 | /// <returns></returns>
|
---|
120 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
121 | public static IClientCommunicator GetClientCommunicator() {
|
---|
122 | if (clientCommunicator == null)
|
---|
123 | clientCommunicator = new ClientCommunicator();
|
---|
124 |
|
---|
125 | return clientCommunicator;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /// <summary>
|
---|
129 | /// Gets the lifecycle manager
|
---|
130 | /// </summary>
|
---|
131 | /// <returns></returns>
|
---|
132 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
133 | public static ILifecycleManager GetLifecycleManager() {
|
---|
134 | if (lifecycleManager == null) {
|
---|
135 | lifecycleManager = new LifecycleManager();
|
---|
136 | }
|
---|
137 |
|
---|
138 | return lifecycleManager;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /// <summary>
|
---|
142 | /// Gets the client database adapter
|
---|
143 | /// </summary>
|
---|
144 | /// <returns></returns>
|
---|
145 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
146 | public static IClientAdapter GetClientAdapter() {
|
---|
147 | if (clientAdapter == null) {
|
---|
148 | clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
|
---|
149 | }
|
---|
150 |
|
---|
151 | return clientAdapter;
|
---|
152 | }
|
---|
153 |
|
---|
154 | /// <summary>
|
---|
155 | /// Gets the client group database adapter
|
---|
156 | /// </summary>
|
---|
157 | /// <returns></returns>
|
---|
158 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
159 | public static IClientGroupAdapter GetClientGroupAdapter() {
|
---|
160 | if (clientGroupAdapter == null) {
|
---|
161 | clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
|
---|
162 | }
|
---|
163 |
|
---|
164 | return clientGroupAdapter;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /// <summary>
|
---|
168 | /// Gets the resource database adapter
|
---|
169 | /// </summary>
|
---|
170 | /// <returns></returns>
|
---|
171 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
172 | public static IResourceAdapter GetResourceAdapter() {
|
---|
173 | if (resourceAdapter == null) {
|
---|
174 | resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
|
---|
175 | }
|
---|
176 |
|
---|
177 | return resourceAdapter;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /// <summary>
|
---|
181 | /// Gets the user database adapter
|
---|
182 | /// </summary>
|
---|
183 | /// <returns></returns>
|
---|
184 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
185 | public static IUserAdapter GetUserAdapter() {
|
---|
186 | if (userAdapter == null) {
|
---|
187 | userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
|
---|
188 | }
|
---|
189 |
|
---|
190 | return userAdapter;
|
---|
191 | }
|
---|
192 |
|
---|
193 | /// <summary>
|
---|
194 | /// Gets the user group database adapter
|
---|
195 | /// </summary>
|
---|
196 | /// <returns></returns>
|
---|
197 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
198 | public static IUserGroupAdapter GetUserGroupAdapter() {
|
---|
199 | if (userGroupAdapter == null) {
|
---|
200 | userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
|
---|
201 | }
|
---|
202 |
|
---|
203 | return userGroupAdapter;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /// <summary>
|
---|
207 | /// Gets the permission owner database adapter
|
---|
208 | /// </summary>
|
---|
209 | /// <returns></returns>
|
---|
210 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
211 | public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
|
---|
212 | if (permOwnerAdapter == null) {
|
---|
213 | permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
|
---|
214 | }
|
---|
215 |
|
---|
216 | return permOwnerAdapter;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /// <summary>
|
---|
220 | /// Gets the job database adapter
|
---|
221 | /// </summary>
|
---|
222 | /// <returns></returns>
|
---|
223 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
224 | public static IJobAdapter GetJobAdapter() {
|
---|
225 | if (jobAdapter == null) {
|
---|
226 | jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0];
|
---|
227 | }
|
---|
228 |
|
---|
229 | return jobAdapter;
|
---|
230 | }
|
---|
231 |
|
---|
232 | /// <summary>
|
---|
233 | /// Gets the job results database adapter
|
---|
234 | /// </summary>
|
---|
235 | /// <returns></returns>
|
---|
236 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
237 | public static IJobResultsAdapter GetJobResultsAdapter() {
|
---|
238 | if (jobResultsAdapter == null) {
|
---|
239 | jobResultsAdapter = discoveryService.GetInstances<IJobResultsAdapter>()[0];
|
---|
240 | }
|
---|
241 |
|
---|
242 | return jobResultsAdapter;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /// <summary>
|
---|
246 | /// Gets the scheduler
|
---|
247 | /// </summary>
|
---|
248 | /// <returns></returns>
|
---|
249 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
250 | public static IScheduler GetScheduler() {
|
---|
251 | if (scheduler == null) {
|
---|
252 | scheduler = discoveryService.GetInstances<IScheduler>()[0];
|
---|
253 | }
|
---|
254 |
|
---|
255 | return scheduler;
|
---|
256 | }
|
---|
257 | } |
---|