Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1648 was 1648, checked in by mbecirov, 15 years ago

#586: Add permission constants and adopt server console

File size: 4.3 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  /// <summary>
54  /// Gets the client manager
55  /// </summary>
56  /// <returns></returns>
57  [MethodImpl(MethodImplOptions.Synchronized)]
58  public static IClientManager GetClientManager() {
59    if (clientManager == null)
60      clientManager = new ClientManager();
61
62    return clientManager;
63  }
64
65  /// <summary>
66  /// Gets the job manager
67  /// </summary>
68  /// <returns></returns>
69  [MethodImpl(MethodImplOptions.Synchronized)]
70  public static IJobManager GetJobManager() {
71    if (jobManager == null)
72      jobManager = new JobManager();
73
74    return jobManager;
75  }
76
77  /// <summary>
78  /// Gets the client Communicator
79  /// </summary>
80  /// <returns></returns>
81  [MethodImpl(MethodImplOptions.Synchronized)]
82  public static IClientCommunicator GetClientCommunicator() {
83    if (clientCommunicator == null)
84      clientCommunicator = new ClientCommunicator();
85
86    return clientCommunicator;
87  }
88
89  /// <summary>
90  /// Gets the lifecycle manager
91  /// </summary>
92  /// <returns></returns>
93  [MethodImpl(MethodImplOptions.Synchronized)]
94  public static ILifecycleManager GetLifecycleManager() {
95    if (lifecycleManager == null) {
96      lifecycleManager = new LifecycleManager();
97    }
98
99    return lifecycleManager;
100  }
101
102  /// <summary>
103  /// Gets the db session factory
104  /// </summary>
105  /// <returns></returns>
106  [MethodImpl(MethodImplOptions.Synchronized)]
107  public static ISessionFactory GetSessionFactory() {
108    if (sessionFactory == null) {
109      sessionFactory =
110        discoveryService.GetInstances<ISessionFactory>()[0];
111
112      sessionFactory.DbConnectionType =
113        typeof(SqlConnection);
114     
115      sessionFactory.DbConnectionString =
116        HeuristicLab.Hive.Server.Core.Properties.Settings.Default.HiveServerConnectionString;
117    }
118
119    return sessionFactory;
120  }
121
122  /// <summary>
123  /// Gets the scheduler
124  /// </summary>
125  /// <returns></returns>
126  [MethodImpl(MethodImplOptions.Synchronized)]
127  public static IScheduler GetScheduler() {
128    if (scheduler == null) {
129      scheduler = discoveryService.GetInstances<IScheduler>()[0];
130    }
131
132    return scheduler;
133  }
134
135  /// <summary>
136  /// Gets the permission manager
137  /// </summary>
138  /// <returns></returns>
139  [MethodImpl(MethodImplOptions.Synchronized)] 
140  public static IPermissionManager GetPermissionManager() {
141    if (permManager == null)
142      permManager = discoveryService.GetInstances<IPermissionManager>()[0];
143    return permManager;
144   
145  }
146}
Note: See TracBrowser for help on using the repository browser.