/refapp-core/src/main/java/com/atlassian/plugin/refimpl/RefappLauncher.java
Java | 108 lines | 68 code | 13 blank | 27 comment | 0 complexity | ce7a977006c276dac35f46260c6e508f MD5 | raw file
- package com.atlassian.plugin.refimpl;
- import com.atlassian.plugin.PluginAccessor;
- import com.atlassian.plugin.SplitStartupPluginSystemLifecycle;
- import com.atlassian.plugin.main.AtlassianPlugins;
- import com.atlassian.plugin.refimpl.db.SchemaCreator;
- import com.atlassian.scheduler.SchedulerServiceException;
- import com.atlassian.scheduler.core.SchedulerServiceController;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.context.annotation.Bean;
- import javax.annotation.ParametersAreNonnullByDefault;
- import java.util.Optional;
- import static java.util.Objects.requireNonNull;
- /**
- * Launches Refapp.
- *
- * @since 5.4 renamed from ContainerManager and had all its object creation code moved to Spring Java configuration.
- */
- @ParametersAreNonnullByDefault
- public class RefappLauncher {
- private static final Logger LOGGER = LoggerFactory.getLogger(RefappLauncher.class);
- private final AtlassianPlugins pluginSystem;
- private final PluginAccessor pluginAccessor;
- private final SchedulerServiceController schedulerServiceController;
- private final SchemaCreator schemaCreator;
- private final SplitStartupPluginSystemLifecycle pluginSystemLifecycle;
- /**
- * Constructor.
- *
- * @param pluginSystem the plugin system
- * @param pluginAccessor the plugin accessor
- * @param schedulerServiceController the scheduler service controller
- * @param schemaCreator the schema creator
- * @param pluginSystemLifecycle the plugin lifecycle
- */
- public RefappLauncher(final AtlassianPlugins pluginSystem,
- final PluginAccessor pluginAccessor,
- final SchedulerServiceController schedulerServiceController,
- final SchemaCreator schemaCreator,
- final SplitStartupPluginSystemLifecycle pluginSystemLifecycle) {
- this.pluginAccessor = requireNonNull(pluginAccessor);
- this.pluginSystem = requireNonNull(pluginSystem);
- this.pluginSystemLifecycle = requireNonNull(pluginSystemLifecycle);
- this.schedulerServiceController = requireNonNull(schedulerServiceController);
- this.schemaCreator = requireNonNull(schemaCreator);
- }
- /**
- * Starts Refapp.
- *
- * @see #shutdown()
- */
- public void launch() {
- loadJavaxXmlTransformFactoryFinderClassBeforePluginsDo();
- schemaCreator.createSchema();
- startScheduler();
- startPluginSystem();
- logStartupMessage();
- }
- // See https://ecosystem.atlassian.net/browse/REFAPP-353
- private static void loadJavaxXmlTransformFactoryFinderClassBeforePluginsDo() {
- try {
- Class.forName("javax.xml.transform.FactoryFinder");
- } catch (final ClassNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
- private void startScheduler() {
- try {
- schedulerServiceController.start();
- } catch (final SchedulerServiceException e) {
- throw new IllegalStateException("Failed to start scheduler", e);
- }
- }
- private void startPluginSystem() {
- pluginSystemLifecycle.init();
- pluginAccessor.getPlugins(); // presumably called for its side effect(s)
- }
- private static void logStartupMessage() {
- Optional.ofNullable(System.getProperty("baseurl.display"))
- .ifPresent(baseUrl -> LOGGER.info("\n\n*** Refapp started on {}\n\n", baseUrl));
- }
- /**
- * Shuts down this instance. "shutdown" is a special method that Spring calls on @Bean instances by default.
- *
- * @see Bean#destroyMethod() for the list of these special method names
- */
- @SuppressWarnings("unused") // called by Spring, see Javadoc
- public void shutdown() {
- // Shutdown plugins before stopping the scheduler, because many plugins attempt to unregister
- // jobs and/or job runners when they stop
- pluginSystemLifecycle.shutdown();
- pluginSystem.destroy();
- schedulerServiceController.shutdown();
- }
- }