Discussion:
IDILoader - couple of questions
(too old to reply)
Franzw
2019-01-08 09:52:25 UTC
Permalink
Happy new Integrator year !

I want to dynamically load classes/jars in solution.

Using the IDILoader() seems to be the way to go - but it looks like there is no way to :

Place the actual class(es) at the top of the stack (it seems to add the classes to the end of the list with no options doing anything else).

Removing the class(es) again from the Server.

I can very well understand that this is very peculiar requirement and may need a non-standard class loader to do so - I am open to any suggestion the community can come up with :-)

Regards
Franz Wolfhagen
j***@gmail.com
2019-01-11 05:37:18 UTC
Permalink
Hi Franz,
the IDILoader class is an extension of java.net.URLClassLoader, which basically
only has a method to add more URLs at the end of the search list. You cannot add
new jars at the beginning of the list, or remove URLs.

You can dynamically add new jar files at the end of list using e.g.
system.loadJarFiles(path)
But I think you already tried that, and needs something even more dynamic.

You could probably do something similar to what you want with some creative
Javascript, using setContextClassLoader() to specify a new loader that this
AssemblyLine should use. Something like this in the Prolog - Before Init of an
AssemblyLine, or wherever you want to change the loader:

currentLoader = task.getContextClassLoader();
newLoader = new com.ibm.di.loader.DynamicClassLoader([new java.net.URL("file:/home/jens/7.2/a.jar")], currentLoader);
task.setContextClassLoader(newLoader)

Since newLoader would be AssemblyLine specific, maybe you would not need to remove the jar files from the loader later, other AssemblyLines would not
see or use the newLoader. But you could also at any time in the AssemblyLine
reset the loader by using
task.setContextClassLoader(currentLoader)

DynamicClassLoader needs an array of URLs as the first parameter, and searches
that array before using the parent loader.
Franzw
2019-01-11 07:24:02 UTC
Permalink
Post by j***@gmail.com
Hi Franz,
the IDILoader class is an extension of java.net.URLClassLoader, which basically
only has a method to add more URLs at the end of the search list. You cannot add
new jars at the beginning of the list, or remove URLs.
You can dynamically add new jar files at the end of list using e.g.
system.loadJarFiles(path)
But I think you already tried that, and needs something even more dynamic.
You could probably do something similar to what you want with some creative
Javascript, using setContextClassLoader() to specify a new loader that this
AssemblyLine should use. Something like this in the Prolog - Before Init of an
currentLoader = task.getContextClassLoader();
newLoader = new com.ibm.di.loader.DynamicClassLoader([new java.net.URL("file:/home/jens/7.2/a.jar")], currentLoader);
task.setContextClassLoader(newLoader)
Since newLoader would be AssemblyLine specific, maybe you would not need to remove the jar files from the loader later, other AssemblyLines would not
see or use the newLoader. But you could also at any time in the AssemblyLine
reset the loader by using
task.setContextClassLoader(currentLoader)
DynamicClassLoader needs an array of URLs as the first parameter, and searches
that array before using the parent loader.
Thanks Jens - this is exactly the information I was looking for - and you understood the challenge 100%.

Now I just time to look into Java class loaders :-)

Regards
Franz Wolfhagen

Loading...