Javolution 6.0.0 java
javolution.context.internal.LocalContextImpl Class Reference
Inheritance diagram for javolution.context.internal.LocalContextImpl:
[legend]
Collaboration diagram for javolution.context.internal.LocalContextImpl:
[legend]

Public Member Functions

void exit ()
 

Static Public Member Functions

static LocalContext enter ()
 
static< T extends AbstractContext > T enter (Class< T > custom)
 
static AbstractContext current ()
 
static void inherit (AbstractContext ctx)
 

Protected Member Functions

LocalContext inner ()
 
AbstractContext enterInner ()
 
AbstractContext getOuter ()
 

Static Protected Member Functions

static< T extends AbstractContext > T current (Class< T > type)
 

Package Functions

public< T > void supersede (Parameter< T > param, T localValue)
 
protected< T > T getValue (Parameter< T > param, T defaultValue)
 

Private Attributes

FastMap< Parameter<?>, Object > localSettings = new FastMap<Parameter<?>, Object>()
 
LocalContextImpl parent
 
AbstractContext outer
 

Static Private Attributes

static final ThreadLocal< AbstractContextCURRENT = new ThreadLocal<AbstractContext>()
 

Detailed Description

Holds the default implementation of LocalContext.

Definition at line 17 of file LocalContextImpl.java.

Member Function Documentation

◆ current() [1/2]

static AbstractContext javolution.context.AbstractContext.current ( )
staticinherited

Returns the current context for the current thread or

null

if this thread has no context (default).

Definition at line 61 of file AbstractContext.java.

61  {
62  return AbstractContext.CURRENT.get();
63  }

References javolution.context.AbstractContext.CURRENT.

Referenced by javolution.context.LogContext.currentLogContext(), javolution.context.SecurityContext.currentSecurityContext(), javolution.text.TextContext.currentTextContext(), javolution.xml.XMLContext.currentXMLContext(), javolution.context.LocalContext.enter(), javolution.context.ConcurrentContext.enter(), and javolution.context.LocalContext.Parameter< T >.get().

Here is the caller graph for this function:

◆ current() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.current ( Class< T >  type)
staticprotectedinherited

Returns the current context of specified type or

null

if none.

Definition at line 69 of file AbstractContext.java.

