org.apache.jmeter.control

## Class CriticalSectionController

- java.lang.Object
- - org.apache.jmeter.testelement.AbstractTestElement
  - - org.apache.jmeter.control.GenericController
    - - org.apache.jmeter.control.CriticalSectionController

All Implemented Interfaces:
  Serializable, Cloneable, Controller, Searchable, TestElement, TestStateListener, ThreadListener, TestCompilerHelper

    public class CriticalSectionController
    extends GenericController
    implements ThreadListener, TestStateListener

This is a Critical Section Controller; it will execute the set of statements (samplers/controllers, etc) under named lock.

In a programming world - this is equivalent of :

     try {
              named_lock.lock();
              statements ....
     } finally {
              named_lock.unlock();
     }

In JMeter you may have :

     Thread-Group (set to loop a number of times or indefinitely,
        ... Samplers ... (e.g. Counter )
        ... Other Controllers ....
        ... CriticalSectionController ( lock name like "foobar" )
           ... statements to perform when lock acquired
           ...
        ... Other Controllers /Samplers }

Since:
  2.12
See Also:
  Serialized Form

### Field Summary

### Fields inherited from class org.apache.jmeter.control.GenericController

`current, subControllersAndSamplers`

### Fields inherited from interface org.apache.jmeter.testelement.TestElement

`COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS`

### Constructor Summary

Constructors
Constructor and Description
`CriticalSectionController()` constructor
`CriticalSectionController(String name)` constructor

### Method Summary

All Methods Instance Methods Concrete Methods
`String` `getLockName()`
`Sampler` `next()` Determines the next sampler to be processed.
`protected void` `reInitialize()` Called after execution of last child of the controller We release lock
`void` `setLockName(String name)` Condition Accessor - this is gonna be any string value
`void` `testEnded()` Called once for all threads after the end of a test.
`void` `testEnded(String host)` Called once for all threads after the end of a test.
`void` `testStarted()` Called just before the start of the test from the main engine thread.
`void` `testStarted(String host)` Called just before the start of the test from the main engine thread.
`void` `threadFinished()` Called for each thread after all samples have been processed.
`void` `threadStarted()` Called for each thread before starting sampling.

### Methods inherited from class org.apache.jmeter.control.GenericController

`addIterationListener, addTestElement, addTestElementOnce, currentReturnedNull, fireIterationStart, fireIterEvents, getCurrentElement, getIterCount, getSubControllers, incrementCurrent, incrementIterCount, initialize, initializeSubControllers, isDone, isFirst, nextIsAController, nextIsASampler, nextIsNull, readResolve, removeCurrentElement, removeIterationListener, resetCurrent, resetIterCount, setCurrentElement, setDone, setFirst, triggerEndOfLoop`

### Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement

`addPropertiesValues, addProperty, addProperty, canRemove, clear, clearTemporary, clearTestElementChildren, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.jmeter.testelement.TestElement

`canRemove, clear, clearTestElementChildren, clone, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removed, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse`

### Constructor Detail

#### CriticalSectionController

    public CriticalSectionController()

constructor

#### CriticalSectionController

    public CriticalSectionController(String name)

constructor

Parameters:
  `name` - The name of this controller

### Method Detail

#### setLockName

    public void setLockName(String name)

Condition Accessor - this is gonna be any string value

Parameters:
  `name` - The name of the lock for this controller

#### getLockName

    public String getLockName()

Returns:
  String lock name

#### next

    public Sampler next()

Description copied from class: `GenericController`

Determines the next sampler to be processed.

If `GenericController.isDone()` is `true`, returns null.

Gets the list element using current pointer. If this is `null`, calls `GenericController.nextIsNull()`.

If the list element is a `Sampler`, calls `GenericController.nextIsASampler(Sampler)`, otherwise calls `GenericController.nextIsAController(Controller)`

If any of the called methods throws `NextIsNullException`, returns `null`, otherwise the value obtained above is returned.

Specified by:
  `next` in interface `Controller`
Overrides:
  `next` in class `GenericController`
Returns:
  the next sampler or `null`
See Also:
  `Controller.next()`

#### reInitialize

    protected void reInitialize()

Called after execution of last child of the controller We release lock

Overrides:
  `reInitialize` in class `GenericController`
See Also:
  `GenericController.reInitialize()`

#### threadStarted

    public void threadStarted()

Description copied from interface: `ThreadListener`
Called for each thread before starting sampling. WARNING: this is called before any Config test elements are processed, so any properties they define will not have been merged in yet. See org.apache.jmeter.threads.JMeterThread#threadStarted()

Specified by:
  `threadStarted` in interface `ThreadListener`

#### threadFinished

    public void threadFinished()

Description copied from interface: `ThreadListener`
Called for each thread after all samples have been processed. See org.apache.jmeter.threads.JMeterThread#threadFinished(org.apache.jmeter.engine.event.LoopIterationListener)

Specified by:
  `threadFinished` in interface `ThreadListener`

#### testStarted

    public void testStarted()

Description copied from interface: `TestStateListener`

Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

N.B. testStarted() and testEnded() are called from different threads.

Specified by:
  `testStarted` in interface `TestStateListener`
See Also:
  `StandardJMeterEngine.run()`

#### testStarted

    public void testStarted(String host)

Description copied from interface: `TestStateListener`

Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

N.B. testStarted() and testEnded() are called from different threads.

Specified by:
  `testStarted` in interface `TestStateListener`
Parameters:
  `host` - name of host
See Also:
  `StandardJMeterEngine.run()`

#### testEnded

    public void testEnded()

Description copied from interface: `TestStateListener`

Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

N.B. testStarted() and testEnded() are called from different threads.

Specified by:
  `testEnded` in interface `TestStateListener`
See Also:
  `StandardJMeterEngine.stopTest()`

#### testEnded

    public void testEnded(String host)

Description copied from interface: `TestStateListener`

Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

N.B. testStarted() and testEnded() are called from different threads.

Specified by:
  `testEnded` in interface `TestStateListener`
Parameters:
  `host` - name of host
See Also:
  `StandardJMeterEngine.stopTest()`