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

Last change on this file since 962 was 962, checked in by svonolfe, 12 years ago

Added job adapter to service locator (#372)

File size: 4.6 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  /// <summary>
51  /// Gets the db transaction manager
52  /// </summary>
53  /// <returns></returns>
54  [MethodImpl(MethodImplOptions.Synchronized)]
55  public static ITransactionManager GetTransactionManager() {
56    if (transManager == null) {
57      transManager = discoveryService.GetInstances<ITransactionManager>()[0];
58    }
59
60    return transManager;
61  }
62
63  /// <summary>
64  /// Gets the client database adapter
65  /// </summary>
66  /// <returns></returns>
67  [MethodImpl(MethodImplOptions.Synchronized)]
68  public static IClientAdapter GetClientAdapter() {
69    if (clientAdapter == null) {
70      clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
71    }
72
73    return clientAdapter;
74  }
75
76  /// <summary>
77  /// Gets the client group database adapter
78  /// </summary>
79  /// <returns></returns>
80  [MethodImpl(MethodImplOptions.Synchronized)]
81  public static IClientGroupAdapter GetClientGroupAdapter() {
82    if (clientGroupAdapter == null) {
83      clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
84    }
85
86    return clientGroupAdapter;
87  }
88
89  /// <summary>
90  /// Gets the resource database adapter
91  /// </summary>
92  /// <returns></returns>
93  [MethodImpl(MethodImplOptions.Synchronized)]
94  public static IResourceAdapter GetResourceAdapter() {
95    if (resourceAdapter == null) {
96      resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
97    }
98
99    return resourceAdapter;
100  }
101
102  /// <summary>
103  /// Gets the user database adapter
104  /// </summary>
105  /// <returns></returns>
106  [MethodImpl(MethodImplOptions.Synchronized)]
107  public static IUserAdapter GetUserAdapter() {
108    if (userAdapter == null) {
109      userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
110    }
111
112    return userAdapter;
113  }
114
115  /// <summary>
116  /// Gets the user group database adapter
117  /// </summary>
118  /// <returns></returns>
119  [MethodImpl(MethodImplOptions.Synchronized)]
120  public static IUserGroupAdapter GetUserGroupAdapter() {
121    if (userGroupAdapter == null) {
122      userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
123    }
124
125    return userGroupAdapter;
126  }
127
128  /// <summary>
129  /// Gets the permission owner database adapter
130  /// </summary>
131  /// <returns></returns>
132  [MethodImpl(MethodImplOptions.Synchronized)]
133  public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
134    if (permOwnerAdapter == null) {
135      permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
136    }
137
138    return permOwnerAdapter;
139  }
140
141  /// <summary>
142  /// Gets the job database adapter
143  /// </summary>
144  /// <returns></returns>
145  [MethodImpl(MethodImplOptions.Synchronized)]
146  public static IJobAdapter GetJobAdapter() {
147    if (jobAdapter == null) {
148      jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0];
149    }
150
151    return jobAdapter;
152  }
153}
Note: See TracBrowser for help on using the repository browser.