Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.guvnor.structure.backend.deployment;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
 import  javax.enterprise.context.ApplicationScoped;
 import  javax.enterprise.event.Event;
 import  javax.enterprise.event.Observes;
 import  javax.inject.Inject;
 
 import  org.guvnor.structure.deployment.DeploymentConfig;
 import  org.guvnor.structure.deployment.DeploymentConfigService;
 import  org.guvnor.structure.server.config.ConfigGroup;
 import  org.guvnor.structure.server.config.ConfigType;
 import  org.guvnor.structure.server.config.ConfigurationFactory;
 import  org.guvnor.structure.server.config.ConfigurationService;
 import  org.guvnor.structure.server.deployment.DeploymentConfigFactory;
 import  org.slf4j.Logger;
 import  org.slf4j.LoggerFactory;
 
 @ApplicationScoped
 public class DeploymentConfigServiceImpl implements DeploymentConfigService {
 
     private static final Logger logger = LoggerFactory.getLogger( DeploymentConfigServiceImpl.class );
 
     @Inject
     private ConfigurationService configurationService;
 
     @Inject
     private ConfigurationFactory configurationFactory;
 
     @Inject
     private DeploymentConfigFactory deploymentFactory;
     @Inject
     @Added
     @Inject
     @Removed
 
     private Map<String, DeploymentConfig> registeredDeployments = new ConcurrentHashMap<String, DeploymentConfig>();
 
     @PostConstruct
     public void loadGroups() {
         Collection<ConfigGroup> deployments = .getConfiguration( ConfigType.DEPLOYMENT );
         if ( deployments != null ) {
             for ( ConfigGroup deploymentConfig : deployments ) {
                 DeploymentConfig deployment = .newDeployment( deploymentConfig );
                 .put( deployment.getIdentifier(), deployment );
             }
         }
     }
 
     @Override
     public void addDeploymentString identifier,
                                Object deploymentUnit ) {
         ConfigGroup deploymentConfig = .newConfigGroup( ConfigType.DEPLOYMENT, identifier"" );
         deploymentConfig.addConfigItem( .newConfigItem( "unit"deploymentUnit ) );
 
         .addConfiguration( deploymentConfig );
 
         DeploymentConfig deployment = .newDeployment( deploymentConfig );
         .put( deployment.getIdentifier(), deployment );
     }
 
     @Override
     public void removeDeploymentString identifier ) {
         ConfigGroup deploymentConfig = .newConfigGroup( ConfigType.DEPLOYMENT, identifier"" );
         .removeConfiguration( deploymentConfig );
 
         .remove( identifier );
 
     }
 
     @Override
     public DeploymentConfig getDeploymentString identifier ) {
         return .get( identifier );
     }
 
     @Override
     public Collection<DeploymentConfig> getDeployments() {
         return Collections.unmodifiableCollection.values() );
     }
 
     public void updateRegisteredDeployments( @Observes SystemRepositoryChangedEvent changedEvent ) {
         .debug( "Received deployment changed event, processing..." );
         Collection<ConfigGroup> deployments = .getConfiguration( ConfigType.DEPLOYMENT );
         if ( deployments != null ) {
             List<StringprocessedDeployments = new ArrayList<String>();
             for ( ConfigGroup deploymentConfig : deployments ) {
                 String name = deploymentConfig.getName();
                if ( !this..containsKey( name ) ) {
                    try {
                        .debug( "New deployment {} has been discovered and will be deployed"name );
                        // add it to registered deployments
                        DeploymentConfig deployment = .newDeployment( deploymentConfig );
                        // trigger deployment of new element
                        .fire( new DeploymentConfigChangedEventdeployment.getDeploymentUnit() ) );
                        .put( deployment.getIdentifier(), deployment );
                        .debug( "Deployment {} deployed successfully"name );
                    } catch ( RuntimeException e ) {
                        .warn( "Deployment {} failed to deploy due to {}"namee.getMessage(), e );
                    }
                }
                processedDeployments.addname );
            }
            Set<StringregisteredDeploymedIds = .keySet();
            // process undeploy
            for ( String identifier : registeredDeploymedIds ) {
                if ( !processedDeployments.containsidentifier ) ) {
                    try {
                        .debug( "New deployment {} has been discovered and will be deployed"identifier );
                        DeploymentConfig deployment = .remove( identifier );
                        // trigger undeloyment as it was removed
                        .fire( new DeploymentConfigChangedEventdeployment.getDeploymentUnit() ) );
                        .debug( "Deployment {} undeployed successfully"identifier );
                    } catch ( RuntimeException e ) {
                        .warn( "Undeployment {} failed to deploy due to {}"identifiere.getMessage(), e );
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X