Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/10 14:17:20 (14 years ago)
Author:
cneumuel
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs

    r4091 r4092  
    3333using HeuristicLab.Hive.Server.Core.InternalInterfaces;
    3434using System.Transactions;
     35using HeuristicLab.Hive.Server.LINQDataAccess;
     36using HeuristicLab.Hive.Server.DataAccess;
    3537
    3638namespace HeuristicLab.Hive.Server.Core {
    37   [ServiceBehavior(InstanceContextMode =
    38     InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    39   public class ClientFacade: IClientFacade {
     39  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
     40  public class ClientFacade : IClientFacade {
    4041
    41     public ClientFacade() {     
     42    public ClientFacade() {
    4243    }
    4344
    4445    private IClientCommunicator clientCommunicator = ServiceLocator.GetClientCommunicator();
    4546
     47    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
     48
    4649    #region IClientCommunicator Members
    4750
    4851    public Response Login(ClientDto clientInfo) {
    49       return clientCommunicator.Login(clientInfo);
     52      using (contextFactory.GetContext()) {
     53        return clientCommunicator.Login(clientInfo);
     54      }
    5055    }
    5156
    5257    public ResponseHB ProcessHeartBeat(HeartBeatData hbData) {
    53       return clientCommunicator.ProcessHeartBeat(hbData);
     58      using (contextFactory.GetContext()) {
     59        return clientCommunicator.ProcessHeartBeat(hbData);
     60      }
    5461    }
    5562
    5663    public ResponseJob SendJob(Guid clientId) {
    57       return clientCommunicator.SendJob(clientId);
     64      using (contextFactory.GetContext()) {
     65        return clientCommunicator.SendJob(clientId);
     66      }
    5867    }
    5968
    60     /*public ResponseSerializedJob SendSerializedJob(Guid clientId) {
    61       return clientCommunicator.SendSerializedJob(clientId);
    62     } */
    63 
    64     public ResponseResultReceived StoreFinishedJobResult(Guid clientId,
    65       Guid jobId,
    66       byte[] result,
    67       double percentage,
    68       Exception exception) {
    69       return clientCommunicator.StoreFinishedJobResult(clientId, jobId, result, percentage, exception);
     69    public ResponseResultReceived StoreFinishedJobResult(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
     70      using (contextFactory.GetContext()) {
     71        return clientCommunicator.StoreFinishedJobResult(clientId, jobId, result, percentage, exception);
     72      }
    7073    }
    7174
    7275    public Response Logout(Guid clientId) {
    73       return clientCommunicator.Logout(clientId);
     76      using (contextFactory.GetContext()) {
     77        return clientCommunicator.Logout(clientId);
     78      }
    7479    }
    7580
    7681    public Response IsJobStillNeeded(Guid jobId) {
    77       return clientCommunicator.IsJobStillNeeded(jobId);
     82      using (contextFactory.GetContext()) {
     83        return clientCommunicator.IsJobStillNeeded(jobId);
     84      }
    7885    }
    7986
    8087    public ResponsePlugin SendPlugins(List<HivePluginInfoDto> pluginList) {
    81       return clientCommunicator.SendPlugins(pluginList);
     88      using (contextFactory.GetContext()) {
     89        return clientCommunicator.SendPlugins(pluginList);     
     90      }
    8291    }
    8392
    8493    public ResponseResultReceived ProcessSnapshot(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
    85       return clientCommunicator.ProcessSnapshot(clientId, jobId, result, percentage, exception);
     94      using (contextFactory.GetContext()) {
     95        return clientCommunicator.ProcessSnapshot(clientId, jobId, result, percentage, exception);
     96      }
    8697    }
    8798
    8899
    89100    public ResponseCalendar GetCalendar(Guid clientId) {
    90       return clientCommunicator.GetCalendar(clientId);
     101      using (contextFactory.GetContext()) {
     102        return clientCommunicator.GetCalendar(clientId);
     103      }
    91104    }
    92105
    93     public Response SetCalendarStatus(Guid clientId, CalendarState state) {
    94       return clientCommunicator.SetCalendarStatus(clientId, state);     
     106    public Response SetCalendarStatus(Guid clientId, CalendarState state) {
     107      using (contextFactory.GetContext()) {
     108        return clientCommunicator.SetCalendarStatus(clientId, state);
     109      }
    95110    }
    96111    #endregion
     
    98113    #region IClientFacade Members
    99114
    100     [SpringTransaction(UserTransaction = true)]
     115    /// <summary>
     116    /// Do not use automatic transactions here
     117    /// </summary>
    101118    public Stream SendStreamedJob(Guid clientId) {
    102       MultiStream stream = new MultiStream();
     119      using (contextFactory.GetContext(false)) {
     120        MultiStream stream = new MultiStream();
    103121
    104       ResponseJob job = null;
     122        ResponseJob job = null;
    105123
    106       job = this.SendJob(clientId);     
     124        job = this.SendJob(clientId);
    107125
    108       //first send response
    109       stream.AddStream(new StreamedObject<ResponseJob>(job));
     126        //first send response
     127        stream.AddStream(new StreamedObject<ResponseJob>(job));
    110128
    111       IJobManager jobManager = ServiceLocator.GetJobManager();
    112       IInternalJobManager internalJobManager = (IInternalJobManager) jobManager;
    113      
    114       //second stream the job binary data
    115       MemoryStream memoryStream = new MemoryStream();     
    116       if(job.Job != null)
    117         stream.AddStream(new MemoryStream(internalJobManager.GetSerializedJobDataById(job.Job.Id)));
    118      
    119       OperationContext clientContext = OperationContext.Current;
     129        IJobManager jobManager = ServiceLocator.GetJobManager();
     130        IInternalJobManager internalJobManager = (IInternalJobManager)jobManager;
     131
     132        //second stream the job binary data
     133        MemoryStream memoryStream = new MemoryStream();
     134        if (job.Job != null)
     135          stream.AddStream(new MemoryStream(internalJobManager.GetSerializedJobDataById(job.Job.Id)));
     136
     137        OperationContext clientContext = OperationContext.Current;
    120138        clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) {
    121139          if (stream != null) {
     
    124142        });
    125143
    126       return stream;
     144        return stream;
     145      }
    127146    }
    128147
    129148    public Stream SendStreamedPlugins(List<HivePluginInfoDto> pluginList) {
    130       return new StreamedObject<ResponsePlugin>(this.SendPlugins(pluginList));
     149      using (contextFactory.GetContext()) {
     150        return new StreamedObject<ResponsePlugin>(this.SendPlugins(pluginList));
     151      }
    131152    }
    132153
    133154    public ResponseResultReceived StoreFinishedJobResultStreamed(Stream stream) {
    134       return ((IInternalClientCommunicator)clientCommunicator).ProcessJobResult(stream, true);
    135     }
     155      using (contextFactory.GetContext()) {
     156        return ((IInternalClientCommunicator)clientCommunicator).ProcessJobResult(stream, true);
     157      }
     158    }
    136159
    137160    public ResponseResultReceived ProcessSnapshotStreamed(Stream stream) {
    138       return ((IInternalClientCommunicator)clientCommunicator).ProcessJobResult(stream, false);
     161      using (contextFactory.GetContext()) {
     162        return ((IInternalClientCommunicator)clientCommunicator).ProcessJobResult(stream, false); 
     163      }
    139164    }
    140165    #endregion
Note: See TracChangeset for help on using the changeset viewer.