Javolution 6.0.0 java
|
Public Member Functions | |
ConcurrentContextImpl () | |
ConcurrentContextImpl (ConcurrentContextImpl parent) | |
synchronized void | completed (Throwable error) |
void | execute (Runnable logic) |
synchronized void | exit () |
int | getConcurrency () |
void | setConcurrency (int concurrency) |
Static Public Member Functions | |
static ConcurrentContext | enter () |
static< T extends AbstractContext > T | enter (Class< T > custom) |
static void | execute (Runnable... logics) |
static AbstractContext | current () |
static void | inherit (AbstractContext ctx) |
Static Public Attributes | |
static final Configurable< Integer > | CONCURRENCY |
Protected Member Functions | |
ConcurrentContext | inner () |
AbstractContext | enterInner () |
AbstractContext | getOuter () |
Static Protected Member Functions | |
static< T extends AbstractContext > T | current (Class< T > type) |
Private Attributes | |
int | completedCount |
Throwable | error |
int | initiatedCount |
final ConcurrentContextImpl | parent |
ConcurrentThreadImpl[] | threads |
AbstractContext | outer |
Static Private Attributes | |
static final ThreadLocal< AbstractContext > | CURRENT = new ThreadLocal<AbstractContext>() |
Holds the default implementation of ConcurrentContext.
Definition at line 17 of file ConcurrentContextImpl.java.
javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl | ( | ) |
Default constructor (root).
Definition at line 29 of file ConcurrentContextImpl.java.
References javolution.context.ConcurrentContext.CONCURRENCY, javolution.lang.Configurable< T >.get(), and javolution.context.internal.ConcurrentContextImpl.threads.
Referenced by javolution.context.internal.ConcurrentContextImpl.inner().
javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl | ( | ConcurrentContextImpl | parent | ) |
Inner implementation.
Definition at line 42 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.parent, and javolution.context.internal.ConcurrentContextImpl.threads.
synchronized void javolution.context.internal.ConcurrentContextImpl.completed | ( | Throwable | error | ) |
Definition at line 48 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.completedCount, and javolution.context.internal.ConcurrentContextImpl.error.
Referenced by javolution.context.internal.ConcurrentThreadImpl.run().
|
staticinherited |
Returns the current context for the current thread or
if this thread has no context (default).
Definition at line 61 of file AbstractContext.java.
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().
|
staticprotectedinherited |
Returns the current context of specified type or
if none.
Definition at line 69 of file AbstractContext.java.
References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.
|
staticinherited |
Enters and returns a new concurrent context instance.
Definition at line 186 of file ConcurrentContext.java.
References javolution.context.AbstractContext.current(), javolution.context.AbstractContext.enterInner(), and javolution.osgi.internal.OSGiServices.getConcurrentContext().
Referenced by javolution.context.ConcurrentContext.execute(), javolution.util.internal.map.ParallelMapImpl< K, V >.perform(), javolution.util.internal.collection.ParallelCollectionImpl< E >.perform(), javolution.util.internal.map.ParallelMapImpl< K, V >.update(), and javolution.util.internal.collection.ParallelCollectionImpl< E >.update().
|
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]
custom | the custom context to enter. |
IllegalArgumentException | if the specified class default constructor cannot be instantiated. |
SecurityException | if SecurityContext.Permission(custom, "enter")
is not granted. |
Definition at line 101 of file AbstractContext.java.
References javolution.context.SecurityContext.check().
|
protectedinherited |
Enters the scope of an inner context which becomes the current context; the previous current context becomes the outer of this context.
Definition at line 141 of file AbstractContext.java.
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().
void javolution.context.internal.ConcurrentContextImpl.execute | ( | Runnable | logic | ) |
Executes the specified logic by a concurrent thread if one available; otherwise the logic is executed by the current thread. Any exception or error occurring during the concurrent execution is propagated to the current thread upon exit of the concurrent context.
logic | the logic to be executed concurrently when possible. |
Reimplemented from javolution.context.ConcurrentContext.
Definition at line 57 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.error, javolution.context.internal.ConcurrentContextImpl.initiatedCount, and javolution.context.internal.ConcurrentContextImpl.threads.
|
staticinherited |
Convenience method to executes the specified logics concurrently. This method is equivalent to: [code] ConcurrentContext ctx = ConcurrentContext.enter(); try { ctx.execute(logics[0]); ctx.execute(logics[1]); ... } finally { ctx.exit(); }[/code]
logics | the logics to execute concurrently if possible. |
Definition at line 209 of file ConcurrentContext.java.
References javolution.context.ConcurrentContext.enter(), javolution.context.ConcurrentContext.execute(), and javolution.context.ConcurrentContext.exit().
Referenced by javolution.context.ConcurrentContext.execute(), javolution.util.internal.map.ParallelMapImpl< K, V >.perform(), javolution.util.internal.collection.ParallelCollectionImpl< E >.perform(), javolution.util.internal.map.ParallelMapImpl< K, V >.update(), and javolution.util.internal.collection.ParallelCollectionImpl< E >.update().
synchronized void javolution.context.internal.ConcurrentContextImpl.exit | ( | ) |
Exits the scope of this concurrent context; this method blocks until all the concurrent executions are completed.
RuntimeException | re-exports any exception raised during concurrent executions. |
Error | re-exports any error raised during concurrent executions. |
IllegalStateException | if this context is not the current context. |
Reimplemented from javolution.context.ConcurrentContext.
Definition at line 74 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.completedCount, javolution.context.internal.ConcurrentContextImpl.error, and javolution.context.internal.ConcurrentContextImpl.initiatedCount.
int javolution.context.internal.ConcurrentContextImpl.getConcurrency | ( | ) |
Returns the current concurrency which is basically the number of concurrent threads authorized to do concurrent work (on top of all others threads of course).
Reimplemented from javolution.context.ConcurrentContext.
Definition at line 93 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.threads.
|
protectedinherited |
Returns the outer context of this context or
if this context has no outer context.
Definition at line 167 of file AbstractContext.java.
|
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.
Referenced by javolution.context.internal.ConcurrentThreadImpl.run().
|
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 109 of file ConcurrentContextImpl.java.
References javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl().
void javolution.context.internal.ConcurrentContextImpl.setConcurrency | ( | int | concurrency | ) |
Sets the maximum concurrency. Setting a value greater than the current concurrency has no effect (concurrency can only be reduced).
Reimplemented from javolution.context.ConcurrentContext.
Definition at line 98 of file ConcurrentContextImpl.java.
References javolution.lang.MathLib.min(), javolution.context.internal.ConcurrentContextImpl.parent, and javolution.context.internal.ConcurrentContextImpl.threads.
|
private |
Definition at line 19 of file ConcurrentContextImpl.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.completed(), and javolution.context.internal.ConcurrentContextImpl.exit().
|
staticinherited |
Holds the maximum concurrency
(default Runtime.getRuntime().availableProcessors() - 1
). The maximum concurrency is configurable. For example, the JVM option
disables concurrency.
Definition at line 160 of file ConcurrentContext.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl().
|
staticprivateinherited |
Holds the last context entered (thread-local).
Definition at line 45 of file AbstractContext.java.
Referenced by javolution.context.AbstractContext.current(), javolution.context.AbstractContext.enterInner(), and javolution.context.AbstractContext.exit().
|
private |
Definition at line 20 of file ConcurrentContextImpl.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.completed(), javolution.context.internal.ConcurrentContextImpl.execute(), and javolution.context.internal.ConcurrentContextImpl.exit().
|
private |
Definition at line 22 of file ConcurrentContextImpl.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.execute(), and javolution.context.internal.ConcurrentContextImpl.exit().
|
privateinherited |
Holds the outer context or
if none (top context).
Definition at line 50 of file AbstractContext.java.
Referenced by javolution.context.AbstractContext.current(), and javolution.context.AbstractContext.enterInner().
|
private |
Definition at line 23 of file ConcurrentContextImpl.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl(), and javolution.context.internal.ConcurrentContextImpl.setConcurrency().
|
private |
Definition at line 24 of file ConcurrentContextImpl.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl(), javolution.context.internal.ConcurrentContextImpl.execute(), javolution.context.internal.ConcurrentContextImpl.getConcurrency(), and javolution.context.internal.ConcurrentContextImpl.setConcurrency().