seade       2003/01/13 04:12:17

  Modified:    src/core/org/apache/jmeter/threads ThreadGroup.java
  Log:
  Reformatted code.
  
  Revision  Changes    Path
  1.5       +286 -279  
jakarta-jmeter/src/core/org/apache/jmeter/threads/ThreadGroup.java
  
  Index: ThreadGroup.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/ThreadGroup.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ThreadGroup.java  13 Dec 2002 21:37:28 -0000      1.4
  +++ ThreadGroup.java  13 Jan 2003 12:12:17 -0000      1.5
  @@ -2,7 +2,7 @@
    * ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -52,7 +52,9 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  + 
   package org.apache.jmeter.threads;
  +
   import java.io.Serializable;
   import java.util.Collections;
   import java.util.Iterator;
  @@ -71,284 +73,289 @@
   import org.apache.log.Hierarchy;
   import org.apache.log.Logger;
   
  -/****************************************
  - * Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
  - * Apache Foundation
  +/**
  + * Threadgroup
    *
  - *@author    Michael Stover
  - *@created   $Date$
  - *@version   1.0
  - ***************************************/
  -
  -public class ThreadGroup extends AbstractTestElement implements SampleListener,
  -             Serializable,Controller,PerThreadClonable
  + *@author Michael Stover
  + *@version $Id$
  + */
  +public class ThreadGroup
  +    extends AbstractTestElement
  +    implements SampleListener, Serializable, Controller, PerThreadClonable
   {
  -     transient private static Logger log = 
Hierarchy.getDefaultHierarchy().getLoggerFor(
  -                     "jmeter.elements");
  -     /****************************************
  -      * !ToDo (Field description)
  -      ***************************************/
  -     public final static String NUM_THREADS = "ThreadGroup.num_threads";
  -     /****************************************
  -      * !ToDo (Field description)
  -      ***************************************/
  -     public final static String RAMP_TIME = "ThreadGroup.ramp_time";
  -     /****************************************
  -      * !ToDo (Field description)
  -      ***************************************/
  -     public final static String MAIN_CONTROLLER = "ThreadGroup.main_controller";
  -     private final int DEFAULT_NUM_THREADS = 1;
  -     private final int DEFAULT_RAMP_UP = 0;
  -     private SampleQueue queue = null;
  -     private int threadsStarted = 0;
  -     private LinkedList listeners = new LinkedList();
  -     private LinkedList remoteListeners = new LinkedList();
  -
  -     /****************************************
  -      * !ToDo (Constructor description)
  -      ***************************************/
  -     public ThreadGroup()
  -     {
  -     }
  -
  -     /****************************************
  -      * !ToDo (Method aadescription)
  -      *
  -      *@param numThreads  !ToDo (Parameter description)
  -      ***************************************/
  -     public void setNumThreads(int numThreads)
  -     {
  -             setProperty(NUM_THREADS,new Integer(numThreads));
  -     }
  -
  -     public boolean isDone()
  -     {
  -             return getSamplerController().isDone();
  -     }
  -
  -     public boolean hasNext()
  -     {
  -             return getSamplerController().hasNext();
  -     }
  -
  -     public Sampler next()
  -     {
  -             return getSamplerController().next();
  -     }
  -
  -     /****************************************
  -      * !ToDo (Method aadescription)
  -      *
  -      *@param rampUp  !ToDo (Parameter description)
  -      ***************************************/
  -     public void setRampUp(int rampUp)
  -     {
  -             setProperty(RAMP_TIME,new Integer(rampUp));
  -     }
  -     
  -     public boolean isNextFirst()
  -     {
  -             return getSamplerController().isNextFirst();
  -     }
  -
  -     /****************************************
  -      * !ToDoo (Method description)
  -      *
  -      *@return   !ToDo (Return description)
  -      ***************************************/
  -     public int getRampUp()
  -     {
  -             return getPropertyAsInt(this.RAMP_TIME);
  -     }
  -
  -     /****************************************
  -      * !ToDoo (Method description)
  -      *
  -      *@return   !ToDo (Return description)
  -      ***************************************/
  -     public Controller getSamplerController()
  -     {
  -             return (Controller)getProperty(MAIN_CONTROLLER);
  -     }
  -
  -     /****************************************
  -      * !ToDo (Method description)
  -      *
  -      *@param c  !ToDo (Parameter description)
  -      ***************************************/
  -     public void setSamplerController(LoopController c)
  -     {
  -             c.setContinueForever(false);
  -             setProperty(MAIN_CONTROLLER, c);
  -     }
  -
  -     /****************************************
  -      * !ToDoo (Method description)
  -      *
  -      *@return   !ToDo (Return description)
  -      ***************************************/
  -     public int getNumThreads()
  -     {
  -             return this.getPropertyAsInt(this.NUM_THREADS);
  -     }
  -
  -     /****************************************
  -      * !ToDoo (Method description)
  -      *
  -      *@return   !ToDo (Return description)
  -      ***************************************/
  -     public int getDefaultNumThreads()
  -     {
  -             return this.DEFAULT_NUM_THREADS;
  -     }
  -
  -     /****************************************
  -      * !ToDoo (Method description)
  -      *
  -      *@return   !ToDo (Return description)
  -      ***************************************/
  -     public int getDefaultRampUp()
  -     {
  -             return this.DEFAULT_RAMP_UP;
  -     }
  -
  -
  -     /****************************************
  -      * !ToDo
  -      *
  -      *@param child  !ToDo
  -      ***************************************/
  -     public void addTestElement(TestElement child)
  -     {
  -             getSamplerController().addTestElement(child);
  -     }
  -
  -     /****************************************
  -      * !ToDo (Method description)
  -      *
  -      *@param e  !ToDo (Parameter description)
  -      ***************************************/
  -     public void sampleOccurred(SampleEvent e)
  -     {
  -             if(queue == null)
  -             {
  -                     queue = new SampleQueue();
  -                     Thread thread = new Thread(queue);
  -                     //thread.setPriority(Thread.MAX_PRIORITY);
  -                     thread.start();
  -             }
  -             queue.sampleOccurred(e);
  -     }
  -
  -     /****************************************
  -      * A sample has started.
  -      *
  -      *@param e  !ToDo (Parameter description)
  -      ***************************************/
  -     public void sampleStarted(SampleEvent e)
  -     {
  -     }
  -
  -     /****************************************
  -      * A sample has stopped.
  -      *
  -      *@param e  !ToDo (Parameter description)
  -      ***************************************/
  -     public void sampleStopped(SampleEvent e)
  -     {
  -     }
  -
  -     /****************************************
  -      * Separate thread to deliver all SampleEvents. This ensures that sample
  -      * listeners will get sample events 1 at a time, and can thus ignore thread
  -      * issues.
  -      *
  -      *@author    $Author$
  -      *@created   $Date$
  -      *@version   $Revision$
  -      ***************************************/
  -     private class SampleQueue implements Runnable, Serializable
  -     {
  -             List occurredQ = Collections.synchronizedList(new LinkedList());
  -
  -             /****************************************
  -              * !ToDo (Constructor description)
  -              ***************************************/
  -             public SampleQueue() { }
  -
  -             /****************************************
  -              * !ToDo (Method description)
  -              *
  -              *@param e  !ToDo (Parameter description)
  -              ***************************************/
  -             public synchronized void sampleOccurred(SampleEvent e)
  -             {
  -                     occurredQ.add(e);
  -                     this.notify();
  -             }
  -
  -             /****************************************
  -              * !ToDo (Method description)
  -              ***************************************/
  -             public void run()
  -             {
  -                     SampleEvent event = null;
  -                     while(true)
  -                     {
  -                             try
  -                             {
  -                                     event = (SampleEvent)occurredQ.remove(0);
  -                             }
  -                             catch(Exception ex)
  -                             {
  -                                     waitForSamples();
  -                                     continue;
  -                             }
  -                             try
  -                             {
  -                                     if(event != null)
  -                                     {
  -                                             Iterator iter = listeners.iterator();
  -                                             while(iter.hasNext())
  -                                             {
  -                                                     
((SampleListener)iter.next()).sampleOccurred(event);
  -                                             }
  -                                             iter = remoteListeners.iterator();
  -                                             while(iter.hasNext())
  -                                             {
  -                                                     try
  -                                                     {
  -                                                             
((RemoteSampleListener)iter.next()).sampleOccurred(event);
  -                                                     }
  -                                                     catch(Exception ex)
  -                                                     {
  -                                                             log.error("",ex);
  -                                                     }
  -                                             }
  -                                     }
  -                                     else
  -                                     {
  -                                             waitForSamples();
  -                                     }
  -                             }
  -                             catch(Throwable ex)
  -                             {
  -                                     log.error("",ex);
  -                             }
  -
  -                     }
  -             }
  -
  -             private synchronized void waitForSamples()
  -             {
  -                     try
  -                     {
  -                             this.wait();
  -                     }
  -                     catch(Exception ex)
  -                     {
  -                             log.error("",ex);
  -                     }
  -             }
  -     }
  +    private static Logger log =
  +        Hierarchy.getDefaultHierarchy().getLoggerFor("jmeter.elements");
  +    /****************************************
  +     * !ToDo (Field description)
  +     ***************************************/
  +    public final static String NUM_THREADS = "ThreadGroup.num_threads";
  +    /****************************************
  +     * !ToDo (Field description)
  +     ***************************************/
  +    public final static String RAMP_TIME = "ThreadGroup.ramp_time";
  +    /****************************************
  +     * !ToDo (Field description)
  +     ***************************************/
  +    public final static String MAIN_CONTROLLER = "ThreadGroup.main_controller";
  +    private final int DEFAULT_NUM_THREADS = 1;
  +    private final int DEFAULT_RAMP_UP = 0;
  +    private SampleQueue queue = null;
  +    private int threadsStarted = 0;
  +    private LinkedList listeners = new LinkedList();
  +    private LinkedList remoteListeners = new LinkedList();
  +
  +    /****************************************
  +     * !ToDo (Constructor description)
  +     ***************************************/
  +    public ThreadGroup()
  +    {
  +    }
  +
  +    /****************************************
  +     * !ToDo (Method aadescription)
  +     *
  +     *@param numThreads  !ToDo (Parameter description)
  +     ***************************************/
  +    public void setNumThreads(int numThreads)
  +    {
  +        setProperty(NUM_THREADS, new Integer(numThreads));
  +    }
  +
  +    public boolean isDone()
  +    {
  +        return getSamplerController().isDone();
  +    }
  +
  +    public boolean hasNext()
  +    {
  +        return getSamplerController().hasNext();
  +    }
  +
  +    public Sampler next()
  +    {
  +        return getSamplerController().next();
  +    }
  +
  +    /****************************************
  +     * !ToDo (Method aadescription)
  +     *
  +     *@param rampUp  !ToDo (Parameter description)
  +     ***************************************/
  +    public void setRampUp(int rampUp)
  +    {
  +        setProperty(RAMP_TIME, new Integer(rampUp));
  +    }
  +
  +    public boolean isNextFirst()
  +    {
  +        return getSamplerController().isNextFirst();
  +    }
  +
  +    /****************************************
  +     * !ToDoo (Method description)
  +     *
  +     *@return   !ToDo (Return description)
  +     ***************************************/
  +    public int getRampUp()
  +    {
  +        return getPropertyAsInt(ThreadGroup.RAMP_TIME);
  +    }
  +
  +    /****************************************
  +     * !ToDoo (Method description)
  +     *
  +     *@return   !ToDo (Return description)
  +     ***************************************/
  +    public Controller getSamplerController()
  +    {
  +        return (Controller) getProperty(MAIN_CONTROLLER);
  +    }
  +
  +    /****************************************
  +     * !ToDo (Method description)
  +     *
  +     *@param c  !ToDo (Parameter description)
  +     ***************************************/
  +    public void setSamplerController(LoopController c)
  +    {
  +        c.setContinueForever(false);
  +        setProperty(MAIN_CONTROLLER, c);
  +    }
  +
  +    /****************************************
  +     * !ToDoo (Method description)
  +     *
  +     *@return   !ToDo (Return description)
  +     ***************************************/
  +    public int getNumThreads()
  +    {
  +        return this.getPropertyAsInt(ThreadGroup.NUM_THREADS);
  +    }
  +
  +    /****************************************
  +     * !ToDoo (Method description)
  +     *
  +     *@return   !ToDo (Return description)
  +     ***************************************/
  +    public int getDefaultNumThreads()
  +    {
  +        return this.DEFAULT_NUM_THREADS;
  +    }
  +
  +    /****************************************
  +     * !ToDoo (Method description)
  +     *
  +     *@return   !ToDo (Return description)
  +     ***************************************/
  +    public int getDefaultRampUp()
  +    {
  +        return this.DEFAULT_RAMP_UP;
  +    }
  +
  +    /****************************************
  +     * !ToDo
  +     *
  +     *@param child  !ToDo
  +     ***************************************/
  +    public void addTestElement(TestElement child)
  +    {
  +        getSamplerController().addTestElement(child);
  +    }
  +
  +    /****************************************
  +     * !ToDo (Method description)
  +     *
  +     *@param e  !ToDo (Parameter description)
  +     ***************************************/
  +    public void sampleOccurred(SampleEvent e)
  +    {
  +        if (queue == null)
  +        {
  +            queue = new SampleQueue();
  +            Thread thread = new Thread(queue);
  +            //thread.setPriority(Thread.MAX_PRIORITY);
  +            thread.start();
  +        }
  +        queue.sampleOccurred(e);
  +    }
  +
  +    /****************************************
  +     * A sample has started.
  +     *
  +     *@param e  !ToDo (Parameter description)
  +     ***************************************/
  +    public void sampleStarted(SampleEvent e)
  +    {
  +    }
  +
  +    /****************************************
  +     * A sample has stopped.
  +     *
  +     *@param e  !ToDo (Parameter description)
  +     ***************************************/
  +    public void sampleStopped(SampleEvent e)
  +    {
  +    }
  +
  +    /****************************************
  +     * Separate thread to deliver all SampleEvents. This ensures that sample
  +     * listeners will get sample events 1 at a time, and can thus ignore thread
  +     * issues.
  +     *
  +     *@author    $Author$
  +     *@created   $Date$
  +     *@version   $Revision$
  +     ***************************************/
  +    private class SampleQueue implements Runnable, Serializable
  +    {
  +        List occurredQ = Collections.synchronizedList(new LinkedList());
  +
  +        /****************************************
  +         * !ToDo (Constructor description)
  +         ***************************************/
  +        public SampleQueue()
  +        {
  +        }
  +
  +        /****************************************
  +         * !ToDo (Method description)
  +         *
  +         *@param e  !ToDo (Parameter description)
  +         ***************************************/
  +        public synchronized void sampleOccurred(SampleEvent e)
  +        {
  +            occurredQ.add(e);
  +            this.notify();
  +        }
  +
  +        /****************************************
  +         * !ToDo (Method description)
  +         ***************************************/
  +        public void run()
  +        {
  +            SampleEvent event = null;
  +            while (true)
  +            {
  +                try
  +                {
  +                    event = (SampleEvent) occurredQ.remove(0);
  +                }
  +                catch (Exception ex)
  +                {
  +                    waitForSamples();
  +                    continue;
  +                }
  +                try
  +                {
  +                    if (event != null)
  +                    {
  +                        Iterator iter = listeners.iterator();
  +                        while (iter.hasNext())
  +                        {
  +                            ((SampleListener) iter.next()).sampleOccurred(
  +                                event);
  +                        }
  +                        iter = remoteListeners.iterator();
  +                        while (iter.hasNext())
  +                        {
  +                            try
  +                            {
  +                                (
  +                                    (RemoteSampleListener) iter
  +                                        .next())
  +                                        .sampleOccurred(
  +                                    event);
  +                            }
  +                            catch (Exception ex)
  +                            {
  +                                log.error("", ex);
  +                            }
  +                        }
  +                    }
  +                    else
  +                    {
  +                        waitForSamples();
  +                    }
  +                }
  +                catch (Throwable ex)
  +                {
  +                    log.error("", ex);
  +                }
  +
  +            }
  +        }
  +
  +        private synchronized void waitForSamples()
  +        {
  +            try
  +            {
  +                this.wait();
  +            }
  +            catch (Exception ex)
  +            {
  +                log.error("", ex);
  +            }
  +        }
  +    }
  +    
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to