Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/29/08 19:22:27 (16 years ago)
Author:
gkronber
Message:

worked on #2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Grid/EngineStore.cs

    r2 r32  
    2727
    2828namespace HeuristicLab.Grid {
    29   [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext=false)]
     29  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    3030  public class EngineStore : IEngineStore {
    3131    private Queue<Guid> engineQueue;
     
    3333    private Dictionary<Guid, byte[]> runningEngines;
    3434    private Dictionary<Guid, byte[]> results;
     35    private Dictionary<Guid, string> runningClients;
    3536    private object bigLock;
     37    private ChannelFactory<IClient> clientChannelFactory;
    3638
    3739    private event EventHandler ResultRecieved;
     
    5961      waitingEngines = new Dictionary<Guid, byte[]>();
    6062      runningEngines = new Dictionary<Guid, byte[]>();
     63      runningClients = new Dictionary<Guid, string>();
    6164      results = new Dictionary<Guid, byte[]>();
    6265      bigLock = new object();
     66
     67      NetTcpBinding binding = new NetTcpBinding();
     68      binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
     69      binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
     70      binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
     71      binding.Security.Mode = SecurityMode.None;
     72
     73      clientChannelFactory = new ChannelFactory<IClient>(binding);
    6374    }
    6475
    65     public bool TryTakeEngine(out Guid guid, out byte[] engine) {
    66       lock (bigLock) {
    67         if (engineQueue.Count == 0) {
     76    public bool TryTakeEngine(string clientUrl, out Guid guid, out byte[] engine) {
     77      lock(bigLock) {
     78        if(engineQueue.Count == 0) {
    6879          guid = Guid.Empty;
    6980          engine = null;
     
    7485          waitingEngines.Remove(guid);
    7586          runningEngines[guid] = engine;
     87          runningClients[guid] = clientUrl;
    7688          return true;
    7789        }
     
    8092
    8193    public void StoreResult(Guid guid, byte[] result) {
    82       lock (bigLock) {
    83         if (!runningEngines.ContainsKey(guid)) return; // ignore result when the engine is not known to be running
     94      lock(bigLock) {
     95        if(!runningEngines.ContainsKey(guid)) return; // ignore result when the engine is not known to be running
    8496
    8597        runningEngines.Remove(guid);
     98        runningClients.Remove(guid);
    8699        results[guid] = result;
    87100        OnResultRecieved(guid);
     
    90103
    91104    internal void AddEngine(Guid guid, byte[] engine) {
    92       lock (bigLock) {
     105      lock(bigLock) {
    93106        engineQueue.Enqueue(guid);
    94107        waitingEngines.Add(guid, engine);
     
    97110
    98111    internal byte[] RemoveResult(Guid guid) {
    99       lock (bigLock) {
     112      lock(bigLock) {
    100113        byte[] result = results[guid];
    101114        results.Remove(guid);
     
    106119    internal byte[] GetResult(Guid guid) {
    107120      ManualResetEvent waitHandle = new ManualResetEvent(false);
    108       lock (bigLock) {
    109         if (results.ContainsKey(guid)) {
     121      lock(bigLock) {
     122        if(results.ContainsKey(guid)) {
    110123          byte[] result = results[guid];
    111124          results.Remove(guid);
     
    114127          ResultRecieved += delegate(object source, EventArgs args) {
    115128            ResultRecievedEventArgs resultArgs = (ResultRecievedEventArgs)args;
    116             if (resultArgs.resultGuid == guid) {
     129            if(resultArgs.resultGuid == guid) {
    117130              waitHandle.Set();
    118131            }
     
    124137      waitHandle.Close();
    125138
    126       lock (bigLock) {
     139      lock(bigLock) {
    127140        byte[] result = results[guid];
    128141        results.Remove(guid);
     
    131144    }
    132145
     146    internal void AbortEngine(Guid guid) {
     147      string clientUrl = "";
     148      lock(bigLock) {
     149        if(runningClients.ContainsKey(guid)) {
     150          clientUrl = runningClients[guid];
     151        }
     152
     153        if(clientUrl != "") {
     154          IClient client = clientChannelFactory.CreateChannel(new EndpointAddress(clientUrl));
     155          client.Abort(guid);
     156        }
     157      }
     158    }
     159
    133160    private void OnResultRecieved(Guid guid) {
    134161      ResultRecievedEventArgs args = new ResultRecievedEventArgs();
    135162      args.resultGuid = guid;
    136       if (ResultRecieved != null) {
     163      if(ResultRecieved != null) {
    137164        ResultRecieved(this, args);
    138165      }
Note: See TracChangeset for help on using the changeset viewer.