J avolution v3.7 (J2SE 1.5+)

javolution.realtime
Class LocalContext

java.lang.Object
  extended by javolution.realtime.Context
      extended by javolution.realtime.LocalContext

public class LocalContext
extends Context

This class represents a local context; it is used to define locally scoped setting through the use of LocalReference typically wrapped within a static method. For example:

     LocalContext.enter();
     try {
         LargeInteger.setModulus(m); // Performs integer operations modulo m.
         Length.showAs(NonSI.INCH); // Shows length in inches.
         RelativisticModel.select(); // Uses relativistic physical model.
         QuantityFormat.getInstance(); // Returns local format for quantities.
         XmlFormat.setFormat(Foo.class, myFormat); // Uses myFormat for instances of Foo.
     } 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).

Finally, local settings are inherited by concurrent threads spawned while in a local context scope.

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

Constructor Summary
LocalContext()
          Default constructor.
 
Method Summary
 void clear()
          Removes all local settings for this context.
static LocalContext current()
          Returns the current local context or null if the current thread does not execute within a local context (global context).
static void enter()
          Enters a LocalContext.
protected  void enterAction()
          The action to be performed after this context becomes the current context.
static void exit()
          Exits the current LocalContext.
protected  void exitAction()
          The action to be performed before this context is no more the current context.
 
Methods inherited from class javolution.realtime.Context
enter, enter, exit, exit, getOuter, getOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalContext

public LocalContext()
Default constructor.

Method Detail

current

public static LocalContext current()
Returns the current local context or null if the current thread does not execute within a local context (global context).

Returns:
the current local context.

enter

public static void enter()
Enters a LocalContext.


exit

public static void exit()
Exits the current LocalContext.

Throws:
java.lang.IllegalStateException - if the current context is not an instance of LocalContext.

clear

public void clear()
Removes all local settings for this context.

Overrides:
clear in class 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

J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.