Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding properties in javamoney.properties?

Using the new 1.0 version of JavaMoney API with the reference implementation we try to stop the resource-loader from loading other ExchangeRateProvider by overriding javamoney.properties.

{1}conversion.default-chain=MY-PROVIDER
# Turn off loading of the default Moneta ExchangeRateProviders.
{1}load.ECBCurrentRateProvider.type=NEVER
{1}load.ECBHistoric90RateProvider.type=NEVER
{1}load.ECBHistoricRateProvider.type=NEVER
{1}load.IMFRateProvider.type=NEVER
{1}load.AbstractECBRateProvider=NEVER

However, the log tells me they are still being loaded:

jun 19, 2015 8:27:58 AM  org.javamoney.moneta.internal.convert.AbstractECBRateProvider newDataLoaded
INFO: Loaded ECBCurrentRateProvider exchange rates for days:1

From the LoaderService interface 'NEVER' triggers loading the local resource (and not the remote), but I've also tried 'LAZY'.

public interface LoaderService {

/**
 * Platform RI: The update policy defines how and when the
 * {@link LoaderService} tries to update the local cache with newest version of
 * the registered data resources, accessing the configured remote
 * {@link URI}s. By default no remote connections are done (
 * {@link UpdatePolicy#NEVER} ).
 *
 * @author Anatole Tresch
 */
public enum UpdatePolicy {
    /**
     * The resource will never be updated from remote, only the fallback URL
     * will be evaluated.
     */
    NEVER,
    /**
     * The resource will be loaded automatically from remote only once on
     * startup.
     */
    ONSTARTUP,
    /**
     * The resource will be loaded automatically from remote only once, when
     * accessed the first time.
     */
    LAZY,
    /**
     * The resource should be regularly reloaded based on a schedule.
     */
    SCHEDULED
}
...

What we've noted is that in the constructor of the ExchangeProviders in org.javamoney.moneta.internal.convert, there is a call to loader.loadDataAsync:

AbstractECBRateProvider(ProviderContext context) {
    super(context);
    saxParserFactory.setNamespaceAware(false);
    saxParserFactory.setValidating(false);
    LoaderService loader = Bootstrap.getService(LoaderService.class);
    loader.addLoaderListener(this, getDataId());
    loader.loadDataAsync(getDataId());
}

This is the same as for case 'ONSTARTUP' in the method registerData in DefaultLoaderService:

switch (updatePolicy) {
        case NEVER:
            loadDataLocal(resourceId);
            break;
        case ONSTARTUP:
            loadDataAsync(resourceId);
            break;
        case SCHEDULED:
            addScheduledLoad(res);
            break;
        case LAZY:
        default:
            break;
    }

Could this be a reason that it is loaded no matter what I put in my javamoney.properties?

How do we turn off the other ExchangeRateProviders altogether? We only want to use our custom ExchangeRateProvider.

like image 519
Truls Avatar asked Jun 19 '15 06:06

Truls


1 Answers

Looks we have an issue here. Can you please file a Jira issue in our java.net/javamoney project (and check if this issue was already filed :) ). We plan to publish a patch release of the ri next days, so we may fix this as well.

Thanks a lot! Anatole

like image 118
Anatole Tresch Avatar answered Sep 20 '22 08:09

Anatole Tresch