How to return a List[File] instead of of a single variable o = Val[]

file
array
variables
return-value

#1

My jar file creates several database-files within one execution run. The number of outputs depends on my input argument -iteration. Is it possible to return a List[File] instead of of a single variable o = val[] ?
Basic idea would be to build something like this. My run function returns a Arraylist of type File.

val arg1 = Val[Int]
val arg2 = Val[Int]
val outputfile_list = List[File]

//Definition of workflow
val javaTask = ScalaTask(""“
outputfile_list = package.start.Main.run(arg1,arg2) “””) set (
libraries += workDirectory / “application.jar”,
inputs += (arg1,arg2),
outputs += (loutputfile),
arg1 := 1,
arg2 := 2
)

Is it possible to achieve something like this?
Or what is the best-practice if the number of return value is not know during compile time?


OpenMole crash/The request allStates failed
#2

Indeed it is possible to achive that in the scala task:


    val arg1 = Val[Int]
    val arg2 = Val[Int]
    val outputfile_list = Val[Array[File]]

    //Definition of workflow
    val javaTask = ScalaTask("""val outputfile_list  = package.start.Main.run(arg1,arg2).toArray""") set (
      libraries += workDirectory / "application.jar",
      inputs += (arg1,arg2),
      outputs += (outputfile_list),
      arg1 := 1,
      arg2 := 2
    )

However you would need a hook in order to copy the files on your system. It is not implemented yet. Tell me if this solution work for you, and then it shouldn’t be to hard to add the possibility for the copy file hook to be able to copy an array of files.

Romain


#3

Actually the Array of file is not the best solution. I think you should simply use a directory to store all your files:

    val arg1 = Val[Int]
    val arg2 = Val[Int]
    val outputDirectory = Val[File]

    //Definition of workflow
    val javaTask = ScalaTask("""
     val outputDirectory = mkDir()
     package.start.Main.run(arg1,arg2, outputDirectory)""") set (
      libraries += workDirectory / "application.jar",
      inputs += (arg1,arg2),
      outputs += (outputDirectory, arg1, arg2),
      arg1 := 1,
      arg2 := 2
    )

javaTask hook CopyFileHook(outputDirectory, workDirectory / "result_${arg1}_${arg2}")

#4

Perfect. The second solution works even better.
In my common main function, I used to call “System.exit(0);” to shutdown my vm. Intention was to kill all remaining threads and avoid memory leaks in my multithreaded java application.
When I now call the exit function in package.start.Main.run(), openmole also is also shutdown since it is running in the same vm. Is it possible just to kill processes and free heap memory related to the ScalaTask?


#5

At the end the ScalaTask is a simple function call, therefore it is sadly not possible on the JVM to clean every resources allocated by a method call.