Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008, 2010 VMware Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: VMware Inc. - initial contribution /
 
 
 package org.eclipse.virgo.kernel.model.internal;
 
 import java.util.List;
 import java.util.Set;
 
 import  org.eclipse.equinox.region.Region;
Implementation of RuntimeArtifactRepository that notifies a collection of listeners that a change has happened to this repository.

Concurrent Semantics
Threadsafe

See also:
ArtifactRepositoryListener
 
 public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifactRepository {
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     private final Object monitor = new Object();
 
     private final Set<Artifactartifacts = new HashSet<Artifact>();
 
     private final List<ArtifactRepositoryListenerlisteners;
 
         this. = Arrays.asList(listeners);
     }

    
 
     public boolean add(@NonNull Artifact artifact) {
         synchronized (this.) {
             boolean result = this..add(artifact);
             if (result) {
                 for (ArtifactRepositoryListener listener : ) {
                     try {
                         listener.added(artifact);
                     } catch (Exception e) {
                         .error(String.format("Exception calling added() on listener '%s'"listener.toString()), e);
                     }
                 }
             }
             return result;
         }
     }

    
 
     public boolean remove(@NonNull Artifact artifact) {
         synchronized (this.) {
             boolean result = this..remove(artifact);
             if (result) {
                 for (ArtifactRepositoryListener listener : ) {
                     try {
                         listener.removed(artifact);
                     } catch (Exception e) {
                         .error(String.format("Exception calling removed() on listener '%s'"listener.toString()), e);
                     }
                 }
             }
             return result;
         }
     }
    
    
 
     public boolean remove(@NonNull String type, @NonNull String name, @NonNull Version version, @NonNull Region region) {
         synchronized (this.) {
             Artifact artifact = getArtifact(typenameversionregion);
             if(artifact != null){
                 return remove(artifact);
             } else {
                 return false;
            }
        }
    }

    
    public Set<ArtifactgetArtifacts() {
        synchronized (this.) {
            return new HashSet<Artifact>(this.);
        }
    }

    
    public Artifact getArtifact(@NonNull String type, @NonNull String name, @NonNull Version version, @NonNull Region region) {
        synchronized (this.) {
            for (Artifact artifact : this.) {
                if (artifact.getType().equals(type) && 
                    artifact.getName().equals(name) && 
                    artifact.getVersion().equals(version) &&
                    artifact.getRegion().getName().equals(region.getName())){
                    return artifact;
                }
            }
            return null;
        }
    }
New to GrepCode? Check out our FAQ X