4

Is it possible to monitor Pipeline tasks somehow? I tried to add monitors to each task like this

FPipeline := Parallel.Pipeline()
  .Stage(StageWorker1, Parallel.TaskConfig.MonitorWith(MyMonitor))
     .NumTasks(MaxReadThreadCount)
  .Stage(StageWorker2, Parallel.TaskConfig.MonitorWith(MyMonitor))
  .Run();

but getting the exception "Task can be only monitored with a single monitor" (as I understand, it happens because the internal hidden monitor is already installed for pipeline stages).

Andrew
  • 3,696
  • 3
  • 40
  • 71
  • 1
    Not by using the TOmniEventMonitor. What do you want to monitor, anyway? – gabr Aug 30 '13 at 18:02
  • @gabr I want to listen for messages from all stages in a single place, I thought I should use monitor for this – Andrew Aug 30 '13 at 23:16

1 Answers1

6

Use Parallel.TaskConfig.OnMessage and provide a common message processing function.

FPipeline := Parallel.Pipeline()
  .Stage(StageWorker1, Parallel.TaskConfig.OnMessage(MessageProc))
     .NumTasks(MaxReadThreadCount)
  .Stage(StageWorker2, Parallel.TaskConfig.OnMessage(MessageProc))
  .Run();

procedure MessageProc(var msg: TOmniMessage);
begin
  ...
end;

MessageProc can be a normal procedure or a method.

gabr
  • 26,580
  • 9
  • 75
  • 141