Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/ServiceLocator.cs @ 4092

Last change on this file since 4092 was 4092, checked in by cneumuel, 14 years ago

replaced transaction- and context management from Spring-advice by custom context management (see ContextFactory) (#1098)

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