Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1468 was 1468, checked in by svonolfe, 15 years ago

Added transaction management (#527)

File size: 3.8 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;
30
31/// <summary>
32/// The service locator for the server core
33/// </summary>
34public class ServiceLocator {
35  private static DiscoveryService discoveryService =
36    new DiscoveryService();
37
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  /// <summary>
51  /// Gets the client manager
52  /// </summary>
53  /// <returns></returns>
54  [MethodImpl(MethodImplOptions.Synchronized)]
55  public static IClientManager GetClientManager() {
56    if (clientManager == null)
57      clientManager = new ClientManager();
58
59    return clientManager;
60  }
61
62  /// <summary>
63  /// Gets the job manager
64  /// </summary>
65  /// <returns></returns>
66  [MethodImpl(MethodImplOptions.Synchronized)]
67  public static IJobManager GetJobManager() {
68    if (jobManager == null)
69      jobManager = new JobManager();
70
71    return jobManager;
72  }
73
74  /// <summary>
75  /// Gets the client Communicator
76  /// </summary>
77  /// <returns></returns>
78  [MethodImpl(MethodImplOptions.Synchronized)]
79  public static IClientCommunicator GetClientCommunicator() {
80    if (clientCommunicator == null)
81      clientCommunicator = new ClientCommunicator();
82
83    return clientCommunicator;
84  }
85
86  /// <summary>
87  /// Gets the lifecycle manager
88  /// </summary>
89  /// <returns></returns>
90  [MethodImpl(MethodImplOptions.Synchronized)]
91  public static ILifecycleManager GetLifecycleManager() {
92    if (lifecycleManager == null) {
93      lifecycleManager = new LifecycleManager();
94    }
95
96    return lifecycleManager;
97  }
98
99  /// <summary>
100  /// Gets the db session factory
101  /// </summary>
102  /// <returns></returns>
103  [MethodImpl(MethodImplOptions.Synchronized)]
104  public static ISessionFactory GetSessionFactory() {
105    if (sessionFactory == null) {
106      sessionFactory =
107        discoveryService.GetInstances<ISessionFactory>()[0];
108
109      sessionFactory.DbConnectionType =
110        typeof(SqlConnection);
111     
112      sessionFactory.DbConnectionString =
113        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 = discoveryService.GetInstances<IScheduler>()[0];
127    }
128
129    return scheduler;
130  }
131}
Note: See TracBrowser for help on using the repository browser.