e2ebridge / bpmn

BPMN 2.0 execution engine
467 stars 138 forks source link

QUESTION: There is a way to persist the bpmnXml schema, to parse just once #4

Open eriknyk opened 10 years ago

eriknyk commented 10 years ago

Hi,

I saw that to use bpmn.createUnmanagedProcess("path/to/myProcess.bpmn", ...}); or bpmn.createUnmanagedProcessFromXML("<definitions ... ", ...);

the first parameter is always the bpmnXml source,.. I know that XML Parsing is a little hardest work, and it consume resources (processor and memory),..

I think that if we are always passing the bpmnXML source as first param, it always is parsing the schema to json. The question is, is there a way to persist the first parse of the schema,. (or cache), to do not parse the xml each time that we need to use an instance of a given process.

By example:

------------------------------------------File A ---------------------------------------------

    var processManager = new bpmn.ProcessManager({
        persistencyOptions: {
            uri: util.format('mongodb://%s:%s/%s', config.db.host, config.db.port, config.db.name)
        },
        bpmnXML: {name: 'TaskExampleProcess', xml: bpmnXML},
        handlerString: {name: 'Process1', string: handlerString}
    });

    processManager.createProcess("instance2", function(err, myProcess){
        if (err) throw err;
        // we start the process
        myProcess.triggerEvent("StartEvent_1");
        console.log('process started');
    });

------------------------------------------File B ---------------------------------------------

   var processManager = new bpmn.ProcessManager({
        persistencyOptions: {
            uri: util.format('mongodb://%s:%s/%s', config.db.host, config.db.port, config.db.name)
        },
        bpmnXML: {name: 'TaskExampleProcess', xml: bpmnXML},
        handlerString: {name: 'Process1', string: handlerString}
    });
    //// returns all processes
    processManager.getAllProcesses(function(err, processes) {
        console.log(processes)
    });

So, on both files I need to pass bpmnXML string, and I assume that the engine is parsing twice the xml. The best way would be parse the xml at first time, give me an ID,... and on the second file B, I create the processManager instance with the given ID, and do not pass again the XML.

BEST REGARDS.

Lukas815 commented 9 years ago

Hi, when you create a new ProcessManager, the bpmn model is stored in cache. When you start a new instance of this bpmn model you use processManager.createProcess and trigger the start Event in its callback. Parsing the xml again is only necessary when you have changes in your model.