The attached file shows how logging is done in WS-GRAM.
Martin

> hi,
>
>   I wrote a globus wsrf service in my project. When I tested it, I met
> a logging problem.
>   I used $GLOBUS_LOCATION/log4j.properties as my log4j file, and its
> content:
>
> # Set root category priority to WARN and its only appender to A1.
> log4j.rootCategory=INFO, A1
> # A1 is set to be a ConsoleAppender.
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
> # A1 uses PatternLayout.
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %-5p %c{2}
> [%t,%M:%L] %m%n
> # Display any warnings generated by our code
> log4j.category.org.globus=WARN
> # added by me
> log4j.category.hit.pact.crawler.common.Globals=INFO
> # added by me
> log4j.category.pact.grid=INFO
> # Enable SOAP Message Logging
> # log4j.category.org.globus.wsrf.handlers.MessageLoggingHandler=DEBUG
> # Comment out the line below if you want to log every authorization
> # decision the notification consumer makes.
> log4j.category.org.globus.wsrf.impl.security.authorization.ServiceAuthorizationChain=WARN
>
> I am using GDT and my service code is like:
>
> public class MyService {
>
>      static {
>            System.out.println("this is a test.");
>            Globals.logger.info("hello");
>            <several important initializing operations>
>      }
>
>       @GridMethod public String submit(String input){...};
>
> }
>
> the logging code is in the static block, so it will be called only
> when a client calls the service for the first time.
>
> and this is the implementation of class Globals:
>
> package hit.pact.crawler.common;
> public class Globals {
>       public static final Log logger = LogFactory.getLog(Globals.class);
> }
>
> also I had another implementation of Globals which is like:
>
> package hit.pact.crawler.common;
> public class Globals {
>       public static Logger logger =
> Logger.getLogger(Globals.class.getName());
>       static {
>               org.apache.log4j.PropertyConfigurator.configure(<path of 
> globus's
> log4j.properties>);
>       }
> }
>
> when I use a client to call this service, the first line in the
> service's static block prints out the message and then the whole
> container process suspends in the second line. It must be something
> wrong with the logging method. I have tested the two implementations
> of Globals and it's always the same. The container process does NOT
> stop or terminate or print out any message.
>
> I have tested class Globals in a non web service version of my
> project, and the two implementations works fine.
>
> If the problem remains I will not finish my project in time.Can you
> tell me what's wrong. If you give me a correct sample of how to use
> log4j in globus wsrf service, it will be highly appreciated.
>
> Thanks.
>
>
/*
 * Portions of this file Copyright 1999-2005 University of Chicago
 * Portions of this file Copyright 1999-2005 The University of Southern 
California.
 *
 * This file or a portion of this file is licensed under the
 * terms of the Globus Toolkit Public License, found at
 * http://www.globus.org/toolkit/download/license.html.
 * If you redistribute this file, with or without
 * modifications, you must include this notice in the file.
 */
package org.globus.exec.service.exec;

import java.util.LinkedList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.globus.util.I18n;
import org.globus.wsrf.ResourceKey;
import org.globus.exec.utils.Resources;
import org.globus.exec.service.factory.ManagedJobFactoryHome;
import org.globus.exec.service.factory.FactoryHomeConfiguration;

class RunQueue
{
    /** Log4J logger */
    private static Log logger = LogFactory.getLog(RunQueue.class);
    private static I18n i18n = I18n.getI18n(Resources.class.getName());
    private static RunQueue RUN_QUEUE;
    private static final int MINIMUM_RUN_THREAD_COUNT = 1;
    private static final int DEFAULT_RUN_THREAD_COUNT = 10;
    private LinkedList readyQueue;

    static
    {
        // get the configured number of run queues
        FactoryHomeConfiguration homeConfig
            = ManagedJobFactoryHome.getConfiguration();
        int runThreadCount;

        // read the number of run threads from the container registry
        try
        {
            runThreadCount
                = Integer.parseInt(homeConfig.getRunQueueThreadCount());
        }
        catch (Exception e)
        {
            logger.warn(i18n.getMessage(Resources.BAD_RUN_QUEUE_THREAD_COUNT),
                        e);
            runThreadCount = DEFAULT_RUN_THREAD_COUNT;
        }

        // assert that there isn't a silly setting
        if (runThreadCount < MINIMUM_RUN_THREAD_COUNT)
        {
            logger.warn(i18n.getMessage(Resources.BAD_RUN_QUEUE_THREAD_COUNT));
            runThreadCount = DEFAULT_RUN_THREAD_COUNT;
        }

        // create the single RunQueue object
        RUN_QUEUE = new RunQueue();          

        // create run thread instances
        for (int threadIndex=0; threadIndex<runThreadCount; threadIndex++)
        {
            RunThread runThread = new RunThread(
                "RunQueueThread_" + threadIndex, RUN_QUEUE);
            runThread.setDaemon(true);
            runThread.start();
        }
        logger.debug("created RunQueue with " + runThreadCount + " threads");
    }

    // private constructor: called during initialization in static block
    private RunQueue()
    { 
        this.readyQueue = new LinkedList();
    }

    public synchronized void add(ResourceKey resourceKey)
    {
        if (logger.isTraceEnabled())
        {
            logger.trace("Entering add()");
        }

        this.readyQueue.add(resourceKey);
        notify();

        if (logger.isDebugEnabled())
        {
            logger.debug("adding " + resourceKey.toString() + " to queue.");
            printRunQueueGraph();
        }

        if (logger.isTraceEnabled())
        {
            logger.trace("Leaving add()");
        }
    }

    public synchronized ResourceKey remove()
    {
        ResourceKey resourceKey = (ResourceKey) this.readyQueue.removeFirst();

        if (logger.isDebugEnabled())
        {
            logger.debug("removing " + resourceKey.toString() + " from queue.");
            printRunQueueGraph();
        }

        return resourceKey;
    }

    private synchronized void printRunQueueGraph() 
    {
        int queuedJobCount = this.readyQueue.size();
        StringBuffer asterisks = new StringBuffer();
        for (int index=0; index<queuedJobCount; index++)
        {
            asterisks.append("*");
        }
        logger.debug("\nRunQueue Graph: " + asterisks.toString());
    }

    public synchronized int size()
    {
        return this.readyQueue.size();
    }

    public static RunQueue getInstance()
    {
        return RUN_QUEUE;
    }
}

Reply via email to