brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bostko <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #492: Allow a user to add or override deseriali...
Date Thu, 22 Dec 2016 11:07:01 GMT
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/492#discussion_r93604719
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/DeserializingClassRenamesProvider.java
---
    @@ -20,65 +20,217 @@
     
     import java.io.IOException;
     import java.io.InputStream;
    +import java.util.Dictionary;
     import java.util.Enumeration;
    +import java.util.List;
     import java.util.Map;
     import java.util.Properties;
     
    +import org.apache.brooklyn.util.collections.MutableMap;
     import org.apache.brooklyn.util.core.ResourceUtils;
     import org.apache.brooklyn.util.exceptions.Exceptions;
     import org.apache.brooklyn.util.javalang.Reflections;
     import org.apache.brooklyn.util.stream.Streams;
    +import org.osgi.framework.Constants;
    +import org.osgi.framework.InvalidSyntaxException;
    +import org.osgi.service.cm.Configuration;
    +import org.osgi.service.cm.ConfigurationAdmin;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
     import com.google.common.annotations.Beta;
    +import com.google.common.collect.ImmutableList;
     import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Lists;
     import com.google.common.collect.Maps;
     
     @Beta
     public class DeserializingClassRenamesProvider {
     
    +    /*
    +     * This provider keeps a cache of the class-renames, which is lazily populated (see
{@link #cache}. 
    +     * Calling {@link #reset()} will set this cache to null, causing it to be reloaded
next time 
    +     * it is requested.
    +     * 
    +     * Loading the cache involves iterating over the {@link #loaders}, returning the
union of 
    +     * the results from {@link Loader#load()}.
    +     * 
    +     * Initially, the only loader is the basic {@link ClasspathConfigLoader}.
    +     * 
    +     * However, when running in karaf the {@link OsgiConfigLoader} will be instantiated
and added.
    +     * See karaf/init/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    +     */
    +    
    +    private static final Logger LOG = LoggerFactory.getLogger(DeserializingClassRenamesProvider.class);
    +    private static final List<String> EXCLUDED_KEYS = ImmutableList.of("service.pid",
"felix.fileinstall.filename");
    +
         public static final String DESERIALIZING_CLASS_RENAMES_PROPERTIES_PATH = "classpath://org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties";
    +    public static final String KARAF_DESERIALIZING_CLASS_RENAMES_PROPERTIES = "org.apache.brooklyn.classrename";
    +
    +    private static final List<Loader> loaders = Lists.newCopyOnWriteArrayList();
    +    static {
    +        loaders.add(new ClasspathConfigLoader());
    +    }
         
         private static volatile Map<String, String> cache;
    -    
    +
         @Beta
         public static Map<String, String> loadDeserializingClassRenames() {
    -        // Double-checked locking - got to use volatile or some such!
    -        if (cache == null) {
    -            synchronized (DeserializingClassRenamesProvider.class) {
    -                if (cache == null) {
    -                    cache = loadDeserializingClassRenamesCache();
    +        synchronized (DeserializingClassRenamesProvider.class) {
    +            if (cache == null) {
    +                ImmutableMap.Builder<String, String> builder = ImmutableMap.<String,
String>builder();
    +                for (Loader loader : loaders) {
    +                    builder.putAll(loader.load());
    --- End diff --
    
    Hi @tbouron  I think you missed my comment, it is still valid.
    
    > _bostko 7 days ago_
    > `ImmutableMap.Builder#putAll` for duplicate entries will fail.
    > It is good to be able to override `DESERIALIZING_CLASS_RENAMES_PROPERTIES_PATH` with
the ones provided in the file `KARAF_DESERIALIZING_CLASS_RENAMES_PROPERTIES_PATH`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message