69  {
70  AbstractContext ctx = AbstractContext.CURRENT.get();
71  while (ctx != null) {
72  if (type.isInstance(ctx))
73  return (T) ctx;
74  ctx = ctx.outer;
75  }
76  return null;
77  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

◆ enter() [1/2]

static LocalContext javolution.context.LocalContext.enter ( )
staticinherited

Enters and returns a new local context instance.

Definition at line 97 of file LocalContext.java.

97  {
98  LocalContext ctx = current(LocalContext.class);
99  if (ctx == null) { // Root.
100  ctx = OSGiServices.getLocalContext();
101  }
102  return (LocalContext) ctx.enterInner();
103  }

References javolution.context.AbstractContext.current(), javolution.context.AbstractContext.enterInner(), and javolution.osgi.internal.OSGiServices.getLocalContext().

Here is the call graph for this function:

◆ enter() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.enter ( Class< T >  custom)
staticinherited

Enters the scope of a custom context. This method raises a SecurityException if the permission to enter contexts of the specified class is not granted. For example, the following disallow entering any custom context. [code] SecurityContext ctx = SecurityContext.enter(); try { ctx.revoke(new SecurityContext.Permission(AbstractContext.class, "enter")); ... // Cannot enter any custom context. } finally { ctx.exit(); // Back to previous security settings. }[/code]


Parameters
customthe custom context to enter.
Exceptions
IllegalArgumentExceptionif the specified class default constructor cannot be instantiated.
SecurityExceptionif
SecurityContext.Permission(custom, "enter")

is not granted.
See also
SecurityContext.Permission

Definition at line 101 of file AbstractContext.java.

101  {
102  SecurityContext.check(new Permission<T>(custom, "enter"));
103  try {
104  return (T) custom.newInstance().enterInner();
105  } catch (InstantiationException e) {
106  throw new IllegalArgumentException(
107  "Cannot instantiate instance of " + custom, e);
108  } catch (IllegalAccessException e) {
109  throw new IllegalArgumentException("Cannot access " + custom, e);
110  }
111  }

References javolution.context.SecurityContext.check().

Here is the call graph for this function:

◆ enterInner()

AbstractContext javolution.context.AbstractContext.enterInner ( )
protectedinherited

Enters the scope of an inner context which becomes the current context; the previous current context becomes the outer of this context.

Returns
the inner context entered.

Definition at line 141 of file AbstractContext.java.

141  {
143  inner.outer = AbstractContext.CURRENT.get();
144  AbstractContext.CURRENT.set(inner);
145  return inner;
146  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

Referenced by javolution.xml.XMLContext.enter(), javolution.text.TextContext.enter(), javolution.context.LogContext.enter(), javolution.context.LocalContext.enter(), javolution.context.SecurityContext.enter(), and javolution.context.ConcurrentContext.enter().

Here is the caller graph for this function:

◆ exit()

void javolution.context.AbstractContext.exit ( )
inherited

Exits the scope of this context; the outer of this context becomes
the current context.

Exceptions
IllegalStateExceptionif this context is not the current context.

Reimplemented in javolution.context.ConcurrentContext, and javolution.context.internal.ConcurrentContextImpl.

Definition at line 155 of file AbstractContext.java.

155  {
156  if (this != AbstractContext.CURRENT.get())
157  throw new IllegalStateException(
158  "This context is not the current context");
159  AbstractContext.CURRENT.set(outer);
160  outer = null;
161  }

References javolution.context.AbstractContext.CURRENT.

◆ getOuter()

AbstractContext javolution.context.AbstractContext.getOuter ( )
protectedinherited

Returns the outer context of this context or

null

if this context has no outer context.

Definition at line 167 of file AbstractContext.java.

167  {
168  return outer;
169  }

◆ getValue()

protected<T> T javolution.context.internal.LocalContextImpl.getValue ( Parameter< T >  param,
defaultValue 
)
package

Returns the local value of the specified parameter or the specified default value if not superseded.

Parameters
paramthe local parameter whose local value is returned.
defaultValuethe parameter value if not superseded.

Reimplemented from javolution.context.LocalContext.

Definition at line 37 of file LocalContextImpl.java.

37  {
38  Object value = localSettings.get(param);
39  if (value != null) return (T) value;
40  if (parent != null) return parent.getValue(param, defaultValue);
41  return defaultValue;
42  }

References javolution.util.FastMap< K, V >.get(), javolution.context.internal.LocalContextImpl.getValue(), javolution.context.internal.LocalContextImpl.localSettings, and javolution.context.internal.LocalContextImpl.parent.

Referenced by javolution.context.internal.LocalContextImpl.getValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inherit()

static void javolution.context.AbstractContext.inherit ( AbstractContext  ctx)
staticinherited

Inherits the specified context which becomes the context of the current thread. This method is particularly useful when creating new threads to make them inherits from the context stack of the parent thread. [code] //Spawns a new thread inheriting the context of the current thread. MyThread myThread = new MyThread(); myThread.inherited = AbstractContext.current(); myThread.start(); ... class MyThread extends Thread { AbstractContext inherited; public void run() { AbstractContext.inherit(inherited); // Sets current context. ... } }[/code]

Definition at line 131 of file AbstractContext.java.

131  {
132  CURRENT.set(ctx);
133  }

Referenced by javolution.context.internal.ConcurrentThreadImpl.run().

Here is the caller graph for this function:

◆ inner()

LocalContext javolution.context.internal.LocalContextImpl.inner ( )
protected

Returns a new inner instance of this context inheriting the properties of this context. The new instance can be configured independently from its parent.

Reimplemented from javolution.context.AbstractContext.

Definition at line 23 of file LocalContextImpl.java.

23  {
24  LocalContextImpl ctx = new LocalContextImpl();
25  ctx.parent = this;
26  return ctx;
27  }

References javolution.context.internal.LocalContextImpl.parent.

◆ supersede()

public<T> void javolution.context.internal.LocalContextImpl.supersede ( Parameter< T >  param,
localValue 
)
package

Supersedes the value of the specified parameter.

Parameters
paramthe local parameter whose local value is overridden.
localValuethe new local value.
Exceptions
SecurityExceptionif the permission to override the specified parameter is not granted.
NullPointerExceptionif the specified local value is
null
.

Reimplemented from javolution.context.LocalContext.

Definition at line 30 of file LocalContextImpl.java.

30  {
31  if (localValue == null) throw new NullPointerException();
32  localSettings.put(param, localValue);
33  }

References javolution.context.internal.LocalContextImpl.localSettings, and javolution.util.FastMap< K, V >.put().

Here is the call graph for this function:

Member Data Documentation

◆ CURRENT

final ThreadLocal<AbstractContext> javolution.context.AbstractContext.CURRENT = new ThreadLocal<AbstractContext>()
staticprivateinherited

◆ localSettings

FastMap<Parameter<?>, Object> javolution.context.internal.LocalContextImpl.localSettings = new FastMap<Parameter<?>, Object>()
private

◆ outer

AbstractContext javolution.context.AbstractContext.outer
privateinherited

Holds the outer context or

null

if none (top context).

Definition at line 50 of file AbstractContext.java.

Referenced by javolution.context.AbstractContext.current(), and javolution.context.AbstractContext.enterInner().

◆ parent

LocalContextImpl javolution.context.internal.LocalContextImpl.parent
private

The documentation for this class was generated from the following file:
javolution.context.LocalContext.LocalContext
LocalContext()
Definition: LocalContext.java:92
javolution.context.internal.LocalContextImpl.getValue
protected< T > T getValue(Parameter< T > param, T defaultValue)
Definition: LocalContextImpl.java:37
javolution.util.FastMap.put
V put(K key, V value)
Definition: FastMap.java:322
javolution.context.AbstractContext.CURRENT
static final ThreadLocal< AbstractContext > CURRENT
Definition: AbstractContext.java:45
javolution.context.AbstractContext.inner
abstract AbstractContext inner()
javolution.context.AbstractContext.outer
AbstractContext outer
Definition: AbstractContext.java:50
javolution.context.internal.LocalContextImpl.parent
LocalContextImpl parent
Definition: LocalContextImpl.java:20
javolution.context.internal.LocalContextImpl.localSettings
FastMap< Parameter<?>, Object > localSettings
Definition: LocalContextImpl.java:19
javolution.context.AbstractContext.current
static AbstractContext current()
Definition: AbstractContext.java:61
javolution.util.FastMap.get
V get(Object key)
Definition: FastMap.java:315
javolution.context.AbstractContext.AbstractContext
AbstractContext()
Definition: AbstractContext.java:55