/** * Refresh the node types from the stored representation. * * @return true if there was at least one node type found, or false if there were none */ protected boolean refreshFromSystem() { this.nodeTypesLock.writeLock().lock(); try { // Re-read and re-register all of the node types ... SessionCache systemCache = repository.createSystemSession(context, true); SystemContent system = new SystemContent(systemCache); Collection<NodeTypeDefinition> nodeTypes = system.readAllNodeTypes(); if (nodeTypes.isEmpty()) return false; registerNodeTypes(nodeTypes, false, false, false); return true; } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); return false; } finally { this.nodeTypesLock.writeLock().unlock(); } }
/** * Refresh the node types from the stored representation. * * @return true if there was at least one node type found, or false if there were none */ protected boolean refreshFromSystem() { this.nodeTypesLock.writeLock().lock(); try { // Re-read and re-register all of the node types ... SessionCache systemCache = repository.createSystemSession(context, true); SystemContent system = new SystemContent(systemCache); Collection<NodeTypeDefinition> nodeTypes = system.readAllNodeTypes(); if (nodeTypes.isEmpty()) return false; registerNodeTypes(nodeTypes, false, false, false); return true; } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingNodeTypes, repository.name()); return false; } finally { this.nodeTypesLock.writeLock().unlock(); } }
protected Set<SequencerPathExpression> buildPathExpressionSet( Sequencer sequencer ) throws InvalidSequencerPathExpression { String[] pathExpressions = sequencer.getPathExpressions(); if (pathExpressions.length == 0) { String msg = RepositoryI18n.atLeastOneSequencerPathExpressionMustBeSpecified.text(repository.name(), sequencer.getName()); throw new InvalidSequencerPathExpression(msg); } // Compile the path expressions ... Set<SequencerPathExpression> result = new LinkedHashSet<SequencerPathExpression>(); for (String pathExpression : pathExpressions) { assert pathExpression != null; assert pathExpression.length() != 0; SequencerPathExpression expression = SequencerPathExpression.compile(pathExpression); result.add(expression); } return Collections.unmodifiableSet(result); }
RepositoryIndexManager( JcrRepository.RunningState repository, RepositoryConfiguration config ) { this.repository = repository; this.config = config; this.context = repository.context(); this.systemWorkspaceName = this.repository.repositoryCache().getSystemWorkspaceName(); PathFactory pathFactory = this.context.getValueFactories().getPathFactory(); this.indexesPath = pathFactory.createAbsolutePath(JcrLexicon.SYSTEM, ModeShapeLexicon.INDEXES); // Set up the index providers ... this.components = config.getIndexProviders(); for (Component component : components) { try { IndexProvider provider = component.createInstance(); register(provider); } catch (Throwable t) { if (t.getCause() != null) { t = t.getCause(); } this.repository.error(t, JcrI18n.unableToInitializeIndexProvider, component, repository.name(), t.getMessage()); } } }
@Override public synchronized void register( IndexProvider provider ) throws RepositoryException { if (providers.containsKey(provider.getName())) { throw new IndexProviderExistsException(JcrI18n.indexProviderAlreadyExists.text(provider.getName(), repository.name())); } // Set the repository name field ... Reflection.setValue(provider, "repositoryName", repository.name()); // Set the logger instance Reflection.setValue(provider, "logger", ExtensionLogger.getLogger(provider.getClass())); // Set the name of the system workspace Reflection.setValue(provider, "systemWorkspaceName", systemWorkspaceName); if (initialized.get()) { // This manager is already initialized, so we have to initialize the new provider ... doInitialize(provider); } // Do this last so that it doesn't show up in the list of providers before it's properly initialized ... IndexProvider existing = providers.putIfAbsent(provider.getName(), provider); if (existing != null) { throw new IndexProviderExistsException(JcrI18n.indexProviderAlreadyExists.text(provider.getName(), repository.name())); } // Re-read the index definitions in case there were disabled index definitions that used the now-available provider ... readIndexDefinitions(); // Refresh the index writer ... refreshIndexWriter(); }
protected Connector instantiateConnector( Component component ) { try { // Instantiate the connector and set the 'name' field ... Connector connector = component.createInstance(); // Set the repository name field ... Reflection.setValue(connector, "repositoryName", repository.name()); // Set the logger instance Reflection.setValue(connector, "logger", Logger.getLogger(connector.getClass())); // Set the logger instance Reflection.setValue(connector, "simpleLogger", ExtensionLogger.getLogger(connector.getClass())); // We'll initialize it later in #intialize() ... return connector; } catch (Throwable t) { if (t.getCause() != null) { t = t.getCause(); } logger.error(t, JcrI18n.unableToInitializeConnector, component, repository.name(), t.getMessage()); return null; } }
/** * Initialize the supplied provider. * * @param provider the provider; may not be null * @throws RepositoryException if there is a problem initializing the provider */ protected void doInitialize( IndexProvider provider ) throws RepositoryException { // Set the execution context instance ... Reflection.setValue(provider, "context", repository.context()); // Set the environment Reflection.setValue(provider, "environment", repository.environment()); provider.initialize(); // If successful, call the 'postInitialize' method reflectively (due to inability to call directly) ... Method postInitialize = Reflection.findMethod(IndexProvider.class, "postInitialize"); Reflection.invokeAccessibly(provider, postInitialize, new Object[] {}); if (logger.isDebugEnabled()) { logger.debug("Successfully initialized index provider '{0}' in repository '{1}'", provider.getName(), repository.name()); } }
/** * Initialize the supplied provider. * * @param provider the provider; may not be null * @throws RepositoryException if there is a problem initializing the provider */ protected void doInitialize( IndexProvider provider ) throws RepositoryException { // Set the execution context instance ... Reflection.setValue(provider, "context", repository.context()); // Set the environment Reflection.setValue(provider, "environment", repository.environment()); provider.initialize(); // If successful, call the 'postInitialize' method reflectively (due to inability to call directly) ... Method postInitialize = Reflection.findMethod(IndexProvider.class, "postInitialize"); Reflection.invokeAccessibly(provider, postInitialize, new Object[] {}); if (logger.isDebugEnabled()) { logger.debug("Successfully initialized index provider '{0}' in repository '{1}'", provider.getName(), repository.name()); } }
protected Connector instantiateConnector( Component component ) { try { // Instantiate the connector and set the 'name' field ... Connector connector = component.createInstance(); // Set the repository name field ... Reflection.setValue(connector, "repositoryName", repository.name()); // Set the logger instance Reflection.setValue(connector, "logger", Logger.getLogger(connector.getClass())); // Set the logger instance Reflection.setValue(connector, "simpleLogger", ExtensionLogger.getLogger(connector.getClass())); // We'll initialize it later in #intialize() ... return connector; } catch (Throwable t) { if (t.getCause() != null) { t = t.getCause(); } logger.error(t, JcrI18n.unableToInitializeConnector, component, repository.name(), t.getMessage()); return null; } }
private static List<TextExtractor> getConfiguredExtractors( JcrRepository.RunningState repository, RepositoryConfiguration.TextExtraction extracting ) { List<Component> extractorComponents = extracting.getTextExtractors(repository.problems()); List<TextExtractor> extractors = new ArrayList<>(extractorComponents.size()); for (Component component : extractorComponents) { try { TextExtractor extractor = component.createInstance(); extractor.setLogger(ExtensionLogger.getLogger(extractor.getClass())); extractors.add(extractor); } catch (Throwable t) { String desc = component.getName(); String repoName = repository.name(); repository.error(t, JcrI18n.unableToInitializeTextExtractor, desc, repoName, t.getMessage()); } } return extractors; }
@Override public void unregisterIndexes( String... indexNames ) throws NoSuchIndexException, RepositoryException { if (indexNames == null || indexNames.length == 0) return; // Remove the definition from the system area ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); for (String indexName : indexNames) { IndexDefinition defn = indexes.getIndexDefinitions().get(indexName); if (defn == null) { throw new NoSuchIndexException(JcrI18n.indexDoesNotExist.text(indexName, repository.name())); } system.remove(defn); } system.save(); // Refresh the immutable snapshot ... this.indexes = readIndexDefinitions(); }
protected Set<SequencerPathExpression> buildPathExpressionSet( Sequencer sequencer ) throws InvalidSequencerPathExpression { String[] pathExpressions = sequencer.getPathExpressions(); if (pathExpressions.length == 0) { String msg = RepositoryI18n.atLeastOneSequencerPathExpressionMustBeSpecified.text(repository.name(), sequencer.getName()); throw new InvalidSequencerPathExpression(msg); } // Compile the path expressions ... Set<SequencerPathExpression> result = new LinkedHashSet<SequencerPathExpression>(); for (String pathExpression : pathExpressions) { assert pathExpression != null; assert pathExpression.length() != 0; SequencerPathExpression expression = SequencerPathExpression.compile(pathExpression); result.add(expression); } return Collections.unmodifiableSet(result); }
protected RepositoryIndexes readIndexDefinitions() { // There were at least some changes ... NodeTypes nodeTypes = repository.nodeTypeManager().getNodeTypes(); try { // Read the affected index definitions ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<IndexDefinition> indexDefns = system.readAllIndexDefinitions(providers.keySet()); this.indexes = new Indexes(context, indexDefns, nodeTypes); return this.indexes; } catch (WorkspaceNotFoundException e) { // This happens occasionally when shutting down ... } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingIndexDefinitions, repository.name()); } return indexes; }
@Override public void unregisterIndexes( String... indexNames ) throws NoSuchIndexException, RepositoryException { if (indexNames == null || indexNames.length == 0) return; // Remove the definition from the system area ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); for (String indexName : indexNames) { IndexDefinition defn = indexes.getIndexDefinitions().get(indexName); if (defn == null) { throw new NoSuchIndexException(JcrI18n.indexDoesNotExist.text(indexName, repository.name())); } system.remove(defn); } system.save(); // Refresh the immutable snapshot ... this.indexes = readIndexDefinitions(); }
private static List<TextExtractor> getConfiguredExtractors( JcrRepository.RunningState repository, RepositoryConfiguration.TextExtraction extracting ) { List<Component> extractorComponents = extracting.getTextExtractors(repository.problems()); List<TextExtractor> extractors = new ArrayList<>(extractorComponents.size()); for (Component component : extractorComponents) { try { TextExtractor extractor = component.createInstance(); extractor.setLogger(ExtensionLogger.getLogger(extractor.getClass())); extractors.add(extractor); } catch (Throwable t) { String desc = component.getName(); String repoName = repository.name(); repository.error(t, JcrI18n.unableToInitializeTextExtractor, desc, repoName, t.getMessage()); } } return extractors; }
protected RepositoryIndexes readIndexDefinitions() { // There were at least some changes ... NodeTypes nodeTypes = repository.nodeTypeManager().getNodeTypes(); try { // Read the affected index definitions ... SessionCache systemCache = repository.createSystemSession(context, false); SystemContent system = new SystemContent(systemCache); Collection<IndexDefinition> indexDefns = system.readAllIndexDefinitions(providers.keySet()); this.indexes = new Indexes(context, indexDefns, nodeTypes); return this.indexes; } catch (WorkspaceNotFoundException e) { // This happens occasionally when shutting down ... } catch (Throwable e) { logger.error(e, JcrI18n.errorRefreshingIndexDefinitions, repository.name()); } return indexes; }
@Override public void unregister( String providerName ) throws RepositoryException { IndexProvider provider = providers.remove(providerName); if (provider == null) { throw new NoSuchProviderException(JcrI18n.indexProviderDoesNotExist.text(providerName, repository.name())); } if (initialized.get()) { provider.shutdown(); } // Re-read the index definitions in case there were disabled index definitions that used the now-available provider ... readIndexDefinitions(); // Refresh the index writer ... refreshIndexWriter(); }
@Override public void unregister( String providerName ) throws RepositoryException { IndexProvider provider = providers.remove(providerName); if (provider == null) { throw new NoSuchProviderException(JcrI18n.indexProviderDoesNotExist.text(providerName, repository.name())); } if (initialized.get()) { provider.shutdown(); } // Re-read the index definitions in case there were disabled index definitions that used the now-available provider ... readIndexDefinitions(); // Refresh the index writer ... refreshIndexWriter(); }
void shutdown() { for (IndexProvider provider : providers.values()) { try { provider.shutdown(); } catch (RepositoryException e) { logger.error(e, JcrI18n.errorShuttingDownIndexProvider, repository.name(), provider.getName(), e.getMessage()); } } }
void shutdown() { for (IndexProvider provider : providers.values()) { try { provider.shutdown(); } catch (RepositoryException e) { logger.error(e, JcrI18n.errorShuttingDownIndexProvider, repository.name(), provider.getName(), e.getMessage()); } } }