Ignore:
Timestamp:
Jun 20, 2010, 3:30:22 PM (11 years ago)
Author:
kopal
Message:
  • Execution now is always triggered when one input changed and provides also old inputs
  • Added support for dynamic Connectors
  • some small bug fixing
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Execution/ExecutionEngine.cs

    r1637 r1680  
    4545        public long ExecutedPluginsCounter { get; set; }
    4646        public bool BenchmarkPlugins { get; set; }
    47         public long CheckInterval { get; set; }
    4847        public long GuiUpdateInterval { get; set; }
    4948
     
    9493                updateGuiProtocol.Start();
    9594
    96                 //The CheckExecutableProtocl is also a kind of "daemon" which will check from time to time if a
    97                 //plugin can be executed again
    98                 CheckExecutableProtocol checkExecutableProtocol = new CheckExecutableProtocol(schedulers[0], workspaceModel, this);
    99                 schedulers[0].AddProtocol(checkExecutableProtocol);
    100                 checkExecutableProtocol.Start();
    101 
    10295                //The BenchmarkProtocl counts the amount of executed plugins per seconds and writes this to debug
    10396                if (this.BenchmarkPlugins)
     
    117110                    pluginModel.PluginProtocol = pluginProtocol;
    118111                    schedulers[counter].AddProtocol(pluginProtocol);
    119                     pluginModel.checkExecutable(pluginProtocol);
     112                   
    120113                    pluginProtocol.Start();
    121114                    counter = (counter + 1) % (System.Environment.ProcessorCount*2);
     115
     116                    if (pluginModel.Startable)
     117                    {
     118                        MessageExecution msg = new MessageExecution();
     119                        msg.PluginModel = pluginModel;
     120                        pluginProtocol.BroadcastMessageReliably(msg);
     121
     122                    }
    122123                }
    123124            }
     
    241242    }
    242243
    243     /// <summary>
    244     /// A Protocol for checking if plugins are executable in time intervals
    245     /// </summary>
    246     public class CheckExecutableProtocol : ProtocolBase
     244   
     245    /// <summary>
     246    /// A Protocol for benchmarking
     247    /// </summary>
     248    public class BenchmarkProtocol : ProtocolBase
    247249    {
    248250        private WorkspaceModel workspaceModel;
    249251        private ExecutionEngine executionEngine;
    250      
     252
    251253        /// <summary>
    252254        /// Create a new protocol. Each protocol requires a scheduler which provides
     
    254256        /// </summary>
    255257        /// <param name="scheduler"></param>
    256         public CheckExecutableProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
     258        public BenchmarkProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
    257259            : base(scheduler)
    258260        {
     
    270272            while (this.executionEngine.IsRunning)
    271273            {
    272                 yield return Timeout(this.executionEngine.CheckInterval, HandleCheckExecutable);
     274                yield return Timeout(1000, HandleBenchmark);
    273275            }
    274276        }
     
    279281        /// </summary>
    280282        /// <param name="msg"></param>
    281         private void HandleCheckExecutable()
    282         {
    283             foreach (PluginModel pluginModel in workspaceModel.AllPluginModels)
    284             {
    285                 pluginModel.checkExecutable(pluginModel.PluginProtocol);
    286             }
    287         }
    288        
    289     }
    290 
    291     /// <summary>
    292     /// A Protocol for checking if plugins are executable in time intervals
    293     /// </summary>
    294     public class BenchmarkProtocol : ProtocolBase
    295     {
    296         private WorkspaceModel workspaceModel;
     283        private void HandleBenchmark()
     284        {
     285            this.workspaceModel.WorkspaceManagerEditor.GuiLogMessage("Executing at about " + this.executionEngine.ExecutedPluginsCounter + " Plugins/s", NotificationLevel.Debug);
     286            this.executionEngine.ExecutedPluginsCounter = 0;
     287        }
     288
     289    }
     290
     291    /// <summary>
     292    /// A Protocol for a PluginModel
     293    /// </summary>
     294    public class PluginProtocol : ProtocolBase
     295    {
     296        private PluginModel pluginModel;
    297297        private ExecutionEngine executionEngine;
    298298
     
    302302        /// </summary>
    303303        /// <param name="scheduler"></param>
    304         public BenchmarkProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
     304        public PluginProtocol(Scheduler scheduler, PluginModel pluginModel,ExecutionEngine executionEngine)
    305305            : base(scheduler)
    306306        {
    307             this.workspaceModel = workspaceModel;
     307            this.pluginModel = pluginModel;
    308308            this.executionEngine = executionEngine;
    309309        }
    310310
    311311        /// <summary>
    312         /// The main function of the protocol
     312        /// The main function of the protocol     
    313313        /// </summary>
    314314        /// <param name="stateMachine"></param>
     
    318318            while (this.executionEngine.IsRunning)
    319319            {
    320                 yield return Timeout(1000, HandleBenchmark);
    321             }
    322         }
    323 
    324         /// <summary>
    325         /// Handler function for a message.
    326         /// This handler must not block, because it executes inside the thread of the scheduler.
    327         /// </summary>
    328         /// <param name="msg"></param>
    329         private void HandleBenchmark()
    330         {
    331             this.workspaceModel.WorkspaceManagerEditor.GuiLogMessage("Executing at about " + this.executionEngine.ExecutedPluginsCounter + " Plugins/s", NotificationLevel.Debug);
    332             this.executionEngine.ExecutedPluginsCounter = 0;
    333         }
    334 
    335     }
    336 
    337     /// <summary>
    338     /// A Protocol for a PluginModel
    339     /// </summary>
    340     public class PluginProtocol : ProtocolBase
    341     {
    342         private PluginModel pluginModel;
    343         private ExecutionEngine executionEngine;
    344 
    345         /// <summary>
    346         /// Create a new protocol. Each protocol requires a scheduler which provides
    347         /// a thread for execution.
    348         /// </summary>
    349         /// <param name="scheduler"></param>
    350         public PluginProtocol(Scheduler scheduler, PluginModel pluginModel,ExecutionEngine executionEngine)
    351             : base(scheduler)
    352         {
    353             this.pluginModel = pluginModel;
    354             this.executionEngine = executionEngine;
    355         }
    356 
    357         /// <summary>
    358         /// The main function of the protocol
    359         ///
    360         /// states are here:
    361         ///
    362         ///     PreExecution -> Execution -> PostExecution
    363         ///        /\                           |
    364         ///         |---------------------------|
    365         ///         
    366         /// </summary>
    367         /// <param name="stateMachine"></param>
    368         /// <returns></returns>
    369         public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
    370         {
    371             while (this.executionEngine.IsRunning)
    372             {
    373320                yield return Receive<MessageExecution>(null, this.HandleExecute);             
    374321            }
     
    389336                if (connectorModel.HasData)
    390337                {
    391                     PropertyInfo propertyInfo = pluginModel.Plugin.GetType().GetProperty(connectorModel.PropertyName);
    392                     propertyInfo.SetValue(pluginModel.Plugin, connectorModel.Data, null);
    393                     connectorModel.HasLastData = true;
    394                     connectorModel.LastData = connectorModel.Data;
    395                     connectorModel.Data = null;
    396                     connectorModel.HasData = false;
    397                     connectorModel.InputConnection.Active = false;                   
     338                    if (connectorModel.IsDynamic)
     339                    {
     340                        MethodInfo propertyInfo = pluginModel.Plugin.GetType().GetMethod(connectorModel.DynamicSetterName);
     341                        propertyInfo.Invoke(pluginModel.Plugin, new object[]{connectorModel.PropertyName, connectorModel.Data});
     342                    }
     343                    else
     344                    {
     345                        PropertyInfo propertyInfo = pluginModel.Plugin.GetType().GetProperty(connectorModel.PropertyName);
     346                        propertyInfo.SetValue(pluginModel.Plugin, connectorModel.Data, null);
     347                    }
    398348                }
    399349            }
Note: See TracChangeset for help on using the changeset viewer.