|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source. |
| 3 | + * Copyright 2010, Red Hat, Inc., and individual contributors |
| 4 | + * as indicated by the @author tags. See the copyright.txt file in the |
| 5 | + * distribution for a full listing of individual contributors. |
| 6 | + * |
| 7 | + * This is free software; you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation; either version 2.1 of |
| 10 | + * the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This software is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this software; if not, write to the Free |
| 19 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. |
| 21 | + */ |
| 22 | + |
| 23 | +package org.jboss.as.server; |
| 24 | + |
| 25 | +import java.util.List; |
| 26 | +import org.jboss.as.deployment.ServerDeploymentRepository; |
| 27 | +import org.jboss.as.deployment.unit.DeploymentUnitProcessor; |
| 28 | +import org.jboss.as.model.AbstractServerModelUpdate; |
| 29 | +import org.jboss.as.model.BootUpdateContext; |
| 30 | +import org.jboss.msc.service.BatchBuilder; |
| 31 | +import org.jboss.msc.service.Service; |
| 32 | +import org.jboss.msc.service.ServiceContainer; |
| 33 | +import org.jboss.msc.service.ServiceName; |
| 34 | +import org.jboss.msc.service.ServiceRegistryException; |
| 35 | +import org.jboss.msc.service.StartContext; |
| 36 | +import org.jboss.msc.service.StartException; |
| 37 | +import org.jboss.msc.service.StopContext; |
| 38 | + |
| 39 | +/** |
| 40 | + * Service used to execute deployment updates once required deployment dependencies are available. |
| 41 | + * |
| 42 | + * @author John Bailey |
| 43 | + */ |
| 44 | +public class DeploymentUpdateService implements Service<Void> { |
| 45 | + private static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("deployment", "updates"); |
| 46 | + private final List<AbstractServerModelUpdate<?>> updates; |
| 47 | + private final ServerStartupListener serverStartupListener; |
| 48 | + |
| 49 | + static final void addService(final BatchBuilder batchBuilder, final List<AbstractServerModelUpdate<?>> updates, final ServerStartupListener serverStartupListener) { |
| 50 | + batchBuilder.addService(SERVICE_NAME, new DeploymentUpdateService(updates, serverStartupListener)) |
| 51 | + .addDependency(ServerDeploymentRepository.SERVICE_NAME); |
| 52 | + } |
| 53 | + |
| 54 | + public DeploymentUpdateService(final List<AbstractServerModelUpdate<?>> updates, final ServerStartupListener serverStartupListener) { |
| 55 | + this.updates = updates; |
| 56 | + this.serverStartupListener = serverStartupListener; |
| 57 | + } |
| 58 | + |
| 59 | + public void start(StartContext context) throws StartException { |
| 60 | + final ServiceContainer serviceContainer = context.getController().getServiceContainer(); |
| 61 | + |
| 62 | + final ServerStartBatchBuilder batchBuilder = new ServerStartBatchBuilder(serviceContainer.batchBuilder(), serverStartupListener); |
| 63 | + batchBuilder.addListener(serverStartupListener); |
| 64 | + |
| 65 | + final BootUpdateContext updateContext = new BootUpdateContext() { |
| 66 | + public BatchBuilder getBatchBuilder() { |
| 67 | + return batchBuilder; |
| 68 | + } |
| 69 | + |
| 70 | + public ServiceContainer getServiceContainer() { |
| 71 | + return serviceContainer; |
| 72 | + } |
| 73 | + |
| 74 | + public void addDeploymentProcessor(DeploymentUnitProcessor processor, long priority) { |
| 75 | + throw new UnsupportedOperationException("Deployments are not allowed to add deployment unit processors"); |
| 76 | + } |
| 77 | + }; |
| 78 | + |
| 79 | + // Deployment chain should be configured now.. |
| 80 | + for (AbstractServerModelUpdate<?> update : updates) { |
| 81 | + if(update.isDeploymentUpdate()) { |
| 82 | + update.applyUpdateBootAction(updateContext); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + try { |
| 87 | + batchBuilder.install(); |
| 88 | + serverStartupListener.finish(); |
| 89 | + } catch (ServiceRegistryException e) { |
| 90 | + throw new IllegalStateException("Failed to install deployment services", e); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + public void stop(StopContext context) { |
| 95 | + } |
| 96 | + |
| 97 | + public Void getValue() throws IllegalStateException { |
| 98 | + return null; |
| 99 | + } |
| 100 | +} |
0 commit comments