Search in sources :

Example 1 with LoadDataInformation

use of org.javamoney.moneta.spi.LoadDataInformation in project jsr354-ri by JavaMoney.

the class LoaderConfigurator method initResource.

private void initResource(String name, Map<String, String> allProps) throws MalformedURLException {
    Map<String, String> props = mapProperties(allProps, name);
    UpdatePolicy updatePolicy = UpdatePolicy.valueOf(props.get(TYPE));
    String fallbackRes = props.get("resource");
    if (Objects.isNull(fallbackRes)) {
        throw new IllegalArgumentException(LOAD + name + ".resource (classpath resource) required.");
    }
    String resourcesString = props.get("urls");
    boolean startRemote = Boolean.valueOf(props.get("startRemote"));
    String[] resources;
    if (Objects.isNull(resourcesString)) {
        LOG.info("No update URLs configured for: " + name);
        resources = new String[0];
    } else {
        resources = resourcesString.split(",");
    }
    URI[] urls = createURIs(resources);
    LoadDataInformation loadDataInformation = new LoadDataInformationBuilder().withResourceId(name).withUpdatePolicy(updatePolicy).withProperties(props).withBackupResource(getClassLoaderLocation(fallbackRes)).withResourceLocations(urls).withStartRemote(startRemote).build();
    this.loaderService.registerData(loadDataInformation);
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder) URI(java.net.URI)

Example 2 with LoadDataInformation

use of org.javamoney.moneta.spi.LoadDataInformation in project jsr354-ri by JavaMoney.

the class DefaultLoaderService method registerData.

@Override
public void registerData(String resourceId, UpdatePolicy updatePolicy, Map<String, String> properties, LoaderListener loaderListener, URI backupResource, URI... resourceLocations) {
    if (resources.containsKey(resourceId)) {
        throw new IllegalArgumentException("Resource : " + resourceId + " already registered.");
    }
    LoadDataInformation loadInfo = new LoadDataInformationBuilder().withResourceId(resourceId).withUpdatePolicy(updatePolicy).withProperties(properties).withLoaderListener(loaderListener).withBackupResource(backupResource).withResourceLocations(resourceLocations).build();
    LoadableResource resource = new LoadableResourceBuilder().withCache(CACHE).withLoadDataInformation(loadInfo).build();
    this.resources.put(loadInfo.getResourceId(), resource);
    if (loadInfo.getLoaderListener() != null) {
        this.addLoaderListener(loadInfo.getLoaderListener(), loadInfo.getResourceId());
    }
    switch(loadInfo.getUpdatePolicy()) {
        case SCHEDULED:
            defaultLoaderServiceFacade.scheduledData(resource);
            break;
        case LAZY:
        default:
            break;
    }
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder)

Example 3 with LoadDataInformation

use of org.javamoney.moneta.spi.LoadDataInformation in project jsr354-ri-bp by JavaMoney.

the class LoaderConfigurator method initResource.

private void initResource(String name, Map<String, String> allProps) throws MalformedURLException {
    Map<String, String> props = mapProperties(allProps, name);
    UpdatePolicy updatePolicy = UpdatePolicy.valueOf(props.get(TYPE));
    String fallbackRes = props.get("resource");
    if (fallbackRes == null) {
        throw new IllegalArgumentException(LOAD + name + ".resource (classpath resource) required.");
    }
    String resourcesString = props.get("urls");
    boolean startRemote = Boolean.parseBoolean(props.get("startRemote"));
    String[] resources;
    if (resourcesString == null) {
        LOG.log(Level.INFO, "No update URLs configured for: %s", name);
        resources = new String[0];
    } else {
        resources = resourcesString.split(",");
    }
    URI[] urls = createURIs(resources);
    LoadDataInformation loadDataInformation = new LoadDataInformationBuilder().withResourceId(name).withUpdatePolicy(updatePolicy).withProperties(props).withBackupResource(getClassLoaderLocation(fallbackRes)).withResourceLocations(urls).withStartRemote(startRemote).build();
    this.loaderService.registerData(loadDataInformation);
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) UpdatePolicy(org.javamoney.moneta.spi.LoaderService.UpdatePolicy) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder) URI(java.net.URI)

Example 4 with LoadDataInformation

use of org.javamoney.moneta.spi.LoadDataInformation in project jsr354-ri-bp by JavaMoney.

the class DefaultLoaderService method registerData.

@Override
public void registerData(String resourceId, UpdatePolicy updatePolicy, Map<String, String> properties, LoaderListener loaderListener, URI backupResource, URI... resourceLocations) {
    if (resources.containsKey(resourceId)) {
        throw new IllegalArgumentException("Resource : " + resourceId + " already registered.");
    }
    LoadDataInformation loadInfo = new LoadDataInformationBuilder().withResourceId(resourceId).withUpdatePolicy(updatePolicy).withProperties(properties).withLoaderListener(loaderListener).withBackupResource(backupResource).withResourceLocations(resourceLocations).build();
    LoadableResource resource = new LoadableResourceBuilder().withCache(CACHE).withLoadDataInformation(loadInfo).build();
    this.resources.put(loadInfo.getResourceId(), resource);
    if (loadInfo.getLoaderListener() != null) {
        this.addLoaderListener(loadInfo.getLoaderListener(), loadInfo.getResourceId());
    }
    switch(loadInfo.getUpdatePolicy()) {
        case SCHEDULED:
            defaultLoaderServiceFacade.scheduledData(resource);
            break;
        case LAZY:
        default:
            break;
    }
    loadData(resourceId);
}
Also used : LoadDataInformation(org.javamoney.moneta.spi.LoadDataInformation) LoadDataInformationBuilder(org.javamoney.moneta.spi.LoadDataInformationBuilder)

Aggregations

LoadDataInformation (org.javamoney.moneta.spi.LoadDataInformation)4 LoadDataInformationBuilder (org.javamoney.moneta.spi.LoadDataInformationBuilder)4 URI (java.net.URI)2 UpdatePolicy (org.javamoney.moneta.spi.LoaderService.UpdatePolicy)2