List of usage examples for org.apache.commons.logging Log debug
void debug(Object message);
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Save.//from w w w. j a v a 2s .co m * * @throws DataDictionaryException * the data dictionary exception */ private static void save() throws DataDictionaryException { final Log log = LogFactory.getLog(DataDictionaryController.class); // resolve datadictionary name File workspaceFolder; try { workspaceFolder = WorkspaceHelper.createWorkingDir(BUNDLE); } catch (final IOException e) { throw new DataDictionaryException(e); } // save datadictionary try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new File(workspaceFolder, CONFIG_NAME)); } catch (final DDException e) { log.error("unable to save data dictionary", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug( "invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("unable to update data dictionary"); } catch (final XMLUtilsException e) { log.error("Unable to stream DataDictionary!", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug( "invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("Unable to stream DataDictionary!"); } }
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Sets the index configuration./*from www. jav a 2s.c o m*/ * * @param indexName * the index name * @param dConfiguration * the d configuration * * @throws DataDictionaryException * the data dictionary exception */ public static void setIndexConfiguration(final String indexName, final DConfiguration dConfiguration) throws DataDictionaryException { final Log log = LogFactory.getLog(DataDictionaryController.class); synchronized (mutex) { ensureLoaded(); if (!hasIndex(indexName)) { throw new DataDictionaryException("index does not exist in data dictionary [" + indexName + "]"); } // check validity of configuration final DIndex dIndex = dd.getIndex(indexName); final DIndexStructure dIS = dIndex.getIndexStructure(); validateConfiguration(dConfiguration, dIS); dIndex.setConfiguration(dConfiguration); // validate data dictionary try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream()); } catch (final DDException e) { log.error("unable to save data dictionary", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug("invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("invalid data dictionary"); } catch (final XMLUtilsException e) { log.error("Unable to stream DataDictionary!", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug("invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("invalid data dictionary while streaming"); } save(); } }
From source file:org.eclipse.smila.search.index.IndexConnection.java
/** * This method applies a given FieldConfig to a field. * /*from ww w . java2 s. c o m*/ * @param field * Search field. * @param nc * Named config. * @param defaultfc * Default config. */ private void applyFieldConfig(final DField field, final DFieldConfig nc, final DFieldConfig defaultfc) { final Log log = LogFactory.getLog(getClass()); StringBuffer sb = new StringBuffer("Processing parameters for search field [" + field.getFieldNo() + "]: "); if (nc == null) { sb = sb.append("[no named config] "); } if (field.getConstraint() == null) { if (nc == null || nc.getConstraint() == null) { field.setConstraint(defaultfc.getConstraint()); sb = sb.append("DC:"); } else { field.setConstraint(nc.getConstraint()); sb = sb.append("NC:"); } } sb = sb.append("Constraint=" + field.getConstraint() + " "); if (field.getFieldTemplate() == null) { if (nc == null || nc.getFieldTemplate() == null) { field.setFieldTemplate(defaultfc.getFieldTemplate()); sb = sb.append("DC:"); } else { field.setFieldTemplate(nc.getFieldTemplate()); sb = sb.append("NC:"); } } sb = sb.append("FieldTemplate=" + field.getFieldTemplate() + " "); if (field.getNodeTransformer() == null) { if (nc == null || nc.getNodeTransformer() == null) { field.setNodeTransformer(defaultfc.getNodeTransformer()); sb = sb.append("DC:"); } else { field.setNodeTransformer(nc.getNodeTransformer()); sb = sb.append("NC:"); } } sb = sb.append("NodeTransformer=" + (field.getNodeTransformer() == null ? "" : field.getNodeTransformer().getName()) + " "); if (field.getWeight() == null) { if (nc == null || nc.getWeight() == null) { field.setWeight(defaultfc.getWeight()); sb = sb.append("DC:"); } else { field.setWeight(nc.getWeight()); sb = sb.append("NC:"); } } sb = sb.append("Weight=" + field.getWeight() + " "); // include technologie dependant parameter assignation if (field instanceof org.eclipse.smila.search.utils.search.DTextField) { final org.eclipse.smila.search.utils.search.DTextField tf = (org.eclipse.smila.search.utils.search.DTextField) field; // assign named config parameters if (nc != null) { final ITFParameter tfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DTextField) nc) .getParameter(); insertTextParameter(tf, tfp, "NC", sb); } // assign default config parameters final ITFParameter tfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DTextField) defaultfc) .getParameter(); insertTextParameter(tf, tfp, "DC", sb); if (tf.getParameter() != null) { tf.setParameter((ITFParameter) tf.getParameter().clone()); } } else if (field instanceof org.eclipse.smila.search.utils.search.DNumberField) { final org.eclipse.smila.search.utils.search.DNumberField nf = (org.eclipse.smila.search.utils.search.DNumberField) field; // assign named config parameters if (nc != null) { final INFParameter nfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DNumberField) nc) .getParameter(); insertNumberParameter(nf, nfp, "NC", sb); } // assign default config parameters final INFParameter nfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DNumberField) defaultfc) .getParameter(); insertNumberParameter(nf, nfp, "DC", sb); if (nf.getParameter() != null) { nf.setParameter((INFParameter) nf.getParameter().clone()); } } else if (field instanceof org.eclipse.smila.search.utils.search.DDateField) { final org.eclipse.smila.search.utils.search.DDateField df = (org.eclipse.smila.search.utils.search.DDateField) field; // assign named config parameters if (nc != null) { final IDFParameter dfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DDateField) nc) .getParameter(); insertDateParameter(df, dfp, "NC", sb); } // assign default config parameters final IDFParameter dfp = ((org.eclipse.smila.search.datadictionary.messages.ddconfig.DDateField) defaultfc) .getParameter(); insertDateParameter(df, dfp, "DC", sb); if (df.getParameter() != null) { df.setParameter((IDFParameter) df.getParameter().clone()); } } if (log.isDebugEnabled()) { log.debug(sb.toString()); } }
From source file:org.eclipse.smila.search.index.IndexManager.java
/** * Returns the instance of a requested IndexConnection by the IndexName. This method implements a pooling mechanism * for these Object ensuring that: - onyl one IndexConnection is used at a time - there no more than the max. # of * IndexConections per Index alive.// w w w .j a v a 2 s .c om * * @param indexName * Index name. * * @return Index connection. * * @throws IndexException * Unable to get instance of index connection. */ public static IndexConnection getInstance(final String indexName) throws IndexException { final Log log = LogFactory.getLog(IndexManager.class); if (s_cleaner != null) { ; // remove compiler warning for cleaning thread. } IndexConnection indexConnection = null; DIndex dIndex = null; try { dIndex = DataDictionaryController.getIndex(indexName); } catch (final DataDictionaryException e) { throw new IndexException(e.getMessage()); } if (dIndex == null) { throw new IndexException("index not in data dictionary [" + indexName + "]"); } final DConnection dConnection = dIndex.getConnection(); IndexConnectionUsage indexConUsage = null; IndexUsage iu = null; while (indexConnection == null) { iu = getIndexUsage(indexName); synchronized (iu) { // check if iu in SINGLE_USAGE if (iu._usage != Usage.Multi) { throw new IndexSingleUseException("index is not in multi use mode [" + indexName + "]"); } // try to find iu that is not at work final Iterator<IndexConnectionUsage> it = iu._indexConnectionUsages.iterator(); while (it.hasNext()) { indexConUsage = it.next(); if (!indexConUsage._atWork) { indexConnection = indexConUsage._indexConnection; indexConUsage._atWork = true; break; } } // no available iu exist, create new if not exceeds max if (indexConnection == null) { if (dConnection.getMaxConnections() > iu._indexConnectionUsages.size()) { indexConUsage = new IndexConnectionUsage(); indexConUsage._atWork = true; indexConUsage._idleSince = System.currentTimeMillis(); final Plugin plugin = PluginFactory.getPlugin(); indexConUsage._indexConnection = plugin.getIndexAccess().getIndexConnection(indexName); indexConnection = indexConUsage._indexConnection; iu._indexConnectionUsages.add(indexConUsage); } } } // sync iu if (indexConnection == null) { try { Thread.sleep(5); } catch (final Exception e) { log.error("SLEEP!", e); } } } if (log.isDebugEnabled()) { log.debug("get index [" + indexConnection + "]"); } return indexConnection; }
From source file:org.eclipse.smila.search.index.IndexManager.java
/** * Release index connection.//from w w w . j a va 2s . c o m * * @param indexConnection * Index connection to release. * @param destroy * Whether to destroy the index connection. */ public static void releaseInstance(final IndexConnection indexConnection, final boolean destroy) { final Log log = LogFactory.getLog(IndexManager.class); IndexConnectionUsage indexConUsage = null; final IndexUsage iu = getIndexUsage(indexConnection.getName()); synchronized (iu) { final Iterator<IndexConnectionUsage> it = iu._indexConnectionUsages.iterator(); while (it.hasNext()) { indexConUsage = it.next(); if (indexConUsage._indexConnection == indexConnection) { indexConUsage._idleSince = System.currentTimeMillis(); indexConUsage._atWork = false; if (log.isDebugEnabled()) { log.debug("index released [" + indexConnection + "]"); } if (destroy) { it.remove(); indexConUsage._indexConnection.close(); if ((iu._indexConnectionUsages.size() == 0) && (iu._usage != Usage.None)) { s_indexUsages.remove(indexConnection.getName()); } indexConUsage._indexConnection = null; indexConUsage = null; if (log.isDebugEnabled()) { log.debug("index destroyed [" + indexConnection + "]"); } } break; } } iu._idleSince = System.currentTimeMillis(); } // sync iu }
From source file:org.eclipse.smila.utils.scriptexecution.LogHelper.java
/** * Logs message with specified level.//from w ww. j a v a2 s .co m * * @param log * log * @param message * message * @param logLevel * log level */ private static void log(final Log log, final String message, final LogLevel logLevel) { if (LogLevel.DEBUG.equals(logLevel)) { log.debug(message); } else if (LogLevel.INFO.equals(logLevel)) { log.info(message); } else if (LogLevel.WARN.equals(logLevel)) { log.warn(message); } else if (LogLevel.ERROR.equals(logLevel)) { log.error(message); } else { throw new IllegalArgumentException("Unknown log level [" + logLevel + "]"); } }
From source file:org.eclipse.smila.utils.scriptexecution.ScriptExecutorFactory.java
/** * Returns script executor according to current platform. * //from ww w .j ava 2 s . c o m * @return script executor */ public static ScriptExecutor getScriptExecutor() { final Log log = LogFactory.getLog(ScriptExecutorFactory.class); final String platform = Platform.getOS(); if (log.isDebugEnabled()) { log.debug("Getting script executor for " + platform); } if (Platform.OS_WIN32.equals(platform)) { return new WindowsScriptExecutor(); } else if (Platform.OS_LINUX.equals(platform) || Platform.OS_SOLARIS.equals(platform)) { return new UnixScriptExecutor(); } else { throw new IllegalStateException("Valid script executor is missing for [" + platform + "] platform."); } }
From source file:org.elasticsearch.client.RequestLogger.java
/** * Logs a request that yielded a response *//* ww w.ja va2s . co m*/ static void logResponse(Log logger, HttpUriRequest request, HttpHost host, HttpResponse httpResponse) { if (logger.isDebugEnabled()) { logger.debug("request [" + request.getMethod() + " " + host + getUri(request.getRequestLine()) + "] returned [" + httpResponse.getStatusLine() + "]"); } if (logger.isWarnEnabled()) { Header[] warnings = httpResponse.getHeaders("Warning"); if (warnings != null && warnings.length > 0) { logger.warn(buildWarningMessage(request, host, warnings)); } } if (tracer.isTraceEnabled()) { String requestLine; try { requestLine = buildTraceRequest(request, host); } catch (IOException e) { requestLine = ""; tracer.trace("error while reading request for trace purposes", e); } String responseLine; try { responseLine = buildTraceResponse(httpResponse); } catch (IOException e) { responseLine = ""; tracer.trace("error while reading response for trace purposes", e); } tracer.trace(requestLine + '\n' + responseLine); } }
From source file:org.elasticsearch.hadoop.rest.InitializationUtils.java
public static boolean discoverNodesIfNeeded(Settings settings, Log log) { if (settings.getNodesDiscovery()) { RestClient bootstrap = new RestClient(settings); try {/*from ww w . ja va 2s.c o m*/ List<String> discoveredNodes = bootstrap.discoverNodes(); if (log.isDebugEnabled()) { log.debug(String.format("Nodes discovery enabled - found %s", discoveredNodes)); } SettingsUtils.addDiscoveredNodes(settings, discoveredNodes); } finally { bootstrap.close(); } return true; } return false; }
From source file:org.elasticsearch.hadoop.rest.InitializationUtils.java
public static void filterNonClientNodesIfNeeded(Settings settings, Log log) { if (!settings.getNodesClientOnly()) { return;/*from w w w . j av a2 s.c o m*/ } RestClient bootstrap = new RestClient(settings); try { String message = "Client-only routing specified but no client nodes with HTTP-enabled available"; List<String> clientNodes = bootstrap.getHttpClientNodes(); if (clientNodes.isEmpty()) { throw new EsHadoopIllegalArgumentException(message); } if (log.isDebugEnabled()) { log.debug(String.format("Found client nodes %s", clientNodes)); } List<String> ddNodes = SettingsUtils.discoveredOrDeclaredNodes(settings); // remove non-client nodes ddNodes.retainAll(clientNodes); if (log.isDebugEnabled()) { log.debug(String.format("Filtered discovered only nodes %s to client-only %s", SettingsUtils.discoveredOrDeclaredNodes(settings), ddNodes)); } if (ddNodes.isEmpty()) { if (settings.getNodesDiscovery()) { message += String.format( "; looks like the client nodes discovered have been removed; is the cluster in a stable state? %s", clientNodes); } else { message += String.format( "; node discovery is disabled and none of nodes specified fits the criterion %s", SettingsUtils.discoveredOrDeclaredNodes(settings)); } throw new EsHadoopIllegalArgumentException(message); } SettingsUtils.setDiscoveredNodes(settings, ddNodes); } finally { bootstrap.close(); } }