Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.context
Class AllocatorContext

    java.lang.Object
      javolution.context.Context
          javolution.context.AllocatorContext

All Implemented Interfaces:
  java.io.Serializable, XMLSerializable

Direct Known Subclasses:
  HeapContext, ImmortalContext, PoolContext, StackContext

    public abstract class AllocatorContext

extends Context

This class represents an allocator context; it defines the the allocation policy of `ObjectFactory` products.

The `default` implementation is an instance of `HeapContext` context.

Specializations may allocate from local stacks (`StackContext`), shared object pools (`StackContext`), specific memory areas (e.g. `ImmortalContext`), aging pools (where objects sufficiently old are recycled), switchable spaces (objects from a particular frame are recycled when buffers are swapped), etc.

Version:
  5.2, August 19, 2007
Author:
  Jean-Marie Dautelle
See Also:
  Serialized Form

Nested Class Summary
`static class` | `AllocatorContext.Reference<T>` This class represents a `reference` allocated from the current `AllocatorContext`.

Field Summary
`static Configurable<java.lang.Class<? extends AllocatorContext>>` | `DEFAULT` Holds the default allocator context shared by all newly created threads (the default is a `HeapContext` instance).

Fields inherited from class javolution.context.Context
`ROOT`

Constructor Summary
`protected` | `AllocatorContext()` Default constructor.

Method Summary
`protected abstract void` | `deactivate()` Deactivates the `allocators` belonging to this context for the current thread.
`protected abstract Allocator` | `getAllocator(ObjectFactory factory)` Returns the allocator for the specified factory in this context.
`static Context` | `getCurrent()` Returns the current allocator context.
`static AllocatorContext` | `getDefault()` Returns the default instance (`DEFAULT` implementation).
`static
`<T extends ValueType> T`
` | `outerCopy(T value)` Performs a copy of the specified value allocated outside of the current allocator context.
`static void` | `outerCopy(ValueType[] values)` Performs a copy of the specified values outside of the current stack context (convenience method).
`static void` | `outerExecute(java.lang.Runnable logic)` Executes the specified logic outside of the current allocator context.

Methods inherited from class javolution.context.Context
`enter, enter, enterAction, exit, exit, exitAction, getOuter, getOwner, setCurrent, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### DEFAULT

    public static final Configurable<java.lang.Class<? extends AllocatorContext>> DEFAULT

  Holds the default allocator context shared by all newly created threads (the default is a `HeapContext` instance). The default allocator context is configurable. For example the following runs the javolution built-in tests with a `PoolContext` as default (javolution built-in tests `loads` their configuration from systems properties)`

         > java -Djavolution.AllocatorContext.Default=javolution.context.PoolContext -jar javolution.jar time

  `

Constructor Detail

### AllocatorContext

    protected AllocatorContext()

  Default constructor.

Method Detail

### getCurrent

    public static Context getCurrent()

  Returns the current allocator context. If the current thread has not entered an allocator context (e.g. new thread) then `getDefault()` is returned.

  Returns:
    the current allocator context.

### getDefault

    public static AllocatorContext getDefault()

  Returns the default instance (`DEFAULT` implementation).

  Returns:
    the default instance.

### getAllocator

    protected abstract Allocator getAllocator(ObjectFactory factory)

  Returns the allocator for the specified factory in this context.

  Parameters:
    `factory` - the factory for which the allocator is returned.
  Returns:
    the allocator producing instances of the specified factory.

### deactivate

    protected abstract void deactivate()

  Deactivates the `allocators` belonging to this context for the current thread. This method is typically called when an inner allocator context is entered by the current thread, when exiting an allocator context or when a concurrent executor has completed its task within this allocator context. Deactivated allocators have no `user` (`null`).

### outerCopy

    public static <T extends ValueType> T outerCopy(T value)

  Performs a copy of the specified value allocated outside of the current allocator context.

  Parameters:
    `value` - the value to be copied.
  Returns:
    a copy allocated using the outer allocator.

### outerCopy

    public static void outerCopy(ValueType[] values)

  Performs a copy of the specified values outside of the current stack context (convenience method). This method is equivalent to:`

        AllocatorContext.outerExecute(new Runnable() {
            public void run() {
               for (int i = 0; i < values.length; i++) {
                   values[i] = {ValueType) values[i].copy();
               }
           }
        });

  `

  Parameters:
    `values` - the array whose elements are exported.

### outerExecute

    public static void outerExecute(java.lang.Runnable logic)

  Executes the specified logic outside of the current allocator context.

  Parameters:
    `logic` - the logic to be executed outside of the current stack context.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2009 Javolution.