private void removeFromDeployedArtifacts(Artifact artifact) {
   Map<Object, Artifact> artifactMap = deployedArtifacts.get(artifact.getType());
   if (artifactMap != null && artifactMap.containsKey(artifact.getKey())) {
     artifactMap.remove(artifact.getKey());
     if (artifactMap.isEmpty()) {
       deployedArtifacts.remove(artifact.getType());
     }
   }
 }
 private void addToDeployedArtifacts(Artifact artifact) {
   ConcurrentHashMap<Object, Artifact> artifactMap = deployedArtifacts.get(artifact.getType());
   if (artifactMap == null) {
     artifactMap = new ConcurrentHashMap<Object, Artifact>();
   }
   artifactMap.put(artifact.getKey(), artifact);
   deployedArtifacts.put(artifact.getType(), artifactMap);
 }
 /**
  * Undeploy the artifacts found in the artifact to be undeployed list
  *
  * @param artifactsToUndeploy list of artifacts to undeploy
  */
 public void undeployArtifacts(List<Artifact> artifactsToUndeploy) {
   for (Object artifact : artifactsToUndeploy) {
     Artifact artifactToUnDeploy = (Artifact) artifact;
     try {
       Deployer deployer = getDeployer(artifactToUnDeploy.getType());
       if (deployer != null) {
         deployer.undeploy(artifactToUnDeploy.getKey());
         removeFromDeployedArtifacts(artifactToUnDeploy);
       } else {
         throw new CarbonDeploymentException(
             "Deployer instance cannot be found for "
                 + "the type : "
                 + artifactToUnDeploy.getType());
       }
     } catch (CarbonDeploymentException e) {
       logger.error("Error while undeploying artifacts", e);
     }
   }
 }