7

JavaMoney APIの新しいバージョン 1.0 を参照実装とともに使用して、javamoney.propertiesをオーバーライドすることにより、リソースローダーが他の ExchangeRateProvider をロードしないようにします。

{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

ただし、ログには、それらがまだロードされていることが示されています。

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

LoaderService インターフェースから 'NEVER' はローカル リソース (リモートではなく) のロードをトリガーしますが、'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
}
...

注目したのは、org.javamoney.moneta.internal.convert の ExchangeProviders のコンストラクターで、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());
}

これは、DefaultLoaderServiceのメソッドregisterDataの「ONSTARTUP」の場合と同じです。

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

これが、javamoney.properties に何を入れても読み込まれる理由でしょうか?

他の ExchangeRateProvider を完全にオフにするにはどうすればよいですか? カスタムExchangeRateProviderのみを使用したい。

4

1 に答える 1