Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ExecutorQueue.cs @ 6451

Last change on this file since 6451 was 6371, checked in by ascheibe, 14 years ago

#1233

  • code cleanups for slave review
  • added switch between privileged and unprivileged sandbox
  • removed childjob management because it's not used
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Threading;
25
26namespace HeuristicLab.Clients.Hive.SlaveCore {
27  /// <summary>
28  /// Every Executor gets an ExecutorQueue in which it can push messages.
29  /// These messages are then read and processed from outside the appdomain.
30  /// </summary>
31  public class ExecutorQueue : MarshalByRefObject {
32    private Queue<ExecutorMessage> queue = null;
33    private Semaphore semaphore = null;
34
35    public ExecutorQueue() {
36      queue = new Queue<ExecutorMessage>();
37      semaphore = new Semaphore(0, 5000);
38    }
39
40    /// <summary>
41    /// Returns the oldest ExecutorMessage Object from the Queue.
42    /// </summary>
43    /// <returns>the oldest ExecutorMessage Object</returns>
44    public ExecutorMessage GetMessage() {
45      semaphore.WaitOne();
46      lock (this) {
47        if (queue.Count > 0) {
48          return queue.Dequeue();
49        }
50      }
51      return null;
52    }
53
54    /// <summary>
55    /// Adds a ExecutorMessage Object to the Queue
56    /// </summary>
57    /// <param name="message">the ExecutorMessage</param>
58    public void AddMessage(ExecutorMessage message) {
59      lock (this) {
60        queue.Enqueue(message);
61        semaphore.Release();
62      }
63    }
64
65    /// <summary>
66    /// Adds a message to the Queue. The ExecutorMessage Object is built in the Method
67    /// </summary>
68    /// <param name="message">the Message</param>
69    public void AddMessage(ExecutorMessageType message) {
70      lock (this) {
71        queue.Enqueue(new ExecutorMessage(message));
72        semaphore.Release();
73      }
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.