public void shutdown() throws ApplicationShutdownException { if(!this.state.isShutdown()) { this.lifecycleEnvironment.stop(); LOGGER.info("Application '{}' ({}) stopped.",this.application.getName(),this.application.getClass().getCanonicalName()); if(this.application!=null) { this.application.shutdown(); LOGGER.info("Application '{}' ({}) shutdown.",this.application.getName(),this.application.getClass().getCanonicalName()); } notifyApplicationStateChange(ApplicationState.SHUTDOWN); } }
public String getApplicationName() { return this.application!=null?this.application.getName():"<unknown>"; }
private T instantiateConfiguration(Application<T> app) throws ApplicationContextBootstrapException { try { Class<T> configurationClass = app.getConfigurationClass(); return configurationClass.newInstance(); } catch (InstantiationException e) { throw new ApplicationContextBootstrapException("Could not load configuration", e); } catch (IllegalAccessException e) { throw new ApplicationContextBootstrapException("Could not load configuration", e); } }
private void initialize(Application<T> application) throws ApplicationConfigurationException { Transaction transaction=this.transactionManager.currentTransaction(); transaction.begin(); try { WriteSession session = writeSessionService(). createSession( WriteSessionConfiguration. builder(). build()); Throwable failure=null; try { application.initialize(session); } catch (ApplicationInitializationException e) { failure=e; } finally { failure=closeQuietly(session, failure); } if(failure!=null) { throw new ApplicationConfigurationException(failure); } } finally { if(transaction.isActive()) { transaction.rollback(); } } }
private void setup(Application<T> application) throws ApplicationConfigurationException { BootstrapImpl<T> bootstrap= new BootstrapImpl<T>( this.configuration, templateManagementService()); this.lifecycleEnvironment=new DefaultLifecycleEnvironment(); EnvironmentImpl environment= new EnvironmentImpl( templateManagementService(), resourceFactory(), RuntimeDelegate.getInstance().getEndpointRepository(), RuntimeDelegate.getInstance().getResourceRepository(), lifecycleEnvironment ); try { application.setup(environment,bootstrap); bootstrap.configureTemplates(); environment.configureRootResources(); } catch (ApplicationSetupException e) { throw new ApplicationConfigurationException(e); } }
private String applicationFailureMessage(String message, Object... objects) { return "[" + this.application.getName() + "] " + String.format(message,objects); }
/** * {@inheritDoc} */ @Override public String applicationName() { return application().getName(); }
public <T extends Configuration> Application<T> initialize(String className) throws ApplicationContextCreationException { checkState(this.state.canInitialize(),"Application cannot be initialized at this moment ("+this.state+")"); if(className==null) { notifyApplicationStateChange(ApplicationState.UNDEFINED); throw new ApplicationContextCreationException("No LDP4j application class specified"); } ApplicationState newState = ApplicationState.UNAVAILABLE; try { ApplicationLoader<T> helper = ApplicationLoader.newInstance(this.<T>loadApplicationClass(className)); Application<T> createdApplication = helper.bootstrap(); newState=ApplicationState.AVAILABLE; this.application=createdApplication; this.configuration=helper.configuration(); this.lifecycleEnvironment=helper.lifecycleEnvironment(); LOGGER.info("Application '{}' ({}) initialized.",this.application.getName(),this.application.getClass().getCanonicalName()); this.lifecycleEnvironment.start(ApplicationContext.getInstance()); LOGGER.info("Application '{}' ({}) started.",this.application.getName(),this.application.getClass().getCanonicalName()); return createdApplication; } catch (ApplicationContextBootstrapException e) { throw e; } finally { notifyApplicationStateChange(newState); } }