@PostConstruct protected void init() { storeRoot = SnowOwlApplication.INSTANCE.getEnviroment().getDataDirectory().getPath(); }
/** * Bootstraps the application with a default configuration. * * @throws Exception * @see {@link #bootstrap(String)} */ public void bootstrap() throws Exception { bootstrap(null); }
/** * Runs the application without any {@link PreRunRunnable} and the given * monitor. * * @param monitor * @throws Exception * @see #run(PreRunRunnable, IProgressMonitor) */ public void run(IProgressMonitor monitor) throws Exception { run(null, monitor); }
/** * Bootstraps the application to a minimum runnable form. * * @param configPath * - the configuration file path to use * @param fragments - additional {@link BootstrapFragment} instances to use during initialization */ public void bootstrap(String configPath, BootstrapFragment...fragments) throws Exception { if (!isRunning()) { LOG.info("Bootstrapping Snow Owl..."); this.bootstrap = new Bootstrap(fragments); this.configuration = createConfiguration(bootstrap, configPath); this.environment = new Environment(bootstrap, configuration); logEnvironment(); this.bootstrap.init(this.configuration, this.environment); // after init checks try { this.environment.service(IUserManager.class); } catch (Exception e) { throw new InitializationException("UserManager should be registered after the bootstrap process."); } } }
/** * Runs the application by performing all necessary initialization logic * like service registrations, etc. * * @param preRunRunnable * - to execute logic between * {@link Bootstrap#preRun(SnowOwlConfiguration, Environment)} * and * {@link Bootstrap#run(SnowOwlConfiguration, Environment, IProgressMonitor)} * @param monitor * - to monitor application startup */ public void run(PreRunRunnable preRunRunnable, IProgressMonitor monitor) throws Exception { if (!isRunning()) { checkState(bootstrap != null, "Bootstrap the application first"); if (preRunCompleted.compareAndSet(false, true)) { this.bootstrap.preRun(configuration, environment); } if (preRunRunnable != null) { preRunRunnable.run(); } LOG.info("Preparing to run Snow Owl..."); this.bootstrap.run(configuration, environment, monitor); checkApplicationState(); running.set(true); LOG.info("Snow Owl successfully started."); } else { LOG.info("Snow Owl is already running."); } }
/** * Shuts down the Snow Owl application by performing shut down logic. */ public void shutdown() { if (isRunning()) { LOG.info("Snow Owl is shutting down."); this.environment.services().dispose(); LifecycleUtil.deactivate(environment.container()); running.set(false); } }
/** * Checks the current application state and throws exceptions if errors have * been found. * * @throws InitializationException * - on application init failures */ private void checkApplicationState() throws InitializationException { // check all registered services final Collection<ServiceRegistryEntry<?>> failedServices = this.environment.services().checkStrictServices(); if (!failedServices.isEmpty()) { final String errorMessage = serviceRegistryErrorMessage(failedServices); throw new InitializationException(errorMessage); } }
private SnowOwlConfiguration createConfiguration(Bootstrap bootstrap, String configPath) throws Exception { if (Strings.isNullOrEmpty(configPath)) { configPath = getDefaultConfigPath(bootstrap); } final Validator validator = ValidationUtil.getValidator(); final ConfigurationFactory<SnowOwlConfiguration> factory = new ConfigurationFactory<SnowOwlConfiguration>(SnowOwlConfiguration.class, validator); factory.setAdditionalModules(bootstrap.getModuleConfigurations()); return configPath != null ? factory.build(new FileConfigurationSourceProvider(), configPath) : factory.build(); }
@PostConstruct protected void init() { LOG.info("Initializing classification service; keeping indexed data for {} recent run(s).", getMaxReasonerRuns()); final File dir = new File(new File(SnowOwlApplication.INSTANCE.getEnviroment().getDataDirectory(), "indexes"), "classification_runs"); indexService = new ClassificationRunIndex(dir); ApplicationContext.getInstance().getServiceChecked(SingleDirectoryIndexManager.class).registerIndex(indexService); try { indexService.trimIndex(getMaxReasonerRuns()); indexService.invalidateClassificationRuns(); } catch (final IOException e) { LOG.error("Failed to run housekeeping tasks for the classification index.", e); } // TODO: common ExecutorService for asynchronous work? executorService = Executors.newCachedThreadPool(); remoteJobSubscription = getNotifications() .ofType(RemoteJobNotification.class) .subscribe(this::onRemoteJobNotification); initialized = true; }
/** * Runs the Snow Owl application by performing all necessary initialization * logic. Uses a <code>null</code> {@link PreRunRunnable} and a * {@link NullProgressMonitor} instance. * * @throws Exception * @see {@link #run(IProgressMonitor)} * @see #run(PreRunRunnable, IProgressMonitor) */ public void run() throws Exception { run(new NullProgressMonitor()); }
@Override protected void doBeforeActivate() throws Exception { //read extension points first, then create managed items super.doBeforeActivate(); Net4jUtil.prepareContainer(IPluginContainer.INSTANCE); JVMUtil.prepareContainer(IPluginContainer.INSTANCE); TCPUtil.prepareContainer(IPluginContainer.INSTANCE); CDONet4jUtil.prepareContainer(IPluginContainer.INSTANCE); CDONet4jServerUtil.prepareContainer(IPluginContainer.INSTANCE); registerCustomProtocols(); LifecycleUtil.activate(IPluginContainer.INSTANCE); final HostAndPort hostAndPort = getRepositoryConfiguration().getHostAndPort(); // open port in server environments if (SnowOwlApplication.INSTANCE.getEnviroment().isServer()) { IAcceptor acceptor = TCPUtil.getAcceptor(IPluginContainer.INSTANCE, hostAndPort.toString()); // Start the TCP transport if (getSnowOwlConfiguration().isGzip()) { IPluginContainer.INSTANCE.addPostProcessor(new TcpGZIPStreamWrapperInjector(CDOProtocolConstants.PROTOCOL_NAME, acceptor)); } LOGGER.info("Listening on {} for connections", hostAndPort); } JVMUtil.getAcceptor(IPluginContainer.INSTANCE, Net4jUtils.NET_4_J_CONNECTOR_NAME); // Start the JVM transport }