Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/09 14:28:30 (15 years ago)
Author:
svonolfe
Message:

Fixed issue related to the streaming of results (#680)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r2117 r2122  
    3737using HeuristicLab.DataAccess.Interfaces;
    3838using System.IO;
     39using System.Runtime.Serialization.Formatters.Binary;
    3940
    4041namespace HeuristicLab.Hive.Server.Core {
     
    465466
    466467    public ResponseResultReceived ProcessJobResult(
    467       JobResult result,
    468468      Stream stream,
    469469      bool finished) {
     
    474474
    475475      try {
     476        BinaryFormatter formatter =
     477          new BinaryFormatter();
     478
     479        JobResult result =
     480          (JobResult)formatter.Deserialize(stream);
     481
    476482        tx = session.BeginTransaction();
    477483
     
    485491          finished);
    486492
    487         //second deserialize the BLOB
    488         IJobResultsAdapter jobResultsAdapter =
    489           session.GetDataAdapter<JobResult, IJobResultsAdapter>();
    490 
    491         IJobAdapter jobAdapter =
    492           session.GetDataAdapter<Job, IJobAdapter>();
    493 
    494         jobResultStream =
    495           jobResultsAdapter.GetSerializedJobResultStream(result.Id, true);
    496 
    497         jobStream =
    498           jobAdapter.GetSerializedJobStream(result.JobId, true);
    499 
    500         byte[] buffer = new byte[3024];
    501         int read = 0;
    502         while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
    503           jobResultStream.Write(buffer, 0, read);
    504 
    505           if (finished)
     493        if (response.Success) {
     494          //second deserialize the BLOB
     495          IJobResultsAdapter jobResultsAdapter =
     496            session.GetDataAdapter<JobResult, IJobResultsAdapter>();
     497
     498          IJobAdapter jobAdapter =
     499            session.GetDataAdapter<Job, IJobAdapter>();
     500
     501          jobResultStream =
     502            jobResultsAdapter.GetSerializedJobResultStream(response.JobResultId, true);
     503
     504          jobStream =
     505            jobAdapter.GetSerializedJobStream(result.JobId, true);
     506
     507          byte[] buffer = new byte[3024];
     508          int read = 0;
     509          while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
     510            jobResultStream.Write(buffer, 0, read);
    506511            jobStream.Write(buffer, 0, read);
    507         }
    508 
    509         jobStream.Close();
    510 
    511         tx.Commit();
     512          }
     513
     514          jobResultStream.Close();
     515          jobStream.Close();
     516
     517          tx.Commit();
     518        }
    512519
    513520        return response;
     
    565572          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID;
    566573          response.JobId = jobId;
     574          tx.Rollback();
    567575          return response;
    568576        }
     
    570578          response.Success = false;
    571579          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED;
     580          tx.Rollback();
     581          return response;
    572582        }
    573583        if (job.JobInfo.Client == null) {
     
    575585          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
    576586          response.JobId = jobId;
     587          tx.Rollback();
    577588          return response;
    578589        }
     
    581592          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB;
    582593          response.JobId = jobId;
     594          tx.Rollback();
    583595          return response;
    584596        }
     
    587599          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED;
    588600          response.JobId = jobId;
     601          tx.Rollback();
    589602          return response;
    590603        }
     
    597610          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE;
    598611          response.JobId = jobId;
     612          tx.Rollback();
    599613          return response;
    600614        }
     
    602616
    603617        if (finished) {
    604           job.JobInfo.State = State.finished;
    605           job.SerializedJobData = result;
    606           jobAdapter.UpdateSerializedJob(job);
    607         }
     618          job.JobInfo.State = State.finished;
     619        }
     620
     621        job.SerializedJobData = result;
     622        jobAdapter.UpdateSerializedJob(job);
    608623
    609624        List<JobResult> jobResults = new List<JobResult>(
     
    625640
    626641        jobResultAdapter.UpdateSerializedJobResult(serializedjobResult);
    627         jobAdapter.Update(job.JobInfo);
    628642
    629643        response.Success = true;
     
    631645        response.JobId = jobId;
    632646        response.finished = finished;
     647        response.JobResultId = jobResult.Id;
    633648
    634649        tx.Commit();
Note: See TracChangeset for help on using the changeset viewer.