Ok… I worked around the issue by letting a Java component do all the work. This ensures that the flowscript is blocked until all files have been generated.

 

function generateValuePropositions() {

var ids = Collection.fromArray(getJson('getCommaSeparatedBasicTypeIds')).toList();

var valuePropositionFactory = cocoon.getComponent('valuePropositionFactory');

valuePropositionFactory.generateValuePropositions(ids);

cocoon.sendPage('index.html');

}

 

 

Robby

 

From: Robby Pelssers [mailto:Robby.Pelssers@nxp.com]
Sent: Thursday, May 24, 2012 4:41 PM
To: dev@cocoon.apache.org
Subject: RE: does flowscript also support sht like setTimeout and setInterval ?? [SOLVED]

 

Damn… A woohoo’d a bit too early as I tested with a simplified version.

 

           setTimeout(

               function() {

                   print('Generating value proposition ' + id);  //This works just fine as there is no dependency on the environment Cocoon object

               }, index * 3000);

           setTimeout(

               function() {

                   print('Generating value proposition ' + id);

                   cocoon.processPipelineTo("write-map-and-topics/" + id, null, new Packages.java.io.ByteArrayOutputStream()); // This runs into an exception as the main function returns quickly and my closures can’t get hold anymore of the current environment

               }, index * 3000);

 

 

Caused by: java.lang.IllegalStateException: Unable to locate current environment.

                at org.apache.cocoon.processing.impl.ProcessInfoProviderImpl.getCurrentObjectModel(ProcessInfoProviderImpl.java:44)

                at org.apache.cocoon.processing.impl.ProcessInfoProviderImpl.getObjectModel(ProcessInfoProviderImpl.java:82)

                at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.setupView(FOM_JavaScriptInterpreter.java:749)

                at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.process(FOM_JavaScriptInterpreter.java:742)

                at org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.jsFunction_processPipelineTo(FOM_Cocoon.java:281)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

 

Not sure yet if my problem is solvable ;-(

 

Robby

 

From: Robby Pelssers [mailto:Robby.Pelssers@nxp.com]
Sent: Thursday, May 24, 2012 4:04 PM
To: dev@cocoon.apache.org
Subject: RE: does flowscript also support sht like setTimeout and setInterval ?? [SOLVED]

 

Works nice !!

 

function generateValuePropositions() {

   var id_collection = Collection.fromArray(getJson('getCommaSeparatedBasicTypeIds'));

   print('Starting generation of ' + id_collection.getLength() + ' value propositions!!');

   var index = 0;

   id_collection.forEach(

       /** we write the map and topics for each id **/

       function(id){

           //We delay invocation of the pipeline with 3 seconds

           setTimeout(

               function() {

                   print('Generating value proposition ' + id);

                   cocoon.processPipelineTo("write-map-and-topics/" + id, null, new Packages.java.io.ByteArrayOutputStream());

               }, index * 3000);

           index++;

       }

   );

   cocoon.sendPage('index.html');

}

 

From: Robby Pelssers [mailto:Robby.Pelssers@nxp.com]
Sent: Thursday, May 24, 2012 3:58 PM
To: dev@cocoon.apache.org
Subject: RE: does flowscript also support sht like setTimeout and setInterval ?? [SOLVED]

 

I found a nice article on stackoverflow showing how to create my own implementation in flowscript.  I will of course first need to thoroughly test it but it looks promising so far ;-)

 

var setTimeout,

    clearTimeout,

    setInterval,

    clearInterval;

 

(function () {

    var timer = new java.util.Timer();

    var counter = 1;

    var ids = {};

 

    setTimeout = function (fn,delay) {

        var id = counter++;

        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});

        timer.schedule(ids[id],delay);

        return id;

    }

 

    clearTimeout = function (id) {

        ids[id].cancel();

        timer.purge();

        delete ids[id];

    }

 

    setInterval = function (fn,delay) {

        var id = counter++;

        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});

        timer.schedule(ids[id],delay,delay);

        return id;

    }

 

    clearInterval = clearTimeout;

 

})();

From: Robby Pelssers [mailto:Robby.Pelssers@nxp.com]
Sent: Thursday, May 24, 2012 2:56 PM
To: dev@cocoon.apache.org
Subject: does flowscript also support sht like setTimeout and setInterval ??

 

Hi guys,

 

I was bulk processing DITA maps and topics from flowscript and noticed that following code is executed parallel.  So basically the cocoon.processPipelineTo returns immediately so it seems.  This results in max sessions reached to XMLDb and I run into an exception.  Just checking what is best way to put some delay in the execution.

 

function generateValuePropositions() {

   var id_collection = Collection.fromArray(getJson('getCommaSeparatedBasicTypeIds'));

   print('Starting generation of ' + id_collection.getLength() + ' value propositions!!');

   id_collection.forEach(

       /** we write the map and topics for each id **/

       function(id){

           cocoon.processPipelineTo("write-map-and-topics/" + id, null, new Packages.java.io.ByteArrayOutputStream());

       }

   );

}

 

Kind regards,

Robby