org.apache.tapestry5.ioc.services

## Interface PerthreadManager

- All Known Implementing Classes:
    PerthreadManagerImpl

      public interface PerthreadManager

  Manages per-thread data, and provides a way for listeners to know when such data should be cleaned up. Typically, data is cleaned up at the end of the request (in a web application). Tapestry IoC has any number of objects that need to know when this event occurs, so that they can clean up any per-thread/per-request state.

  Due to TAPESTRY-2141 (and the underlying JDK 1.5 bug 5025230), this service has expanded to manage per-thread data (not just end-of-request listeners).

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addThreadCleanupCallback(Runnable callback)` Adds a callback to be invoked when `cleanup()` is invoked; callbacks are then removed.
    `void` | `addThreadCleanupListener(ThreadCleanupListener listener)` Deprecated. Deprecated in 5.4, use `addThreadCleanupCallback(Runnable)` instead.
    `void` | `cleanup()` Immediately performs a cleanup of the thread, invoking all callback, then discarding all per-thread data stored by the manager (including the list of callbacks).
    `<T> PerThreadValue<T>` | `createValue()` Creates a value using a unique internal key.
    `<T> ObjectCreator<T>` | `createValue(ObjectCreator<T> delegate)` Return `ObjectCreator`, which for each thread, the first call will use the delegate `ObjectCreator` to create an instance, and later calls will reuse the same per-thread instance.
    `<T> T` | `invoke(Invokable<T> invokable)` Returns the result from the invocation, providing a try...finally to cleanup after.
    `void` | `run(Runnable runnable)` Invokes `Runnable.run()`, providing a try...finally to cleanup after.

- - ### Method Detail

    - #### addThreadCleanupListener

          void addThreadCleanupListener(ThreadCleanupListener listener)

      Deprecated. Deprecated in 5.4, use `addThreadCleanupCallback(Runnable)` instead.
      Adds a listener to the hub. All listeners are discarded at the `cleanup()`.
      Parameters:
        `listener` - to add

    - #### addThreadCleanupCallback

          void addThreadCleanupCallback(Runnable callback)

      Adds a callback to be invoked when `cleanup()` is invoked; callbacks are then removed.
      Parameters:
        `callback` -
      Since:
        5.4

    - #### cleanup

          void cleanup()

      Immediately performs a cleanup of the thread, invoking all callback, then discarding all per-thread data stored by the manager (including the list of callbacks).

    - #### createValue

          <T> PerThreadValue<T> createValue()

      Creates a value using a unique internal key.
      Since:
        5.2.0

    - #### createValue

          <T> ObjectCreator<T> createValue(ObjectCreator<T> delegate)

      Return `ObjectCreator`, which for each thread, the first call will use the delegate `ObjectCreator` to create an instance, and later calls will reuse the same per-thread instance. The instance is stored in the `PerthreadManager` and will be released at the end of the request.
      Since:
        5.4

    - #### run

          void run(Runnable runnable)

      Invokes `Runnable.run()`, providing a try...finally to cleanup after.
      Since:
        5.2.0

    - #### invoke

          <T> T invoke(Invokable<T> invokable)

      Returns the result from the invocation, providing a try...finally to cleanup after.

${project.version} - Copyright © 2003-2014 The Apache Software Foundation.