Jesse Eichar a écrit :
Since we are only interested in the geometry we made a query so that
only the geometry attribute is read from disk. As you know this
involves creating a new FeatureType, which in turn involves searching
for a FeatureTypeFactory using the FactoryFinder service. According to
the profiling I did it seems that a great deal of the time is being
spent in ClassLoader.getResourceAsStream() called at line 350 in
FactoryFinder. Is there any caching of the Factories so the disk is hit
less?
org.geotools.factory.FactoryFinder (not to be confused with org.geotools.referencing.FactoryFinder)
is the previous factory framework (I was not involved in this one), which is now marked as
deprecated but still used in various place like FeatureTypeFactory. As you point out,
org.geotools.factory.FactoryFinder do not performs any caching.
The proposed replacement is org.geotools.factory.FactoryRegistry, which is build on top of
javax.imageio.spi.ServiceRegistry (while the later live in javax.imageio package, it is actually
truly generic). Leveraging J2SE's ServiceRegistry give us caching out of the box, among other
advantages. The drawback is that org.geotools.factory.FactoryRegistry is more complex to use for
implementor (but should still easy for users - actually they don't use it directly, but use a
convenience wrapper like org.geotools.referencing.FactoryFinder).
A possible approach is to replace the use of the deprecated org.geotools.factory.FactoryFinder by
FactoryRegistry in FeatureTypeFactory, and see if we get any improvement. Proposed steps:
- Add the following in FeatureTypeFactory:
/**
* The service registry for this manager.
* Will be initialized only when first needed.
*/
private static FactoryRegistry registry;
/**
* Returns the service registry. The registry will be created the first
* time this method is invoked.
*/
private static FactoryRegistry getServiceRegistry() {
assert Thread.holdsLock(FeatureTypeFactory.class);
if (registry == null) {
registry = new FactoryCreator(Arrays.asList(new Class[] {
FeatureTypeFactory.class}));
}
return registry;
}
- Replace all FactoryConfigurationError by FactoryRegistryException.
- Modify newInstance() as below:
public static synchronized FeatureTypeFactory newInstance(String name)
throws FactoryRegistryException {
FeatureTypeFactory factory = (FeatureTypeFactory) getServiceRegistry()
.getServiceProvider(FeatureTypeFactory.class, null, null, null);
factory.setName(name);
return factory;
}
NOTE: We have an issue with 'setName' below, because 'getServiceProvider' usually returns a
singleton (the cached instance, namely) and we can't use a singleton if we are going to change its
configuration according user's parameters. This situation can be handled with hints. Please let me
know if you would like to go along that path, and I will provide more indications.
Martin.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel