Hi all

i have a sample callable subprocess as below: alt text

With SubProcessCall util, i can trigger to run it and also control input&output. So i want to go a step futher to monitor that such process. Is there any API or util that could help me to monitor this process? like when process come to step Do first thing, i will be notified and i can access variable in/out or just simple logging out the name of that ivy element.? Also the same question for other kind of process (sub process/start process/...)

Thanks all

asked 06.12.2016 at 06:42

trungdv's gravatar image

trungdv
(suspended)
accept rate: 52%


Should be an easy task with process engine of 6.0 and upwards. Be aware that the shown example uses non-public API and that it can change without any notice.

The following code show a custom engine execution listener that logs the data and process element PID of every element that is executed:

public class ExecListener {

    public static void install()
    {
        IBpmEngine engine = DiCore.getGlobalInjector().getInstance(IBpmEngine.class);
        engine.getHistory().addElementHistoryListener(new LoggingListener(Ivy.log()));
    }

    private static class LoggingListener implements IElementHistoryListener
    {
        private final Logger logger;

        public LoggingListener(Logger logger) {
            this.logger = logger;
        }

        @Override
        public void elementExecutionHistoryAdded(IElementExecutionHistory executionHistory) {
            PID pid = executionHistory.getElementRequestHistory().getElementHistory().getProcessElementId();
            logger.info("executing element pid: "+pid);

            Object in = executionHistory.getData().getAttributeValue("in");
            if (in instanceof Data)
            {
                Data data = (Data)in;
                logger.info(data);
            }
        }
    }
}

I've created a simple demo project here: https://answers.axonivy.com/upfiles/engineExecutionListener_641.iar

alt text

link

answered 06.12.2016 at 12:51

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

edited 07.03.2018 at 10:39

Alex%20Suter's gravatar image

Alex Suter ♦♦
3.1k122247

yes, it worked. so can i get the name/description of PID?

(07.12.2016 at 07:52) trungdv trungdv's gravatar image

Yes you can navigate to the concrete process element model like this:

IProcessManager processManager = DiCore.getGlobalInjector().getInstance(IProcessManager.class);
IProcessModelVersion pmv = executionHistory.getElementRequestHistory().getElementHistory().getPmv();
IProjectProcessManager projectProcessManager = processManager.getProjectDataModelFor(pmv);
BaseElement element = projectProcessManager.search().pid(pid).findOneDeep();
logger.info(element.getName()+" /desc="+element.getDescription());
(07.12.2016 at 08:42) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Hi ivy team How can we prevent initialization many times? everytime i start process, it init one LoggingListener and i don't know how to avoid this. I've tried with removeElementHistoryListener() but i can't remove exactly listener that i've created before. Thanks

(12.12.2016 at 12:52) trungdv trungdv's gravatar image

didn't test it but I think you could implement the clear() method. As far as I remember it is called at least whenever an engine stopps:

LoggingListener{
  ...

  public void historyCleared()
  {
    engine.getHistory().removeElementHistoryListener(this);
  }
}
(12.12.2016 at 12:56) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Hi @Reguel Werme... ♦♦ i guess this code just be able to monitor on the process which is in same project with the listener, right?

If i have project B depend on project A, then from B i register listener and try to call subprocess of A, then listener will not work. Do i miss something?

(26.12.2016 at 07:59) trungdv trungdv's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×37

Asked: 06.12.2016 at 06:42

Seen: 2,216 times

Last updated: 07.03.2018 at 10:39