Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/27/10 13:25:48 (14 years ago)
Author:
cneumuel
Message:

improved stateless WCF-Proxy client with ServicePool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/WcfService.cs

    r4337 r4338  
    7878    public event EventHandler Connected;
    7979
     80    SlaveFacadeServicePool servicePool;
     81
    8082    /// <summary>
    8183    /// Constructor
     
    9799          return;
    98100        }
     101        servicePool = new SlaveFacadeServicePool(ServerIp);
    99102
    100103        Logger.Debug("Creating the new connection proxy");
    101         client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     104        client = servicePool.CreateStreamedSlaveFacade();
    102105        Logger.Debug("Created the new connection proxy");
    103106
     
    116119      }
    117120      finally {
    118         ServiceLocator.DisposeSlaveClient(client);
     121        servicePool.DisposeSlaveClient(client);
    119122      }
    120123    }
     
    146149        if (ConnState == NetworkEnum.WcfConnState.Connected) {
    147150          Logger.Debug("STARTED: Login Sync");
    148           client = ServiceLocator.CreateSlaveFacade(ServerIp);
     151          client = servicePool.CreateSlaveFacade();
    149152          Response res = client.Login(slaveInfo);
    150153          if (res.StatusMessage != ResponseStatus.Ok) {
     
    161164      }
    162165      finally {
    163         ServiceLocator.DisposeSlaveClient(client);
     166        servicePool.DisposeSlaveClient(client);
    164167      }
    165168    }
     
    173176      if (LoggedIn) {
    174177        Logger.Debug("STARTED: Fetching of Jobs from Server for Slave");
    175         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     178        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    176179        //client.GetStreamedJobAsync(guid);
    177180        client.BeginGetStreamedJob(guid, (ar => {
     
    214217            HandleNetworkError(new FaultException("GetJobAsync did not complete"));
    215218
    216           ServiceLocator.DisposeSlaveClient(client);
     219          servicePool.DisposeSlaveClient(client);
    217220        }), null);
    218221      }
     
    234237        Logger.Debug("Making the call");
    235238        //proxy.StoreFinishedJobResultStreamedAsync(stream, stream);
    236         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     239        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    237240        client.BeginStoreFinishedJobResultStreamed(stream, (ar => {
    238241          Logger.Debug("Finished storing the job");
     
    249252            HandleNetworkError(new FaultException("GetFinishedJobResultAsync did not complete"));
    250253          }
    251           ServiceLocator.DisposeSlaveClient(client);
     254          servicePool.DisposeSlaveClient(client);
    252255        }), null);
    253256      }
     
    262265        Stream stream = GetStreamedJobResult(clientId, jobId, result, percentage, exception);
    263266        //proxy.ProcessSnapshotStreamedAsync(stream, stream);
    264         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     267        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    265268        client.BeginProcessSnapshotStreamed(stream, (ar => {
    266269          if (stream != null)
     
    274277            HandleNetworkError(new FaultException("ProcessSnapshotAsync did not complete"));
    275278          }
    276           ServiceLocator.DisposeSlaveClient(client);
     279          servicePool.DisposeSlaveClient(client);
    277280        }), null);
    278281      }
     
    291294        Logger.Debug("STARTING: sending heartbeat");
    292295        //proxy.ProcessHeartBeatAsync(hbd);
    293         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     296        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    294297        client.BeginProcessHeartBeat(hbd, (ar => {
    295298          if (ar.IsCompleted) {
     
    304307            HandleNetworkError(new FaultException("ProcessHeartBeatAsync did not complete"));
    305308          }
    306           ServiceLocator.DisposeSlaveClient(client);
     309          servicePool.DisposeSlaveClient(client);
    307310        }), null);
    308311      }
     
    334337
    335338    public ResponseResultReceived StoreFinishedJobResultsSync(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception, bool finished) {
    336       SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     339      SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    337340      ResponseResultReceived res = client.StoreFinishedJobResultStreamed(GetStreamedJobResult(clientId, jobId, result, percentage, exception));
    338       ServiceLocator.DisposeSlaveClient(client);
     341      servicePool.DisposeSlaveClient(client);
    339342      return res;
    340343    }
     
    343346      try {
    344347        Logger.Debug("STARTING: Sync call: IsJobStillNeeded");
    345         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     348        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    346349        Response res = client.IsJobStillNeeded(jobId);
    347         ServiceLocator.DisposeSlaveClient(client);
     350        servicePool.DisposeSlaveClient(client);
    348351        Logger.Debug("ENDED: Sync call: IsJobStillNeeded");
    349352        return res;
     
    357360    public ResponseResultReceived ProcessSnapshotSync(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
    358361      try {
    359         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     362        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    360363        var res = client.ProcessSnapshotStreamed(GetStreamedJobResult(clientId, jobId, result, percentage, exception));
    361         ServiceLocator.DisposeSlaveClient(client);
     364        servicePool.DisposeSlaveClient(client);
    362365        return res;
    363366      }
     
    372375        Logger.Debug("STARTED: Requesting Plugins for Job");
    373376        Logger.Debug("STARTED: Getting the stream");
    374         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     377        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    375378        Stream stream = client.GetStreamedPlugins(requestedPlugins.ToArray());
    376         ServiceLocator.DisposeSlaveClient(client);
     379        servicePool.DisposeSlaveClient(client);
    377380        Logger.Debug("ENDED: Getting the stream");
    378381        BinaryFormatter formatter = new BinaryFormatter();
     
    393396      try {
    394397        Logger.Debug("STARTED: Logout");
    395         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     398        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    396399        client.Logout(guid);
    397         ServiceLocator.DisposeSlaveClient(client);
     400        servicePool.DisposeSlaveClient(client);
    398401        Logger.Debug("ENDED: Logout");
    399402      }
     
    406409      try {
    407410        Logger.Debug("STARTED: Syncing Calendars");
    408         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     411        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    409412        ResponseCalendar cal = client.GetCalendar(clientId);
    410         ServiceLocator.DisposeSlaveClient(client);
     413        servicePool.DisposeSlaveClient(client);
    411414        Logger.Debug("ENDED: Syncing Calendars");
    412415        return cal;
     
    421424      try {
    422425        Logger.Debug("STARTED: Setting Calendar status to: " + state);
    423         SlaveService.ISlaveFacade client = ServiceLocator.CreateStreamedSlaveFacade(ServerIp);
     426        SlaveService.ISlaveFacade client = servicePool.CreateStreamedSlaveFacade();
    424427        Response resp = client.SetCalendarStatus(clientId, state);
    425         ServiceLocator.DisposeSlaveClient(client);
     428        servicePool.DisposeSlaveClient(client);
    426429        Logger.Debug("ENDED: Setting Calendar status to: " + state);
    427430        return resp;
Note: See TracChangeset for help on using the changeset viewer.