protected virtual void Initialize() { HostInfo serv = Job.Server; string ipAddress = null; if (serv.IsConnected || serv.Connect()) { WriteToStream(serv.Writer, (byte)Constants.PointCreated); WriteToStream(serv.Writer, job.Number); WriteToStream(serv.Writer, parentNumber); ipAddress = ReadIPFromStream(serv.Reader); Host = new HostInfo(ipAddress, (int)Ports.DaemonPort); if (!Host.Connect()) { throw new ParcsException("Cannot connect to host"); } } }
protected virtual void Initialize() { HostInfo serv = Job.Server; string ipAddress = null; if (serv.IsConnected || serv.Connect()) { serv.Writer.Write((byte)Constants.PointCreated); serv.Writer.Write(_job.Number); serv.Writer.Write(_parentNumber); ipAddress = ReadIPFromStream(serv.Reader); Host = new HostInfo(ipAddress, (int)Ports.DaemonPort); if (!Host.Connect()) { throw new ParcsException("Cannot connect to host"); } } }
public PointInfo(HostInfo host, int parentNumber) { Host = host; ParentNumber = parentNumber; StartTimeUtc = DateTime.UtcNow; }
public static void SetServerIp(string serverIp) { Server = new HostInfo(serverIp, (int)Ports.ServerPort); }
private void RunClient(NetworkStream clientStream) { Channel channel; byte signal; Job currentJob = null; int pointNumber = 0; using (BinaryReader reader = new BinaryReader(clientStream)) { using (BinaryWriter writer = new BinaryWriter(clientStream)) { channel = new Channel(reader, writer, true); while (true) { try { signal = channel.ReadData(typeof(byte)); switch (signal) { case ((byte)Constants.RecieveTask): currentJob = (Job)channel.ReadObject(); pointNumber = channel.ReadData(typeof(int)); _jobPointNumberDictionary.AddOrUpdate(currentJob.Number, new List<int> { pointNumber }, (key, oldvalue) => { oldvalue.Add(pointNumber); return oldvalue; }); _cancellationDictionary.AddOrUpdate(currentJob.Number, new CancellationTokenSource(), (key, oldValue) => oldValue); continue; case ((byte)Constants.ExecuteClass): if (currentJob != null) { var cancellationTokenSource = _cancellationDictionary[currentJob.Number]; if (!_cancellationDictionary[currentJob.Number].IsCancellationRequested) { var executor = new ModuleExecutor(channel, currentJob, pointNumber); try { executor.Run(cancellationTokenSource.Token); } catch (OperationCanceledException) { _log.Info($"Point N {currentJob.Number}:{pointNumber} was cancelled"); } DeletePoint(currentJob.Number, pointNumber); if (_jobPointNumberDictionary[currentJob.Number].Count == 0) { lock (_locker) { if (File.Exists(currentJob.FileName)) { File.Delete(currentJob.FileName); } } } } } return; case ((byte)Constants.LoadFile): { LoadFile(channel, currentJob); continue; } case ((byte)Constants.ProcessorsCountRequest): { channel.WriteData(Environment.ProcessorCount); continue; } case ((byte)Constants.LinpackRequest): { var linpack = new Linpack(); linpack.RunBenchmark(); channel.WriteData(linpack.MFlops); continue; } case ((byte)Constants.ServerIP): { string ip = channel.ReadData(typeof(string)); if (_server == null || _server.IpAddress.ToString() != ip) { _server = new HostInfo(ip, (int)Ports.ServerPort); } continue; } case ((byte)Constants.CancelJob): { int jobNumber = channel.ReadData(typeof (int)); CancellationTokenSource tokenSource; if (_cancellationDictionary.TryGetValue(jobNumber, out tokenSource)) { tokenSource.Cancel(); _log.Info($"Cancelling job N {jobNumber}"); } else { _log.Info($"Job N {jobNumber} does not exist or does not have cancellation token"); } continue; } default: _log.Error("Unknown signal received, stopping the application..."); return; } } catch (Exception ex) { _log.Error(ex.Message); return; } } } } }