List of usage examples for org.apache.commons.logging Log isDebugEnabled
boolean isDebugEnabled();
From source file:de.ingrid.iplug.csw.dsc.cache.impl.AbstractUpdateStrategy.java
/** * Fetch all records from a id list using the GetRecordById and put them in the cache * /*from w w w . jav a2 s. c om*/ * @param client The CSWClient to use * @param elementSetName The ElementSetName of the records to fetch * @param recordIds The list of ids * @param requestPause The time between two requests in milliseconds * @throws Exception */ protected void fetchRecords(CSWClient client, ElementSetName elementSetName, List<String> recordIds, int requestPause) throws Exception { CSWFactory factory = client.getFactory(); Cache cache = this.getExecutionContext().getCache(); Log log = this.getLog(); CSWQuery query = factory.createQuery(); query.setElementSetName(elementSetName); int cnt = 1; int max = recordIds.size(); Iterator<String> it = recordIds.iterator(); while (it.hasNext()) { String id = it.next(); query.setId(id); CSWRecord record = null; try { record = client.getRecordById(query); if (log.isDebugEnabled()) log.debug("Fetched record: " + id + " " + record.getElementSetName() + " (" + cnt + "/" + max + ")"); cache.putRecord(record); } catch (Exception e) { log.error("Error fetching record '" + query.getId() + "'! Removing record from cache.", e); cache.removeRecord(query.getId()); recordIds.remove(id); } cnt++; Thread.sleep(requestPause); } }
From source file:com.flexive.shared.exceptions.FxApplicationException.java
/** * Log a message at a given level (or error if no level given) * * @param log Log to use//from ww w.java 2 s. c o m * @param message message to LOG * @param level log4j level to apply */ private void logMessage(Log log, String message, LogLevel level) { this.messageLogged = true; if (FxContext.get() != null && FxContext.get().isTestDivision()) return; //dont log exception traces during automated tests final Throwable cause = getCause() != null ? getCause() : this; if (level == null) log.error(message, cause); else { switch (level) { case DEBUG: if (log.isDebugEnabled()) log.debug(message); break; case ERROR: if (log.isErrorEnabled()) log.error(message, cause); break; case FATAL: if (log.isFatalEnabled()) log.fatal(message, cause); break; case INFO: if (log.isInfoEnabled()) log.info(message); break; // case Level.WARN_INT: default: if (log.isWarnEnabled()) log.warn(message); } } }
From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java
public boolean add(PConnector a, PConnector b) { if (DEBUG) {//w w w .j a v a 2s . c o m Log log = getLog(); if (log.isDebugEnabled()) { log.debug("adding connectors a,b=" + a + "," + b); } } if (a == b) { if (DEBUG) { Log log = getLog(); if (log.isDebugEnabled()) { log.debug("connectors are equal: a,b=" + a + "," + b); } } return false; // throw new IllegalArgumentException("Cannot connect connector to itself:"+a); } Node na = nodemap.get(a); Node nb = nodemap.get(b); if ((na == null && (!validTarget(a))) || (nb == null && (!validTarget(b)))) { if (DEBUG) { Log log = getLog(); if (log.isDebugEnabled()) { log.debug("null/valid-target check failed: " + a + "," + b); } } return false; } { PConnector checkout1 = a; PConnector checkout2 = b; Node ra = null; Node rb = null; if (na != null) { ra = na.root(); checkout1 = ra.c; } if (nb != null) { rb = nb.root(); checkout2 = rb.c; } if (ra != null && ra == rb) { // already connected if (DEBUG) { Log log = getLog(); if (log.isDebugEnabled()) { log.debug("already connected a,b=" + a + "," + b); } } return false; } // two outputs ? if (checkout1.isOutput() && checkout2.isOutput()) { if (DEBUG) { Log log = getLog(); if (log.isDebugEnabled()) { log.debug("cannot connect two outputs: a,b=" + a + "," + b); } } return false; } if (checkout2.isOutput()) { Node swapn = nb; nb = na; na = swapn; PConnector swapc = b; b = a; a = swapc; } } // graph(b) contains no output => graph(a) eventually contains an output boolean updateA = false; boolean updateB = false; if (na == null) { na = new Node(a); nodemap.put(a, na); updateA = true; } if (nb == null) { nb = new Node(b); na.addChild(nb); nodemap.put(b, nb); updateB = true; } else { // nb must be root of graph(nb) nb.becomeRoot(); na.addChild(nb); } modCount++; size++; if (updateA) a.verifyConnectedState(); if (updateB) b.verifyConnectedState(); fireConnectionAdded(a, b); fireUpdateTree(nb); // update sub tree return true; }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Releases the repository lock file.//w w w . j a v a 2 s. c om */ protected void releaseRepositoryFileLock(final RepositoryFileLock repositoryFileLock) { Log logger = this.getLog(); if (logger.isDebugEnabled()) logger.debug("Releasing repository file lock."); try { if (repositoryFileLock != null) repositoryFileLock.release(); else if (logger.isDebugEnabled()) logger.debug("Cannot release repository file lock - lock is null."); } catch (Exception e) { logger.error("Error releasing repository file lock!", e); } }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Checks for module updates./*from www .java2 s .c om*/ */ protected void checkForModuleUpdates() { Log logger = this.getLog(); if (logger.isDebugEnabled()) logger.debug("Checking for updated modules in path '" + this.moduleRepositoryDirectory + "'."); synchronized (super.getLock()) { RepositoryFileLock fileLock = null; try { fileLock = this.obtainRepositoryFileLockNoRetries(true); // Obtain lock without retries since this method // will be executed again in the // near future... File[] moduleDirectories = this.moduleRepositoryDirectory.listFiles(); ArrayList activeModuleNames = new ArrayList(Arrays.asList(super.getHotBeanModuleNames())); if (moduleDirectories != null) { String moduleName; for (int i = 0; i < moduleDirectories.length; i++) { if (moduleDirectories[i].isDirectory()) { moduleName = moduleDirectories[i].getName(); if (moduleName != null) { activeModuleNames.remove(moduleName); this.checkModuleDirectory(moduleName, moduleDirectories[i]); } } } } // Check for deleted modules... Iterator deletedModulesIterator = activeModuleNames.iterator(); // HotBeanModule module; HotBeanModuleType moduleType; while (deletedModulesIterator.hasNext()) { moduleType = super.getHotBeanModuleType((String) deletedModulesIterator.next()); if (moduleType != null) moduleType.setRemoveType(true); // Set remove flag of type } } catch (Exception e) { logger.error("Error checking for updated modules - " + e + "!", e); // TODO: Handle/log exception } finally { this.releaseRepositoryFileLock(fileLock); fileLock = null; } } }
From source file:jp.terasoluna.fw.batch.util.BatchUtil.java
/** * ??//from w w w. jav a 2 s . c o m * @param tranMap * @param statMap * @param log */ public static void commitTransactions(Map<?, ?> tranMap, Map<String, TransactionStatus> statMap, Log log) { Set<Entry<String, TransactionStatus>> statSet = statMap.entrySet(); if (statSet.isEmpty()) { return; } Stack<Entry<String, TransactionStatus>> stack = new Stack<Entry<String, TransactionStatus>>(); for (Entry<String, TransactionStatus> stat : statSet) { stack.push(stat); } while (!stack.isEmpty()) { // ??? Entry<String, TransactionStatus> statEntry = stack.pop(); String key = statEntry.getKey(); TransactionStatus trnStat = statEntry.getValue(); if (trnStat == null) { continue; } // ??? Object ptmObj = tranMap.get(key); if (ptmObj == null || !(ptmObj instanceof PlatformTransactionManager)) { continue; } PlatformTransactionManager ptm = (PlatformTransactionManager) ptmObj; if (log != null && log.isDebugEnabled()) { logDebug(log, LogId.DAL025038, trnStat); } // ptm.commit(trnStat); } }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Obtains a file lock on the repository lock file. */// w ww. jav a 2 s .c o m protected RepositoryFileLock obtainRepositoryFileLock(final boolean shared, final int timeout) throws IOException { Log logger = this.getLog(); if (logger.isDebugEnabled()) logger.debug("Obtaining repository file lock (shared: " + shared + ")."); RepositoryFileLock repositoryFileLock = null; FileLock lock = null; final long beginWait = System.currentTimeMillis(); while (repositoryFileLock == null) { try { RandomAccessFile lockFile = new RandomAccessFile( new File(moduleRepositoryDirectory, LOCK_FILE_NAME), "rws"); FileChannel channel = lockFile.getChannel(); // Attempt to obtain a lock on the file lock = channel.tryLock(0L, Long.MAX_VALUE, shared); if (!shared && (lockFile.length() == 0)) { lockFile.write(new String("LOCK").getBytes()); lockFile.getFD().sync(); } repositoryFileLock = new RepositoryFileLock(lockFile, lock); } catch (IOException ioe) { if (logger.isDebugEnabled()) logger.debug("Error obtaining repository file lock (shared: " + shared + ").", ioe); if (timeout < 0) throw ioe; } catch (OverlappingFileLockException ofle) { if (logger.isDebugEnabled()) logger.debug("Error obtaining repository file lock (shared: " + shared + ").", ofle); if (timeout < 0) throw ofle; } if (repositoryFileLock == null) // This statement shouldn't be reaced if timeout is < 0 { if ((System.currentTimeMillis() - beginWait) > timeout) // Wait a maximum of timeout milliseconds on lock { throw new IOException("Timeout while waiting for file lock on repository lock file!"); } else { // Otherwise - wait a while before trying to obtain a lock again try { Thread.sleep(Math.min(250, timeout - (System.currentTimeMillis() - beginWait))); } catch (InterruptedException ie) { } } } } if (logger.isDebugEnabled()) logger.debug("Repository file lock (shared: " + shared + ") obtained."); return repositoryFileLock; }
From source file:it.caladyon.akka.commonslog.CommonsLoggingLogger.java
@Override public void onReceive(Object message) throws Exception { if (message instanceof InitializeLogger) { loggerLog.info(message);// w w w . j a v a 2 s.c o m getSender().tell(Logging.loggerInitialized(), getSelf()); } else if (message instanceof Error) { Log log = LogFactory.getLog(((Error) message).logClass()); if (((Error) message).cause() == null) { log.error(composeMessage((LogEvent) message)); } else { log.error(composeMessage((LogEvent) message), ((Error) message).cause()); } } else if (message instanceof Warning) { Log log = LogFactory.getLog(((Warning) message).logClass()); log.warn(composeMessage((LogEvent) message)); } else if (message instanceof Info) { Log log = LogFactory.getLog(((Info) message).logClass()); if (log.isInfoEnabled()) { log.info(composeMessage((LogEvent) message)); } } else if (message instanceof Debug) { Log log = LogFactory.getLog(((Debug) message).logClass()); if (log.isDebugEnabled()) { log.debug(composeMessage((LogEvent) message)); } } }
From source file:com.healthmarketscience.rmiio.RemoteRetry.java
/** * Implementation of the actual retry logic. Calls the call() method of the * given Caller, returning results. All Throwables will be caught and * shouldRetry() will be queried to see if the call should be reattempted. * Iff shouldRetry() returns <code>true</code>, backoff() is called in order * to allow the other end of the connection to have a breather and then the * call() is reattempted (and the cycle repeats). Otherwise, the original * Throwable is thrown to the caller./*from w w w .ja v a 2 s . c o m*/ * * @param caller * implementation of the actual remote method call */ protected final <RetType> RetType callImpl(Caller<RetType> caller, Log log) throws Throwable { int numTries = 0; do { try { // attempt actual remote call return caller.call(); } catch (Throwable e) { // keep track of number of retries ++numTries; // determine if caller wants to retry if (!shouldRetry(e, numTries)) { // guess not... log.warn("Retry for caller " + caller + " giving up!"); throw e; } if (log.isDebugEnabled()) { log.debug("Caller " + caller + " got exception, retrying", e); } // wait for a bit before retrying backOff(numTries, log); } } while (true); }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Called to handle a Spring application context event. *///from w ww .j a v a2s. c om public void onApplicationEvent(ApplicationEvent applicationEvent) { Log logger = this.getLog(); synchronized (super.getLock()) { if (applicationEvent.getSource() == this.parentApplicationContext) { if (logger.isDebugEnabled()) logger.debug("Parent Spring ApplicationContext initialized."); applicationContextInitialized = true; } } }