brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: CLI commands for manipulating cat...
Date Mon, 25 May 2015 08:26:57 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/617#discussion_r30968526
  
    --- Diff: utils/common/src/main/java/brooklyn/util/javalang/AggregateClassLoader.java
---
    @@ -57,24 +61,65 @@ public static AggregateClassLoader newInstanceWithNoLoaders() {
     
         /** Add a loader to the first position in the search path. */
         public void addFirst(ClassLoader classLoader) {
    -        if (classLoader != null) classLoaders.add(0, classLoader);
    +        if (classLoader != null) {
    +            synchronized (classLoaders) {
    +                classLoaders.add(0, classLoader);
    +            }
    +        }
         }
         /** Add a loader to the last position in the search path. */
         public void addLast(ClassLoader classLoader) {
    -        if (classLoader != null) classLoaders.add(classLoader);
    +        if (classLoader != null) {
    +            synchronized (classLoaders) {
    +                classLoaders.add(classLoader);
    +            }
    +        }
         }
         /** Add a loader to the specific position in the search path. 
          * (It is callers responsibility to ensure that position is valid.) */
         public void add(int index, ClassLoader classLoader) {
    -        if (classLoader != null) classLoaders.add(index, classLoader);
    +        if (classLoader != null) {
    +            synchronized (classLoaders) {
    +                classLoaders.add(index, classLoader);
    +            }
    +        }
    +    }
    +    
    +    /** Resets the classloader shown here to be the given set */
    +    public void reset(Collection<? extends ClassLoader> newClassLoaders) {
    +        synchronized (classLoaders) {
    +            // synchronize:
    +            // * to prevent concurrent invocations
    +            // * so add(0, cl) doesn't interfere
    +            // * and for good measure we add before removing so that iterator always
contains everything
    +            //   although since iterator access is synchronized that shouldn't be necessary
    +            int count = classLoaders.size();
    +            classLoaders.addAll(newClassLoaders);
    +            for (int i=0; i<count; i++) {
    +                classLoaders.remove(0);
    +            }
    +        }
    +    }
    +
    +    /** True if nothing is in the list here */
    +    public boolean isEmpty() {
    +        return classLoaders.isEmpty();
         }
         
    -    /** Returns the _live_ (and modifiable) list of classloaders 
    -     * @return */ 
    +    /** Returns the _live_ (and modifiable) list of classloaders; dangerous and discouraged.

    +     * @deprecated since 0.7.0 */
    +    @Deprecated
         public List<ClassLoader> getList() {
             return classLoaders;
         }
     
    +    public Iterator<ClassLoader> iterator() {
    +        synchronized (classLoaders) {
    +            // provides iterator of snapshot
    +            return classLoaders.iterator();
    --- End diff --
    
    semantics of `CopyOnWriteList.iterator()` is to take a snapshot, with unmodifiable iterator;
have expanded comment


---
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