On 20/09/15 12:16, A. Soroka wrote:
On Sep 18, 2015, at 6:21 PM, Andy Seaborne <[email protected]> wrote:
How would people have the chance to call JenaSystem::set before those static
initializers run? Or am I misunderstanding the use of the hook?
The documentation
/**
* Set the {@link JenaSubsystemRegistry}.
* To have any effect, this function must be called before any other Jena
code,
* and especially before calling {@code JenaSystem.init()}.
*/
Touch Jena and it initialises.
Yes, this is what I don’t understand. If JenaSystem.init() is
gettingcalled in static initializers (and it is) then that means I must somehow
call JenaSystem.set() in static code, too, or I don’t see how it happen
before JenaSystem.init(). Even then, it doesn’t seem that I can
guarantee that my JenaSystem.set() call will precede JenaSystem.init()
getting called.
This works with "*********** LOAD" printed and running with debug on:
JenaSubsystemRegistry r = new JenaSubsystemRegistryBasic() {
@Override
public void load() {
System.err.println("*********** LOAD") ;
super.load();
}
} ;
// Set the sub-system registry
JenaSystem.setSubsystemRegistry(r);
// Enable output if required
JenaSystem.DEBUG_INIT = true ;
// Initialize Jena directly or indirectly
//JenaSystem.init() ;
ModelFactory.createDefaultModel() ;
and ModelFactory has a static initializer. This is the first call to
"other Jena code". When a class is loaded, the <init> is not run. That
happens on first use.
Run the example code above uncommenting the "System.init()" and you will
see that the call in ModelFactory returns early (the recursive
initialization problem - much discussed in the comments and a well known
Java issue.) if the explicit JenaSystem.init() is used.
IMHO JenaSystem.init is a step in the right direction and better way
than the current way initialization is done.
What would be helpful at this point is concrete
improvements/alternatives and concrete evaluation esp in OSGi. [*]
Andy
http://jena.staging.apache.org/documentation/notes/system-initialization.html
[*] JENA-913 : The OSGi integration testing in the build is broken.
---
A. Soroka
The University of Virginia Library