private JcrRepository lookForAlreadyDeployedRepositoryName( String name ) { if (engine().getRepositoryNames().contains(name)) { try { return engine().getRepository(name); } catch (NoSuchRepositoryException e) { // Must have been removed since we checked, so just continue on to redeploy it ... } } return null; }
/** * 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(); }
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; }
@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)); }
/** * 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(); }
private JcrRepository lookForAlreadyDeployedRepositoryName( String name ) { if (engine().getRepositoryNames().contains(name)) { try { return engine().getRepository(name); } catch (NoSuchRepositoryException e) { // Must have been removed since we checked, so just continue on to redeploy it ... } } return null; }
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; }
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileRunning() 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)); long defaultLargeValueSize = Default.MINIMUM_BINARY_SIZE_IN_BYTES; assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(defaultLargeValueSize)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(defaultLargeValueSize)); // Change the configuration. We'll do something simple, like changing the large value size ... long newLargeValueSizeInBytes = defaultLargeValueSize * 2L; 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.RUNNING)); // Verify the running repository and its configuraiton are using the new value ... RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(newLargeValueSizeInBytes)); }
/** * Get the state of the deployed {@link Repository} instance with the given the name. * * @param repositoryName the name of the deployed repository * @return the state of the repository instance; 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} * @see #deploy(RepositoryConfiguration) * @see #undeploy(String) */ public final State getRepositoryState( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).getState(); }
@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); }
public static void killEngine( ModeShapeEngine engine ) { if (engine == null) return; try { if (engine.getState() != State.RUNNING) return; engine.getRepositoryKeys().forEach(key -> { try { TestingUtil.killRepository(engine.getRepository(key)); } catch (NoSuchRepositoryException e) { //ignore } }); } catch (Throwable t) { log.error(t, JcrI18n.errorKillingEngine, t.getMessage()); } }
/** * Get the state of the deployed {@link Repository} instance with the given the name. * * @param repositoryName the name of the deployed repository * @return the state of the repository instance; 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} * @see #deploy(RepositoryConfiguration) * @see #undeploy(String) */ public final State getRepositoryState( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).getState(); }
@Override public JcrRepository getValue() throws IllegalStateException, IllegalArgumentException { try { return getEngine().getRepository(repositoryName()); } catch (NoSuchRepositoryException e) { throw new IllegalStateException(e); } }
/** * Asynchronously shutdown the deployed {@link Repository} instance with the given the name, and return a future that will * return whether the Repository instance is shutdown. If the Repository is not running, the resulting future will return * immediately. * <p> * Note that the caller does not have to wait for the shutdown to completed. However, to do so the caller merely calls * {@link Future#get() get()} or {@link Future#get(long, TimeUnit) get(long,TimeUnit)} on the future to return a boolean flag * specifying whether the Repository instance is shutdown (not running). Note that any exceptions thrown during the shutdown * will be wrapped in an {@link ExecutionException} thrown by the Future's <code>get</code> methods. * </p> * * @param repositoryName the name of the deployed repository * @return a future wrapping the asynchronous shutdown process; never null, and {@link Future#get()} will return whether the * @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} * @see #deploy(RepositoryConfiguration) * @see #undeploy(String) */ public final Future<Boolean> shutdownRepository( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).shutdown(); }
/** * Asynchronously shutdown the deployed {@link Repository} instance with the given the name, and return a future that will * return whether the Repository instance is shutdown. If the Repository is not running, the resulting future will return * immediately. * <p> * Note that the caller does not have to wait for the shutdown to completed. However, to do so the caller merely calls * {@link Future#get() get()} or {@link Future#get(long, TimeUnit) get(long,TimeUnit)} on the future to return a boolean flag * specifying whether the Repository instance is shutdown (not running). Note that any exceptions thrown during the shutdown * will be wrapped in an {@link ExecutionException} thrown by the Future's <code>get</code> methods. * </p> * * @param repositoryName the name of the deployed repository * @return a future wrapping the asynchronous shutdown process; never null, and {@link Future#get()} will return whether the * @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} * @see #deploy(RepositoryConfiguration) * @see #undeploy(String) */ public final Future<Boolean> shutdownRepository( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).shutdown(); }
final JcrRepository repository = getRepository(repositoryName); if (repository.getState() == State.RUNNING) { return ImmediateFuture.create(repository);
final JcrRepository repository = getRepository(repositoryName); if (repository.getState() == State.RUNNING) { return ImmediateFuture.create(repository);
@Override @SuppressWarnings( {"unchecked", "rawtypes"} ) public JcrRepository getRepository( String repositoryName, Map parameters ) throws RepositoryException { if (!StringUtil.isBlank(repositoryName)) { try { JcrRepository repository = engine().getRepository(repositoryName); if (repository.getState() == ModeShapeEngine.State.STARTING || repository.getState() == ModeShapeEngine.State.RUNNING) { return repository; } } catch (NoSuchRepositoryException e) { // there is no such repository, so try to create & initialize it } } String repositoryURL = repositoryURLFromParams(parameters); if (StringUtil.isBlank(repositoryURL)) { LOG.debug("No repository URL parameter found"); return null; } Map configParams = parameters; if (!StringUtil.isBlank(repositoryName)) { configParams = new HashMap(parameters); configParams.put(RepositoryFactory.REPOSITORY_NAME, repositoryName); } if (repositoryURL.toLowerCase().startsWith(JNDI_PROTOCOL)) { return new JNDIRepositoryLookup().repository(configParams, repositoryURL); } return new UrlRepositoryLookup().repository(configParams, repositoryURL); }
@Override @SuppressWarnings( {"unchecked", "rawtypes"} ) public JcrRepository getRepository( String repositoryName, Map parameters ) throws RepositoryException { if (!StringUtil.isBlank(repositoryName)) { try { JcrRepository repository = engine().getRepository(repositoryName); if (repository.getState() == ModeShapeEngine.State.STARTING || repository.getState() == ModeShapeEngine.State.RUNNING) { return repository; } } catch (NoSuchRepositoryException e) { // there is no such repository, so try to create & initialize it } } String repositoryURL = repositoryURLFromParams(parameters); if (StringUtil.isBlank(repositoryURL)) { LOG.debug("No repository URL parameter found"); return null; } Map configParams = parameters; if (!StringUtil.isBlank(repositoryName)) { configParams = new HashMap(parameters); configParams.put(RepositoryFactory.REPOSITORY_NAME, repositoryName); } if (repositoryURL.toLowerCase().startsWith(JNDI_PROTOCOL)) { return new JNDIRepositoryLookup().repository(configParams, repositoryURL); } return new UrlRepositoryLookup().repository(configParams, repositoryURL); }
repository = engine.getRepository(repositoryName); } catch (NoSuchRepositoryException e) { throw new StartException(e);