Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/SlaveFacade.cs @ 4263

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

consolidated Response objects to use only StatusMessage with enums instead of strings.
removed Success property from Response. success is now represented by StatusMessage alone. (#1159)

File size: 5.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 System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts;
29using HeuristicLab.PluginInfrastructure;
30using System.IO;
31using System.Runtime.Serialization.Formatters.Binary;
32using System.ServiceModel;
33using HeuristicLab.Hive.Server.Core.InternalInterfaces;
34using System.Transactions;
35using HeuristicLab.Hive.Server.LINQDataAccess;
36using HeuristicLab.Hive.Server.DataAccess;
37using HeuristicLab.Hive.Contracts.ResponseObjects;
38
39namespace HeuristicLab.Hive.Server.Core {
40  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
41  public class SlaveFacade : ISlaveFacade {
42
43    public SlaveFacade() {
44    }
45
46    private ISlaveCommunicator slaveCommunicator = ServiceLocator.GetSlaveCommunicator();
47
48    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
49
50    #region ISlaveCommunicator Members
51
52    public Response Login(ClientDto clientInfo) {
53      using (contextFactory.GetContext()) {
54        return slaveCommunicator.Login(clientInfo);
55      }
56    }
57
58    public ResponseHeartBeat ProcessHeartBeat(HeartBeatData hbData) {
59      using (contextFactory.GetContext()) {
60        return slaveCommunicator.ProcessHeartBeat(hbData);
61      }
62    }
63
64    public ResponseObject<JobDto> GetJob(Guid clientId) {
65      using (contextFactory.GetContext()) {
66        return slaveCommunicator.GetJob(clientId);
67      }
68    }
69
70    public ResponseResultReceived StoreFinishedJobResult(Guid clientId, Guid jobId, byte[] result, double percentage, string exception) {
71      using (contextFactory.GetContext()) {
72        return slaveCommunicator.StoreFinishedJobResult(clientId, jobId, result, percentage, exception);
73      }
74    }
75
76    public Response Logout(Guid clientId) {
77      using (contextFactory.GetContext()) {
78        return slaveCommunicator.Logout(clientId);
79      }
80    }
81
82    public Response IsJobStillNeeded(Guid jobId) {
83      using (contextFactory.GetContext()) {
84        return slaveCommunicator.IsJobStillNeeded(jobId);
85      }
86    }
87
88    public ResponseList<CachedHivePluginInfoDto> GetPlugins(List<HivePluginInfoDto> pluginList) {
89      return slaveCommunicator.GetPlugins(pluginList);     
90    }
91
92    public ResponseResultReceived ProcessSnapshot(Guid clientId, Guid jobId, byte[] result, double percentage, string exception) {
93      using (contextFactory.GetContext()) {
94        return slaveCommunicator.ProcessSnapshot(clientId, jobId, result, percentage, exception);
95      }
96    }
97
98    public ResponseCalendar GetCalendar(Guid clientId) {
99      using (contextFactory.GetContext()) {
100        return slaveCommunicator.GetCalendar(clientId);
101      }
102    }
103
104    public Response SetCalendarStatus(Guid clientId, CalendarState state) {
105      using (contextFactory.GetContext()) {
106        return slaveCommunicator.SetCalendarStatus(clientId, state);
107      }
108    }
109    #endregion
110
111    #region IClientFacade Members
112
113    /// <summary>
114    /// Do not use automatic transactions here
115    /// </summary>
116    public Stream GetStreamedJob(Guid clientId) {
117      using (contextFactory.GetContext(false)) {
118        MultiStream stream = new MultiStream();
119
120        ResponseObject<JobDto> job = null;
121
122        job = ServiceLocator.GetSlaveCommunicator().GetJob(clientId);
123
124        //first send response
125        stream.AddStream(new StreamedObject<ResponseObject<JobDto>>(job));
126
127        IInternalJobManager internalJobManager = (IInternalJobManager)ServiceLocator.GetJobManager();
128
129        //second stream the job binary data
130        MemoryStream memoryStream = new MemoryStream();
131        if (job.Obj != null) {
132          stream.AddStream(new MemoryStream(internalJobManager.GetSerializedJobDataById(job.Obj.Id)));
133        }
134
135        OperationContext clientContext = OperationContext.Current;
136        clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) {
137          if (stream != null) {
138            stream.Dispose();
139          }
140        });
141
142        return stream;
143      }
144    }
145
146    public Stream GetStreamedPlugins(List<HivePluginInfoDto> pluginList) {
147      return new StreamedObject<ResponseList<CachedHivePluginInfoDto>>(this.GetPlugins(pluginList));
148    }
149
150    public ResponseResultReceived StoreFinishedJobResultStreamed(Stream stream) {
151      using (contextFactory.GetContext()) {
152        return ((IInternalSlaveCommunicator)slaveCommunicator).ProcessJobResult(stream, true);
153      }
154    }
155
156    public ResponseResultReceived ProcessSnapshotStreamed(Stream stream) {
157      using (contextFactory.GetContext()) {
158        return ((IInternalSlaveCommunicator)slaveCommunicator).ProcessJobResult(stream, false); 
159      }
160    }
161    #endregion
162  }
163}
Note: See TracBrowser for help on using the repository browser.