JADE v6.1

com.dautelle.realtime
Class LocalContext

java.lang.Object
  extended bycom.dautelle.realtime.Context
      extended bycom.dautelle.realtime.LocalContext

public final class LocalContext
extends Context

This class represents a local context; it is used to define locally scoped environment settings.

These settings are inherited by concurrent executions when performed within the scope of the local context. For example:

     LocalContext.enter(); // Enters local context scope.
     try {
         MY_VAR.setValue(myValue);
         ConcurrentContext.enter();
         try {
             // Concurrent executions inherit local setting of MY_VAR
             ConcurrentContext.execute(...);
             ConcurrentContext.execute(...); 
         } finally {
             ConcurrentContext.exit();
         }
     } finally {
         LocalContext.exit(); // End of local context scope.
     }
     static final LocalContext.Variable MY_VAR = new LocalContext.Variable();
     

Settings outside of a LocalContext scope, affects all threads (global default value). For example:

     public static final LocalContext.Variable DEBUG = new LocalContext.Variable();
     public static void main(String[] args) {
          DEBUG.setValue(new Boolean(true)); // Affects all threads.
          ...
     }

Locally scoped settings are typically wrapped by a static method. For example:

        LargeInteger.setModulus(m); // Performs integer operations modulo m.
        Length.showAs(NonSI.INCH); // Shows length in inches.
        RelativisticModel.select(); // Uses relativistic physical model.
        QuantityFormat.setInstance(format); // Changes current format.

Version:
6.0, May 02, 2004
Author:
Jean-Marie Dautelle

Nested Class Summary
static class LocalContext.Variable
           This class represents a LocalContext variable.
 
Method Summary
static void enter()
          Enters a LocalContext.
static void exit()
          Exits the current LocalContext.
 
Methods inherited from class com.dautelle.realtime.Context
current, getInner, getOuter, getOwner, pop, push, push
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

enter

public static void enter()
Enters a LocalContext.


exit

public static void exit()
Exits the current LocalContext.

Throws:
java.lang.ClassCastException - if the current context is not a LocalContext.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.