Github user andreaturli commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/808#discussion_r136297846
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/objs/proxy/ClassLoaderCache.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.core.objs.proxy;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.util.Set;
    +import java.util.concurrent.ConcurrentMap;
    +
    +import org.apache.brooklyn.util.javalang.AggregateClassLoader;
    +
    +import com.google.common.base.Objects;
    +import com.google.common.collect.ImmutableSet;
    +import com.google.common.collect.Maps;
    +import com.google.common.collect.Sets;
    +
    +/**
    + * For getting/creating {@link AggregateClassLoader} for an entity proxy. 
The returned class loader
    + * can be used when calling {@link 
java.lang.reflect.Proxy#newProxyInstance(ClassLoader, Class[], 
java.lang.reflect.InvocationHandler)}.
    + * 
    + * The classloader is created with references to ClassLoaders for the 
given class and interfaces
    + * (including all super-classes and super-interfaces of those). Also see 
comment in
    + * {@link InternalEntityFactory#createEntityProxy(Iterable, 
org.apache.brooklyn.api.entity.Entity)}.
    + * 
    + * If a classloader has already been created for the given 
class+interfaces, then it guarantees
    + * to return that same classloader instance. This is very important when 
using {@code newProxyInstance}
    + * because if a different ClassLoader instance is used then it will 
reflectively create a new Proxy class.
    + * See https://issues.apache.org/jira/browse/BROOKLYN-528.
    + */
    +class ClassLoaderCache {
    --- End diff --
    
    [minor] @aledsage cache looks exactly what we need here.
    FYI @robertgmoss has used a `computeIfAbsent` in 
https://github.com/apache/brooklyn-server/blob/master/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractComputeServiceRegistry.java#L79
 which may save some boilerplate code.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to