use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.
the class JMXAgent method addMBean.
@Override
public synchronized void addMBean(final PerInstanceMBean mbean) throws DatabaseConfigurationException {
try {
addMBean(mbean.getName(), mbean);
if (mbean.getInstanceId() != null) {
Deque<ObjectName> stack = registeredMBeans.get(mbean.getInstanceId());
if (stack == null) {
stack = new ArrayDeque<>();
registeredMBeans.put(mbean.getInstanceId(), stack);
}
stack.push(mbean.getName());
}
beanInstances.put(mbean.getName(), mbean);
} catch (final MalformedObjectNameException e) {
LOG.warn("Problem registering JMX MBean: {}", e.getMessage(), e);
throw new DatabaseConfigurationException("Exception while registering JMX MBean: " + e.getMessage());
}
}
use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.
the class LuceneIndex method open.
@Override
public void open() throws DatabaseConfigurationException {
Path dir = getDataDir().resolve(getDirName());
Path taxoDir = dir.resolve(TAXONOMY_DIR_NAME);
if (LOG.isDebugEnabled())
LOG.debug("Opening Lucene index directory: {}", dir.toAbsolutePath().toString());
IndexWriter writer = null;
try {
if (Files.exists(dir)) {
if (!Files.isDirectory(dir))
throw new DatabaseConfigurationException("Lucene index location is not a directory: " + dir.toAbsolutePath().toString());
} else {
Files.createDirectories(taxoDir);
}
directory = FSDirectory.open(dir.toFile());
taxoDirectory = FSDirectory.open(taxoDir.toFile());
final IndexWriterConfig idxWriterConfig = new IndexWriterConfig(LUCENE_VERSION_IN_USE, defaultAnalyzer);
idxWriterConfig.setRAMBufferSizeMB(bufferSize);
cachedWriter = new IndexWriter(directory, idxWriterConfig);
cachedTaxonomyWriter = new DirectoryTaxonomyWriter(taxoDirectory);
searcherManager = new SearcherTaxonomyManager(cachedWriter, true, null, cachedTaxonomyWriter);
readerManager = new ReaderManager(cachedWriter, true);
} catch (IOException e) {
throw new DatabaseConfigurationException("Exception while reading lucene index directory: " + e.getMessage(), e);
} finally {
releaseWriter(writer);
}
}
use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.
the class LuceneConfig method parseConfig.
/**
* Parse a configuration entry. The main configuration entries for this index
* are the <text> elements. They may be enclosed by a <lucene> element.
*
* @param configNodes the configuration
* @param namespaces the namespaces
*
* @throws DatabaseConfigurationException if the configuration can't be parsed
*/
protected void parseConfig(final NodeList configNodes, final Map<String, String> namespaces) throws DatabaseConfigurationException {
Node node;
for (int i = 0; i < configNodes.getLength(); i++) {
node = configNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
try {
final String localName = node.getLocalName();
if (null != localName) {
switch(localName) {
case CONFIG_ROOT:
{
Element elem = (Element) node;
if (elem.hasAttribute(BOOST_ATTRIB)) {
String value = elem.getAttribute(BOOST_ATTRIB);
try {
boost = Float.parseFloat(value);
} catch (NumberFormatException e) {
throw new DatabaseConfigurationException("Invalid value for 'boost' attribute in " + "lucene index config: float expected, got " + value);
}
}
if (elem.hasAttribute(DIACRITICS)) {
String value = elem.getAttribute(DIACRITICS);
if (value.equalsIgnoreCase("no")) {
analyzers.setDefaultAnalyzer(new NoDiacriticsStandardAnalyzer(LuceneIndex.LUCENE_VERSION_IN_USE));
}
}
parseConfig(node.getChildNodes(), namespaces);
break;
}
case ANALYZER_ELEMENT:
analyzers.addAnalyzer((Element) node);
break;
case PARSER_ELEMENT:
queryParser = ((Element) node).getAttribute("class");
break;
case MODULE_ELEMENT:
if (imports == null) {
imports = new ArrayList<>(3);
}
imports.add(new ModuleImport((Element) node));
break;
case FIELD_TYPE_ELEMENT:
FieldType type = new FieldType((Element) node, analyzers);
fieldTypes.put(type.getId(), type);
break;
case INDEX_ELEMENT:
{
// found an index definition
Element elem = (Element) node;
LuceneIndexConfig config = new LuceneIndexConfig(this, elem, namespaces, analyzers, fieldTypes);
// if it is a named index, add it to the namedIndexes map
if (config.getName() != null) {
namedIndexes.put(config.getName(), config);
}
// register index either by QName or path
if (config.getNodePathPattern().hasWildcard()) {
wildcardPaths.add(config);
} else {
LuceneIndexConfig idxConf = paths.get(config.getNodePathPattern().getLastComponent());
if (idxConf == null) {
paths.put(config.getNodePathPattern().getLastComponent(), config);
} else {
idxConf.add(config);
}
}
break;
}
case INLINE_ELEMENT:
{
Element elem = (Element) node;
QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
if (inlineNodes == null) {
inlineNodes = new TreeSet<>();
}
inlineNodes.add(qname);
break;
}
case IGNORE_ELEMENT:
{
Element elem = (Element) node;
QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
if (ignoreNodes == null) {
ignoreNodes = new TreeSet<>();
}
ignoreNodes.add(qname);
break;
}
}
}
} catch (DatabaseConfigurationException e) {
LOG.warn("Invalid lucene configuration element: {}", e.getMessage());
}
}
}
}
use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.
the class AbstractExistHttpServlet method getOrCreateBrokerPool.
private BrokerPool getOrCreateBrokerPool(final ServletConfig config) throws EXistException, DatabaseConfigurationException, ServletException {
// Configure BrokerPool
if (BrokerPool.isConfigured()) {
getLog().info("Database already started. Skipping configuration ...");
} else {
final String confFile = Optional.ofNullable(config.getInitParameter("configuration")).orElse("conf.xml");
final Optional<Path> dbHome = Optional.ofNullable(config.getInitParameter("basedir")).map(baseDir -> Optional.ofNullable(config.getServletContext().getRealPath(baseDir)).map(rp -> Optional.of(Paths.get(rp))).orElse(Optional.ofNullable(config.getServletContext().getRealPath("/")).map(dir -> Paths.get(dir).resolve("WEB-INF").toAbsolutePath()))).orElse(Optional.ofNullable(config.getServletContext().getRealPath("/")).map(Paths::get));
getLog().info("EXistServlet: exist.home={}", dbHome.map(Path::toString).orElse("null"));
final Path cf = dbHome.map(h -> h.resolve(confFile)).orElse(Paths.get(confFile));
getLog().info("Reading configuration from {}", cf.toAbsolutePath().toString());
if (!Files.isReadable(cf)) {
throw new ServletException("Configuration file " + confFile + " not found or not readable");
}
final Configuration configuration = new Configuration(confFile, dbHome);
final String start = config.getInitParameter("start");
if (start != null && "true".equals(start)) {
doDatabaseStartup(configuration);
}
}
return BrokerPool.getInstance();
}
Aggregations