PageRenderTime 27ms CodeModel.GetById 23ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/arquillian/container-embedded/src/main/java/org/jboss/as/arquillian/container/embedded/EmbeddedDeployableContainer.java

https://bitbucket.org/cprenzberg/wildfly
Java | 72 lines | 37 code | 7 blank | 28 comment | 2 complexity | b4bc50daebfceb9152b5dd09320cfb18 MD5 | raw file
 1/*
 2 * JBoss, Home of Professional Open Source
 3 * Copyright 2012, Red Hat Middleware LLC, and individual contributors
 4 * by the @authors tag. See the copyright.txt in the distribution for a
 5 * full listing of individual contributors.
 6 *
 7 * Licensed under the Apache License, Version 2.0 (the "License");
 8 * you may not use this file except in compliance with the License.
 9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.jboss.as.arquillian.container.embedded;
18
19import org.jboss.arquillian.container.spi.client.container.LifecycleException;
20import org.jboss.as.arquillian.container.CommonDeployableContainer;
21import org.jboss.as.embedded.EmbeddedServerFactory;
22import org.jboss.as.embedded.EmbeddedStandAloneServerFactory;
23import org.jboss.as.embedded.StandaloneServer;
24
25/**
26 * {@link org.jboss.arquillian.container.spi.client.container.DeployableContainer} implementation to bootstrap JBoss Logging (installing the LogManager if possible), use the JBoss
27 * Modules modular ClassLoading Environment to create a new server instance, and handle lifecycle of the Application Server in
28 * the currently-running environment.
29 *
30 * @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a>
31 * @author <a href="mailto:mmatloka@gmail.com">Michal Matloka</a>
32 * @author Thomas.Diesler@jboss.com
33 */
34public final class EmbeddedDeployableContainer extends CommonDeployableContainer<EmbeddedContainerConfiguration> {
35
36    /**
37     * Hook to the server; used in start/stop, created by setup
38     */
39    private StandaloneServer server;
40
41    @Override
42    public void setup(final EmbeddedContainerConfiguration config) {
43        super.setup(config);
44        if (config.getCleanServerBaseDir() != null) {
45            SecurityActions.setSystemProperty(EmbeddedStandAloneServerFactory.JBOSS_EMBEDDED_ROOT, config.getCleanServerBaseDir());
46        }
47        server = EmbeddedServerFactory.create(config.getJbossHome(), config.getModulePath(), config.getBundlePath());
48    }
49
50    @Override
51    public Class<EmbeddedContainerConfiguration> getConfigurationClass() {
52        return EmbeddedContainerConfiguration.class;
53    }
54
55    @Override
56    protected void startInternal() throws LifecycleException {
57        try {
58            server.start();
59        } catch (Throwable e) {
60            throw new LifecycleException("Could not invoke start on: " + server, e);
61        }
62    }
63
64    @Override
65    protected void stopInternal() throws LifecycleException {
66        try {
67            server.stop();
68        } catch (Throwable e) {
69            throw new LifecycleException("Could not invoke stop on: " + server, e);
70        }
71    }
72}