javolution.context
Class LocalContext

Object
  extended by Context
      extended by LocalContext
All Implemented Interfaces:
Serializable, XMLSerializable

public class LocalContext
extends Context

This class represents a context to define locally scoped environment settings. This settings are held by LocalContext.Reference and typically wrapped within a static method:

     LocalContext.enter();
     try {
         ModuloInteger.setModulus(m); // Performs integer operations modulo m.
         Length.showAs(NonSI.INCH); // Shows length in inches.
         RelativisticModel.select(); // Uses relativistic physical model.
         ... // Operations performed using local settings.
     } finally {
         LocalContext.exit(); // Reverts to previous settings.
     }

Calls to locally scoped methods should be performed either at start-up (global setting) or within a local context (to avoid impacting other threads).

As for any context, local context settings are inherited during concurrent executions.

Version:
3.6, September 24, 2005
Author:
Jean-Marie Dautelle
See Also:
LocalMap, Serialized Form

Nested Class Summary
static class LocalContext.Reference<T>
           This class represents a reference whose setting is local to the current LocalContext.
 
Field Summary
 
Fields inherited from class Context
ROOT
 
Constructor Summary
LocalContext()
          Default constructor.
 
Method Summary
static void enter()
          Enters a LocalContext possibly recycled.
protected  void enterAction()
          The action to be performed after this context becomes the current context.
static void exit()
          Exits the current local context.
protected  void exitAction()
          The action to be performed before this context is no more the current context.
 
Methods inherited from class Context
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalContext

public LocalContext()
Default constructor.

Method Detail

enter

public static void enter()
Enters a LocalContext possibly recycled.


exit

public static void exit()
Exits the current local context.

Throws:
ClassCastException - if the context is not a local context.

enterAction

protected void enterAction()
Description copied from class: Context
The action to be performed after this context becomes the current context.

Specified by:
enterAction in class Context

exitAction

protected void exitAction()
Description copied from class: Context
The action to be performed before this context is no more the current context.

Specified by:
exitAction in class Context


Copyright © 2005-2012 Javolution. All Rights Reserved.