Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2476 was 1768, checked in by mbecirov, 16 years ago

#586 extended the interface for HivePermissionManager

File size: 4.7 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.DataAccess;
23using HeuristicLab.PluginInfrastructure;
24using System.Runtime.CompilerServices;
25using HeuristicLab.Hive.Contracts.Interfaces;
26using HeuristicLab.Hive.Server.Core;
27using HeuristicLab.Hive.Server.Core.InternalInterfaces;
28using HeuristicLab.DataAccess.Interfaces;
29using System.Data.SqlClient;
30using HeuristicLab.Security.Contracts.Interfaces;
31
32/// <summary>
33/// The service locator for the server core
34/// </summary>
35public class ServiceLocator {
36  private static DiscoveryService discoveryService =
37    new DiscoveryService();
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 ISessionFactory sessionFactory = null;
48
49  private static IScheduler scheduler = null;
50
51  private static IPermissionManager permManager = null;
52
53  private static IHivePermissionManager hivePermManager = null;
54
55  /// <summary>
56  /// Gets the client manager
57  /// </summary>
58  /// <returns></returns>
59  [MethodImpl(MethodImplOptions.Synchronized)]
60  public static IClientManager GetClientManager() {
61    if (clientManager == null)
62      clientManager = new ClientManager();
63
64    return clientManager;
65  }
66
67  /// <summary>
68  /// Gets the job manager
69  /// </summary>
70  /// <returns></returns>
71  [MethodImpl(MethodImplOptions.Synchronized)]
72  public static IJobManager GetJobManager() {
73    if (jobManager == null)
74      jobManager = new JobManager();
75
76    return jobManager;
77  }
78
79  /// <summary>
80  /// Gets the client Communicator
81  /// </summary>
82  /// <returns></returns>
83  [MethodImpl(MethodImplOptions.Synchronized)]
84  public static IClientCommunicator GetClientCommunicator() {
85    if (clientCommunicator == null)
86      clientCommunicator = new ClientCommunicator();
87
88    return clientCommunicator;
89  }
90
91  /// <summary>
92  /// Gets the lifecycle manager
93  /// </summary>
94  /// <returns></returns>
95  [MethodImpl(MethodImplOptions.Synchronized)]
96  public static ILifecycleManager GetLifecycleManager() {
97    if (lifecycleManager == null) {
98      lifecycleManager = new LifecycleManager();
99    }
100    return lifecycleManager;
101  }
102
103  /// <summary>
104  /// Gets the db session factory
105  /// </summary>
106  /// <returns></returns>
107  [MethodImpl(MethodImplOptions.Synchronized)]
108  public static ISessionFactory GetSessionFactory() {
109    if (sessionFactory == null) {
110      sessionFactory =
111        discoveryService.GetInstances<ISessionFactory>()[0];
112
113      sessionFactory.DbConnectionType =
114        typeof(SqlConnection);
115     
116      sessionFactory.DbConnectionString =
117        HeuristicLab.Hive.Server.Core.Properties.Settings.Default.HiveServerConnectionString;
118    }
119
120    return sessionFactory;
121  }
122
123  /// <summary>
124  /// Gets the scheduler
125  /// </summary>
126  /// <returns></returns>
127  [MethodImpl(MethodImplOptions.Synchronized)]
128  public static IScheduler GetScheduler() {
129    if (scheduler == null) {
130      scheduler = discoveryService.GetInstances<IScheduler>()[0];
131    }
132
133    return scheduler;
134  }
135
136  /// <summary>
137  /// Gets the permission manager
138  /// </summary>
139  /// <returns></returns>
140  [MethodImpl(MethodImplOptions.Synchronized)] 
141  public static IPermissionManager GetPermissionManager() {
142    if (permManager == null)
143      permManager = discoveryService.GetInstances<IPermissionManager>()[0];
144    return permManager;
145   
146  }
147
148  /// <summary>
149  /// Gets the permission manager
150  /// </summary>
151  /// <returns></returns>
152  [MethodImpl(MethodImplOptions.Synchronized)]
153  public static IHivePermissionManager GetHivePermissionManager() {
154    if (hivePermManager == null)
155      hivePermManager = discoveryService.GetInstances<IHivePermissionManager>()[0];
156    return hivePermManager;
157
158  }
159}
Note: See TracBrowser for help on using the repository browser.