/** * Deploy a new repository with the given configuration. This method will fail if this engine already contains a repository * with the specified name. * * @param repositoryConfiguration the configuration for the repository * @return the deployed repository instance, which must be {@link #startRepository(String) started} before it can be used; * never null * @throws ConfigurationException if the configuration is not valid * @throws RepositoryException if there is already a deployed repository with the specified name, or if there is a problem * deploying the repository * @throws IllegalArgumentException if the configuration is null * @see #deploy(RepositoryConfiguration) * @see #update(String, Changes) * @see #undeploy(String) */ public JcrRepository deploy( final RepositoryConfiguration repositoryConfiguration ) throws ConfigurationException, RepositoryException { return deploy(repositoryConfiguration, null); }
/** * Method that shuts down the JDNI repository factory's engine, usually for testing purposes. * * @return a future that allows the caller to block until the engine is shutdown; any error during shutdown will be thrown * when {@link Future#get() getting} the result from the future, where the exception is wrapped in a * {@link ExecutionException}. The value returned from the future will always be true if the engine shutdown (or was * not running), or false if the engine is still running. */ static Future<Boolean> shutdown() { return ENGINE.shutdown(); }
protected ModeShapeEngine engine() { // Make sure the engine is started ... switch (ENGINE.getState()) { case NOT_RUNNING: ENGINE.start(); break; case STOPPING: // Wait until it's shutdown ... try { ENGINE.shutdown().get(10, TimeUnit.SECONDS); } catch (Exception e) { // ignore and let if fail ... } break; case RESTORING: case RUNNING: case STARTING: // do nothing ... } return ENGINE; }
public synchronized ModeShapeEngine getEngine() { if (engine == null) { ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); this.engine = engine; } return engine; } }
private JcrRepository lookForAlreadyDeployedRepositoryKey( String key ) { if (engine().getRepositoryKeys().contains(key)) { try { return engine().getRepository(key); } catch (NoSuchRepositoryException e) { // Must have been removed since we checked, so just continue on to redeploy it ... } } return null; }
public static void main( String[] argv ) { ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); repository = engine.deploy(config); repositoryName = config.getName(); } catch (Throwable e) { try { repository = engine.getRepository(repositoryName); System.out.println("Shutting down engine ..."); try { engine.shutdown().get(); System.out.println("Success!"); } catch (Exception e) {
@Test public void shouldNotAutomaticallyStartDeployedRepositories() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); engine.startRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); engine.shutdownRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); }
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileNotRunning() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(Default.MINIMUM_BINARY_SIZE_IN_BYTES)); // Change the configuration ... long newLargeValueSizeInBytes = Default.MINIMUM_BINARY_SIZE_IN_BYTES * 2; Editor editor = repository.getConfiguration().edit(); EditableDocument binaryStorage = editor.getOrCreateDocument(FieldName.STORAGE) .getOrCreateDocument(FieldName.BINARY_STORAGE); binaryStorage.setNumber(FieldName.MINIMUM_BINARY_SIZE_IN_BYTES, newLargeValueSizeInBytes); Changes changes = editor.getChanges(); // Apply the changes to the deployed repository ... engine.update(name, changes).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); }
ENGINE.start(); JcrRepository repository = ENGINE.getRepository(repositoryName); switch (repository.getState()) { case STARTING: ENGINE.start(); JcrRepository repository = ENGINE.deploy(config); try { ENGINE.startRepository(repository.getName()).get(); } catch (InterruptedException e) { Thread.interrupted();
engine = new ModeShapeEngine(); engine.start(); repository = engine.deploy(configuration); engine.startRepository(repository.getName()).get();
@Override public Repository getRepository(Map parameters) throws RepositoryException { String name = (String) parameters.get(org.modeshape.jcr.api.RepositoryFactory.REPOSITORY_NAME); logger.info("Accessing repository " + name); Map defaultParameters = getRepositoryConfiguration(name); defaultParameters.putAll(parameters); if (!engine.getRepositoryNames().contains(name)) { try { File configurationFile = new File(new File(applicationConfiguration.getBaseDir(), "conf"), (String) defaultParameters.get(org.modeshape.jcr.api.RepositoryFactory.URL)); engine.deploy(RepositoryConfiguration.read(configurationFile)); } catch (ParsingException e) { logger.error(e.getMessage(), e); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } } return engine.getRepository(name); }
protected void startEngineAndDeployRepositoryAndLogIn() throws Exception { print("starting engine"); engine.start(); assertThat(engine.getState(), is(State.RUNNING)); print("deploying repository"); repository = engine.deploy(config); session = repository.login(); assertThat(session.getRootNode(), is(notNullValue())); }
repository = engine.getRepository(repositoryName); } catch (NoSuchRepositoryException e) { throw new StartException(e); engine.update(this.repositoryName, configEditor.getChanges()); } catch (Exception e) { throw new StartException(e);
@Test public void shouldAllowUpdatingSequencerInformationWhenRunning() throws Exception { URL configUrl = getClass().getClassLoader().getResource("config/repo-config.json"); engine.start(); config = RepositoryConfiguration.read(configUrl).with(environment); JcrRepository repository = engine.deploy(config); engine.update(config.getName(), changes).get(); // don't forget to wait! RepositoryConfiguration config2 = engine.getRepositoryConfiguration(config.getName()); Document sequencerA2 = (Document)config2.getDocument() .getDocument(FieldName.SEQUENCING)
/** * Get the immutable configuration for the repository with the supplied name. * * @param repositoryName the name of the deployed repository * @return the repository configuration; never null * @throws IllegalArgumentException if the repository name is null, blank or invalid * @throws NoSuchRepositoryException if there is no repository with the specified name * @throws IllegalStateException if this engine is not {@link #getState() running} */ public final RepositoryConfiguration getRepositoryConfiguration( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).getConfiguration(); }
@SuppressWarnings( "synthetic-access" ) @Override public void objectRemoved( NamingEvent evt ) { Object oldObject = evt.getOldBinding().getObject(); if (!(oldObject instanceof JcrRepository)) return; JcrRepository repository = (JcrRepository)oldObject; String repoName = repository.getName(); try { ENGINE.shutdownRepository(repoName).get(); } catch (NoSuchRepositoryException e) { // Ignore this ... } catch (InterruptedException ie) { LOG.error(ie, JcrI18n.errorWhileShuttingDownRepositoryInJndi, repoName, jndiName); // Thread.interrupted(); } catch (ExecutionException e) { LOG.error(e.getCause(), JcrI18n.errorWhileShuttingDownRepositoryInJndi, repoName, jndiName); } finally { // Try to shutdown the repository only if there are no more running repositories. // IOW, shutdown but do not force shutdown of running repositories ... ENGINE.shutdown(false); // no need to block on the futured returned by 'shutdown(boolean)' } }
public static void shutdownEngine() { if (engine != null && engine.checkRunning()) { engine.shutdown(); engine = null; reloadRepositoryInstance = true; } }
final String repoName = repository.getName(); try { final Future<Boolean> futureUndeployRepo = modeShapeEngine.undeploy(repoName); if (futureUndeployRepo.get()) { LOGGER.info("ModeShape repository {} has undeployed.", repoName); LOGGER.error("Repository {} cannot undeploy.", repoName, e.getCause()); final Future<Boolean> futureShutdownEngine = modeShapeEngine.shutdown(); try { if (futureShutdownEngine.get()) {