Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2010, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.osgi.deployment;
 
 import static org.jboss.as.server.deployment.Services.deploymentUnitName;
 
Service responsible for creating and managing the life-cycle of an OSGi deployment.

Author(s):
Thomas.Diesler@jboss.com
Since:
20-Sep-2010
 
 public class BundleInstallService implements Service<BundleInstallService> {
 
     private static final Logger log = Logger.getLogger("org.jboss.as.osgi");
 
     public static final ServiceName SERVICE_NAME_BASE = ..append("osgi""deployment");
 
     private final Deployment deployment;
     private ServiceName installedBundleName;
 
     private BundleInstallService(Deployment deployment) {
         this. = deployment;
     }
 
     public static void addService(DeploymentPhaseContext phaseContextDeployment deployment) {
         final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
         final BundleInstallService service = new BundleInstallService(deployment);
         final String contextName = deploymentUnit.getName();
         final ServiceName serviceName = getServiceName(contextName);
         final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
         ServiceBuilder<BundleInstallServicebuilder = serviceTarget.addService(serviceNameservice);
         builder.addDependency(.BundleManagerService.classservice.injectedBundleManager);
         builder.addDependency(.BundleStartTracker.classservice.injectedStartTracker);
         builder.addDependency(deploymentUnitName(contextName));
         builder.addDependency(.);
         builder.install();
     }
 
     public static void removeService(DeploymentUnit depUnit) {
         final ServiceName serviceName = getServiceName(depUnit.getName());
         final ServiceController<?> serviceController = depUnit.getServiceRegistry().getService(serviceName);
         if (serviceController != null) {
             serviceController.setMode(.);
         }
     }
 
     public static ServiceName getServiceName(String contextName) {
         ServiceName deploymentServiceName = deploymentUnitName(contextName);
         return ..append(deploymentServiceName.getSimpleName());
     }
 
     public synchronized void start(StartContext contextthrows StartException {
         ServiceController<?> controller = context.getController();
         .debugf("Starting: %s in mode %s"controller.getName(), controller.getMode());
         try {
             ServiceTarget serviceTarget = context.getChildTarget();
             BundleManagerService bundleManager = .getValue();
              = bundleManager.installBundle(serviceTarget);
        } catch (Throwable t) {
            throw new StartException("Failed to install deployment: " + t);
        }
    }
    public synchronized void stop(StopContext context) {
        ServiceController<?> controller = context.getController();
        .debugf("Stoppping: %s in mode %s"controller.getName(), controller.getMode());
        try {
            BundleManagerService bundleManager = .getValue();
            bundleManager.uninstallBundle();
        } catch (Throwable t) {
            .errorf(t"Failed to uninstall deployment: %s");
        }
        // [JBAS-8801] Undeployment leaks root deployment service
        // [TODO] remove this workaround
        ServiceName serviceName = deploymentUnitName(context.getController().getName().getSimpleName());
        ServiceController<?> deploymentController = context.getController().getServiceContainer().getService(serviceName);
        if (deploymentController != null) {
            deploymentController.setMode(.);
        }
    }
    @Override
        return this;
    }
        return ;
    }
New to GrepCode? Check out our FAQ X