Example usage for org.apache.commons.logging Log debug

List of usage examples for org.apache.commons.logging Log debug

Introduction

In this page you can find the example usage for org.apache.commons.logging Log debug.

Prototype

void debug(Object message);

Source Link

Document

Logs a message with debug log level.

Usage

From source file:com.boylesoftware.web.AbstractWebApplication.java

/**
 * Clean-up the application object.//from   w  w w  . ja  va2  s  . co  m
 */
private void cleanup() {

    // get the log
    final Log log = LogFactory.getLog(AbstractWebApplication.class);
    log.debug("destroying the web-application");

    // shutdown the executors
    if (this.executors != null) {
        log.debug("shutting down the request processing executors...");
        this.executors.shutdown();
        try {
            boolean success = true;
            if (!this.executors.awaitTermination(30, TimeUnit.SECONDS)) {
                log.warn("could not shutdown the request processing"
                        + " executors in 30 seconds, trying to force" + " shutdown...");
                this.executors.shutdownNow();
                if (!this.executors.awaitTermination(30, TimeUnit.SECONDS)) {
                    log.error("could not shutdown the request processing" + " executors");
                    success = false;
                }
            }
            if (success)
                log.debug("request processing executors shut down");
        } catch (final InterruptedException e) {
            log.warn("waiting for the request processing executors to" + " shutdown was interrupted");
            this.executors.shutdownNow();
            Thread.currentThread().interrupt();
        } finally {
            this.executors = null;
        }
    }

    // destroy custom application
    log.debug("destroying custom application");
    try {
        this.destroy();
    } catch (final Exception e) {
        log.error("error destroying custom application", e);
    }

    // forget the router configuration
    this.routerConfiguration = null;

    // close and forget the entity manager factory
    final EntityManagerFactory emf = this.services.getEntityManagerFactory();
    if (emf != null) {
        this.services.setEntityManagerFactory(null);
        try {
            log.debug("closing persistence manager factory");
            emf.close();
        } catch (final Exception e) {
            log.error("error shutting down the application", e);
        }
    }

    // forget user locale finder
    this.services.setUserLocaleFinder(null);

    // close and forget the validator factory
    final ValidatorFactory vf = this.services.getValidatorFactory();
    if (vf != null) {
        this.services.setValidatorFactory(null);
        try {
            log.debug("closing validator factory");
            vf.close();
        } catch (final Exception e) {
            log.error("error shutting down the application", e);
        }
    }

    // forget the authentication service
    this.services.setAuthenticationService(null);
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Releases the repository lock file./*from  w  ww.  ja  va2 s.c o m*/
 */
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:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java

public boolean add(PConnector a, PConnector b) {
    if (DEBUG) {//from  w ww.ja  v  a  2  s  . 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

/**
 * Checks for module updates./*from  www  .j  a va  2 s. co  m*/
 */
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:com.npower.dm.processor.BaseProcessor.java

protected void dump(Log log, ManagementOperation[] operations) {
    for (int i = 0; operations != null && i < operations.length; i++) {
        log.debug(operations[i]);
    }//from w  w w  .  j  a v  a  2  s.c om
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Obtains a file lock on the repository lock file.
 *///  w w w  . j  a v  a 2  s. co 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);//from w w  w  .  jav a2 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.teletalk.jserver.util.aop.MethodInvocationDebugLogger.java

/**
 *//*  w ww . java 2 s .co m*/
public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
    Method method = methodInvocation.getMethod();
    String paramLogString = null;
    long executionStartTime = System.currentTimeMillis();
    Log logger = this.logger;
    String methodName;
    if (logger == null) {
        logger = LogFactory.getLog(method.getDeclaringClass());
        methodName = method.getName();
    } else
        methodName = method.getDeclaringClass().getName() + "." + method.getName();

    if (logger.isDebugEnabled()) {
        paramLogString = "";
        Object[] arguments = methodInvocation.getArguments();
        if (arguments != null) {
            for (int i = 0; i < arguments.length; i++) {
                paramLogString += StringUtils.limitStringLength(StringUtils.toString(arguments[i]),
                        this.maxParameterStringRepresentationLength);
                if (i < (arguments.length - 1))
                    paramLogString += ", ";
            }
        }

        logger.debug("Executing " + methodName + "(" + paramLogString + ").");
    }

    Object returnValue = methodInvocation.proceed();

    if (logger.isDebugEnabled()) {
        if ((method.getReturnType() == null) || method.getReturnType().equals(Void.TYPE)) {
            logger.debug("Done executing " + methodName + "(" + paramLogString + ") after "
                    + (System.currentTimeMillis() - executionStartTime) + "ms.");
        } else {
            logger.debug("Done executing " + methodName + "(" + paramLogString + ") after "
                    + (System.currentTimeMillis() - executionStartTime) + "ms" + " - return value: "
                    + StringUtils.limitStringLength(StringUtils.toString(returnValue),
                            this.maxReturnValueStringRepresentationLength)
                    + ".");
        }
    }

    return returnValue;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Called to handle a Spring application context event.
 *///from  ww w. j a v a  2s.  com
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;
        }
    }
}

From source file:com.curl.orb.servlet.DestroyInstanceServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    super.doPost(request, response);
    Log log = LogFactory.getLog(getClass());
    DestroyInstanceRequest destroyInstanceRequest = (DestroyInstanceRequest) InstanceManagementUtil
            .getRequest(request);/*  w  w w. ja  v a  2 s  . c  o  m*/
    try {
        HttpSession session = request.getSession(false);
        if (session == null)
            throw new InstanceManagementException("Does not exist HttpSession.");
        String objectId = destroyInstanceRequest.getObjectId();
        Object obj = session.getAttribute(objectId);
        // security
        RemoteServiceAnnotationChecker.check(obj.getClass(), environment);
        // remove the object from session
        session.removeAttribute(objectId);

        // kill session
        if (destroyInstanceRequest.getHeader() != null
                && destroyInstanceRequest.getHeader().containsKey(KILL_SESSION)
                && (Boolean) destroyInstanceRequest.getHeader().get(KILL_SESSION)) {
            log.debug("Killed HttpSession:" + session.getId());
            session.invalidate();
        }
        InstanceManagementUtil.setResponse(request, null, null);
        log.debug("Request destroyed");
    }
    // IOException, SerializerException, InstanceManagementException
    catch (Exception e) {
        InstanceManagementUtil.setResponse(request, e, null);
    }
}