Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/ServiceLocator.cs @ 1088

Last change on this file since 1088 was 1088, checked in by msteinbi, 15 years ago

Started implementation of Lifecycle Management for CLient Communicator (#453)

File size: 5.4 KB
Line 
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
22using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
23using HeuristicLab.PluginInfrastructure;
24using System.Runtime.CompilerServices;
25using HeuristicLab.Hive.Contracts.Interfaces;
26
27/// <summary>
28/// The service locator for the server core
29/// </summary>
30public class ServiceLocator {
31  private static DiscoveryService discoveryService =
32    new DiscoveryService();
33
34  private static ITransactionManager transManager = null;
35
36  private static IClientAdapter clientAdapter = null;
37
38  private static IClientGroupAdapter clientGroupAdapter = null;
39
40  private static IResourceAdapter resourceAdapter = null;
41
42  private static IUserAdapter userAdapter = null;
43
44  private static IUserGroupAdapter userGroupAdapter = null;
45
46  private static IPermissionOwnerAdapter permOwnerAdapter = null;
47
48  private static IJobAdapter jobAdapter = null;
49
50  private static IJobResultsAdapter jobResultsAdapter = null;
51
52  private static ILifecycleManager lifecycleManager = null;
53
54  /// <summary>
55  /// Gets the db transaction manager
56  /// </summary>
57  /// <returns></returns>
58  [MethodImpl(MethodImplOptions.Synchronized)]
59  public static ITransactionManager GetTransactionManager() {
60    if (transManager == null) {
61      transManager = discoveryService.GetInstances<ITransactionManager>()[0];
62    }
63
64    return transManager;
65  }
66
67  /// <summary>
68  /// Gets the client database adapter
69  /// </summary>
70  /// <returns></returns>
71  [MethodImpl(MethodImplOptions.Synchronized)]
72  public static IClientAdapter GetClientAdapter() {
73    if (clientAdapter == null) {
74      clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
75    }
76
77    return clientAdapter;
78  }
79
80  /// <summary>
81  /// Gets the client group database adapter
82  /// </summary>
83  /// <returns></returns>
84  [MethodImpl(MethodImplOptions.Synchronized)]
85  public static IClientGroupAdapter GetClientGroupAdapter() {
86    if (clientGroupAdapter == null) {
87      clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
88    }
89
90    return clientGroupAdapter;
91  }
92
93  /// <summary>
94  /// Gets the resource database adapter
95  /// </summary>
96  /// <returns></returns>
97  [MethodImpl(MethodImplOptions.Synchronized)]
98  public static IResourceAdapter GetResourceAdapter() {
99    if (resourceAdapter == null) {
100      resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
101    }
102
103    return resourceAdapter;
104  }
105
106  /// <summary>
107  /// Gets the user database adapter
108  /// </summary>
109  /// <returns></returns>
110  [MethodImpl(MethodImplOptions.Synchronized)]
111  public static IUserAdapter GetUserAdapter() {
112    if (userAdapter == null) {
113      userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
114    }
115
116    return userAdapter;
117  }
118
119  /// <summary>
120  /// Gets the user group database adapter
121  /// </summary>
122  /// <returns></returns>
123  [MethodImpl(MethodImplOptions.Synchronized)]
124  public static IUserGroupAdapter GetUserGroupAdapter() {
125    if (userGroupAdapter == null) {
126      userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
127    }
128
129    return userGroupAdapter;
130  }
131
132  /// <summary>
133  /// Gets the permission owner database adapter
134  /// </summary>
135  /// <returns></returns>
136  [MethodImpl(MethodImplOptions.Synchronized)]
137  public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
138    if (permOwnerAdapter == null) {
139      permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
140    }
141
142    return permOwnerAdapter;
143  }
144
145  /// <summary>
146  /// Gets the job database adapter
147  /// </summary>
148  /// <returns></returns>
149  [MethodImpl(MethodImplOptions.Synchronized)]
150  public static IJobAdapter GetJobAdapter() {
151    if (jobAdapter == null) {
152      jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0];
153    }
154
155    return jobAdapter;
156  }
157
158  /// <summary>
159  /// Gets the job results database adapter
160  /// </summary>
161  /// <returns></returns>
162  [MethodImpl(MethodImplOptions.Synchronized)]
163  public static IJobResultsAdapter GetJobResultsAdapter() {
164    if (jobResultsAdapter == null) {
165      jobResultsAdapter = discoveryService.GetInstances<IJobResultsAdapter>()[0];
166    }
167
168    return jobResultsAdapter;
169  }
170
171  /// <summary>
172  /// Gets the lifecycle manager
173  /// </summary>
174  /// <returns></returns>
175  [MethodImpl(MethodImplOptions.Synchronized)]
176  public static ILifecycleManager GetLifecycleManager() {
177    if (lifecycleManager == null) {
178      lifecycleManager = discoveryService.GetInstances<ILifecycleManager>()[0];
179    }
180
181    return lifecycleManager;
182  }
183}
Note: See TracBrowser for help on using the repository browser.