Beispiel #1
0
 /// <summary>
 /// Освобожает рабочий сервер
 /// </summary>
 /// <param name="wm">Метаданные рабочего сервера</param>
 private void CloseWorker(WorkerMetadata wm)
 {
     if (wm.Worker != null)
     {
         try
         {
             wm.Worker.StandardInput.WriteLine();
             wm.Worker.WaitForExit();
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex);
             try
             {
                 wm.Worker.Kill();
             }
             catch (Exception ex2)
             {
                 Trace.WriteLine(ex2);
             }
         }
         finally
         {
             _portPool.ReleasePort(wm.Port);
         }
     }
 }
Beispiel #2
0
        private bool NewWorker()
        {
            ushort port    = _portPool.AcquirePort();
            bool   success = false;

            try
            {
                WorkerMetadata worker = new WorkerMetadata(port);
                success = StartNewWorker(worker);
                if (success)
                {
                    lock (_consumeLock)
                    {
                        _availableWorkers.Enqueue(worker);
                        Monitor.Pulse(_consumeLock);
                    }
                }
                else
                {
                    _portPool.ReleasePort(port);
                }
            }
            catch (Exception ex)
            {
                success = false;
                _portPool.ReleasePort(port);
                Trace.WriteLine(ex.ToString());
            }

            return(success);
        }
Beispiel #3
0
 /// <summary>
 /// Освобожает рабочий сервер
 /// </summary>
 /// <param name="wm">Метаданные рабочего сервера</param>
 public void FreeWorker(WorkerMetadata wm)
 {
     lock (_freeLock)
     {
         _workersToFree.Enqueue(wm);
         Monitor.Pulse(_freeLock);
     }
 }
Beispiel #4
0
        /*check whether u can do it in a thread*/
        public bool createLocalWorker(WorkerMetadata workerMetadata)
        {
            Worker worker = new Worker(workerMetadata.WorkerId);

            workerIdMap.Add(workerMetadata.WorkerId, worker);

            /*  new Thread(delegate()
             * {
             *    worker.initWorker(workerMetadata);
             * }).Start();*/
            worker.initWorker(workerMetadata);
            return(true);
        }
Beispiel #5
0
        private bool StartNewWorker(WorkerMetadata worker)
        {
            string port       = worker.Port.ToString();
            Guid   markerGuid = Guid.NewGuid();
            string configFile = Path.Combine(_confElement.GetConfigFolder(), port, Path.GetFileName(_confElement.GetExecutablePath())) + ".config";
            string args       = $"{port} {markerGuid} \"{configFile}\" \"{_pluginsFolder}\"";
            string markerLine = $"Worker {port},{markerGuid} started";

            Process process = new Process();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName         = _confElement.GetExecutablePath();
            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(_confElement.GetExecutablePath());
            process.StartInfo.Arguments        = args;
            process.StartInfo.CreateNoWindow   = false;
            process.Start();

            bool error = false;

            while (true)
            {
                if (process.HasExited)
                {
                    error = true;
                    break;
                }

                string str = null;
                try
                {
                    str = process.StandardOutput.ReadLine();
                }
                catch
                {
                    error = true;
                    break;
                }

                if (string.Compare(str, markerLine, true) == 0)
                {
                    worker.Worker = process;
                    ServerRemoteManager.GetWorker(worker).Poll();
                    break;
                }
            }

            return(!error);
        }
Beispiel #6
0
        internal void createWorker(WorkerMetadata workerMetadata)
        {
            String puppetToConnect = workerMetadata.PuppetRUL;

            if (puppetToConnect.ToLower().Equals(puppetUrl.ToLower()))//worker can be started through local puppet
            {
                createLocalWorker(workerMetadata);
            }
            else //worker started through remote puppet
            {
                IPuppetMaster puppet = (IPuppetMaster)Activator.GetObject(
                    typeof(IPuppetMaster),
                    puppetToConnect);
                puppet.createLocalWorker(workerMetadata);
            }
        }
Beispiel #7
0
        private void createWorker(string command)
        {
            String[]       splits         = command.Split(Constants.SPACE_CHAR);
            WorkerMetadata workerMetadata = new WorkerMetadata();

            workerMetadata.WorkerId  = Convert.ToInt16(splits[1]);
            workerMetadata.PuppetRUL = splits[2];

            //Create worker-Id puppet map to use with wait, freeze, unfreeze etc
            puppet.WorkerPuppetMap.Add(workerMetadata.WorkerId, workerMetadata.PuppetRUL);
            puppet.UrlIdMap.Add(splits[3], workerMetadata.WorkerId);/* to fix issue of same puppet->multiple workers */

            if (splits.Length == 5 && splits[4] != string.Empty)
            {
                workerMetadata.EntryURL = splits[4] + puppet.UrlIdMap[splits[4]];
            }

            workerMetadata.ServiceURL = splits[3] + workerMetadata.WorkerId;

            puppet.createWorker(workerMetadata);
        }