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.deployer;
 
 import  org.eclipse.equinox.region.RegionDigraph;
 import  org.eclipse.equinox.region.Region;
Implementation of InstallArtifactLifecycleListener that notices InstallArtifactLifecycleListener.onInstalling(InstallArtifact) and InstallArtifactLifecycleListener.onUninstalled(InstallArtifact) calls to add and remove respectively Artifacts from the RuntimeArtifactRepository

An existing artifact with the same type, name, and version as the incoming artifact is not replaced except in the case of a bundle. An existing BundleArtifact is replaced by an incoming DeployerBundleArtifact. This prevents the RAM being corrupted if an attempt it made to install an artifact which belongs to an existing install tree. See TreeRestrictingInstallArtifactLifecycleListener.

Concurrent Semantics
Threadsafe

 
 
     private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
 
     private final BundleContext bundleContext;
 
     private final RegionDigraph regionDigraph;
 
     private final Region globalRegion;
     
 
     public ModelInstallArtifactLifecycleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull RegionDigraph regionDigraph, @NonNull Region globalRegion, @NonNull SpringContextAccessor springContextAccessor) {
         this. = bundleContext;
         this. = artifactRepository;
         this. = regionDigraph;
         this. = springContextAccessor;
         this. = globalRegion;
     }

    
 
     @Override
     public void onInstalling(InstallArtifact installArtifactthrows DeploymentException {
         logEvent("installing"installArtifact);
         if (installArtifact instanceof PlanInstallArtifact) {
             addPlan((PlanInstallArtifactinstallArtifact);
         } else if (installArtifact instanceof BundleInstallArtifact) {
             addOrReplaceBundle((BundleInstallArtifactinstallArtifact);
         } else {
             addArtifact(installArtifact);
         }
     }
 
     private void addPlan(PlanInstallArtifact planInstallArtifact) {
         this..add(new DeployerCompositeArtifact(this.planInstallArtifactthis.));
     }
 
     private void addOrReplaceBundle(BundleInstallArtifact bundleInstallArtifact) {
         Artifact existingBundleArtifact = this..getArtifact(bundleInstallArtifact.getType(), bundleInstallArtifact.getName(), bundleInstallArtifact.getVersion(), getRegion());
         if (!(existingBundleArtifact instanceof DeployerBundleArtifact)) {
             remove(bundleInstallArtifact);
             this..add(new DeployerBundleArtifact(this.bundleInstallArtifactgetRegion(), this.));
         }
     }
 
     private void addArtifact(InstallArtifact installArtifact) {
        this..add(new DeployerArtifact(this.installArtifactthis.));
    }

    
    @Override
    public void onInstallFailed(InstallArtifact installArtifactthrows DeploymentException {
        logEvent("install failed"installArtifact);
        remove(installArtifact);
    }

    
    @Override
    public void onUninstalled(InstallArtifact installArtifactthrows DeploymentException {
        logEvent("uninstalled"installArtifact);
        remove(installArtifact);
    }
    private void logEvent(String eventInstallArtifact installArtifact) {
        this..info("Processing " + event + " event for {} '{}' version '{}'",
            new String[] { installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion().toString() });
    }
    private void remove(InstallArtifact installArtifact) {
        if(installArtifact instanceof BundleInstallArtifact){
            this..remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), getRegion());
        } else {
            this..remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), this.);
        }
    }
    
    private Region getRegion(String name){
        return this..getRegion(name);
    }
New to GrepCode? Check out our FAQ X