You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/09/06 14:27:10 UTC

[18/18] git commit: temporarily added a patched version of javolution with fast collections, because the released version has several bugs (see https://java.net/jira/browse/JAVOLUTION-106 and https://java.net/jira/browse/JAVOLUTION-105)

temporarily added a patched version of javolution with fast collections, because the released version has several bugs (see https://java.net/jira/browse/JAVOLUTION-106 and https://java.net/jira/browse/JAVOLUTION-105)


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/e43574ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/e43574ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/e43574ef

Branch: refs/heads/develop
Commit: e43574efa9e27f39c58449737b480bee4f7916b9
Parents: 1c4b4a5
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Sep 6 14:26:51 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Sep 6 14:26:52 2013 +0200

----------------------------------------------------------------------
 commons/marmotta-commons/pom.xml                |   68 +
 .../java/javolution/util/FastTableTest.java     |  331 ++++
 .../ext/java/javax/realtime/RealtimeThread.java |   13 +
 .../javolution/context/AbstractContext.java     |  178 ++
 .../javolution/context/ConcurrentContext.java   |  258 +++
 .../java/javolution/context/FormatContext.java  |   39 +
 .../java/javolution/context/LocalContext.java   |  125 ++
 .../ext/java/javolution/context/LogContext.java |  157 ++
 .../javolution/context/SecurityContext.java     |  256 +++
 .../java/javolution/context/StorageContext.java |  125 ++
 .../context/internal/ConcurrentContextImpl.java |  120 ++
 .../context/internal/ConcurrentThreadImpl.java  |   74 +
 .../context/internal/LocalContextImpl.java      |   44 +
 .../context/internal/LogContextImpl.java        |   91 +
 .../context/internal/SecurityContextImpl.java   |   61 +
 .../context/internal/StorageContextImpl.java    |   87 +
 .../java/javolution/context/package-info.java   |  103 ++
 .../ext/java/javolution/doc-files/overview.html |  149 ++
 .../java/javolution/io/AppendableWriter.java    |  163 ++
 .../java/javolution/io/CharSequenceReader.java  |  156 ++
 .../src/ext/java/javolution/io/Struct.java      | 1749 ++++++++++++++++++
 .../javolution/io/UTF8ByteBufferReader.java     |  267 +++
 .../javolution/io/UTF8ByteBufferWriter.java     |  224 +++
 .../java/javolution/io/UTF8StreamReader.java    |  316 ++++
 .../java/javolution/io/UTF8StreamWriter.java    |  338 ++++
 .../src/ext/java/javolution/io/Union.java       |   54 +
 .../ext/java/javolution/io/package-info.java    |    7 +
 .../ext/java/javolution/lang/Configurable.java  |  283 +++
 .../src/ext/java/javolution/lang/Immutable.java |   45 +
 .../ext/java/javolution/lang/Initializer.java   |  149 ++
 .../src/ext/java/javolution/lang/MathLib.java   | 1471 +++++++++++++++
 .../java/javolution/lang/Parallelizable.java    |   78 +
 .../src/ext/java/javolution/lang/Realtime.java  |  118 ++
 .../src/ext/java/javolution/lang/ValueType.java |   71 +
 .../ext/java/javolution/lang/package-info.java  |    5 +
 .../osgi/internal/ConfigurableListenerImpl.java |   32 +
 .../osgi/internal/JavolutionActivator.java      |   75 +
 .../osgi/internal/LogServiceImpl.java           |  115 ++
 .../javolution/osgi/internal/OSGiServices.java  |  150 ++
 .../osgi/internal/ServiceTrackerImpl.java       |   62 +
 .../osgi/internal/XMLInputFactoryProvider.java  |   34 +
 .../osgi/internal/XMLOutputFactoryProvider.java |   34 +
 .../ext/java/javolution/test/Perfometer.java    |  271 +++
 .../ext/java/javolution/test/package-info.java  |    5 +
 .../src/ext/java/javolution/text/CharArray.java |  393 ++++
 .../src/ext/java/javolution/text/CharSet.java   |  327 ++++
 .../src/ext/java/javolution/text/Cursor.java    |  397 ++++
 .../java/javolution/text/DefaultTextFormat.java |   60 +
 .../src/ext/java/javolution/text/Text.java      | 1333 +++++++++++++
 .../ext/java/javolution/text/TextBuilder.java   |  888 +++++++++
 .../ext/java/javolution/text/TextContext.java   |   93 +
 .../ext/java/javolution/text/TextFormat.java    |  125 ++
 .../ext/java/javolution/text/TypeFormat.java    |  732 ++++++++
 .../text/internal/TextContextImpl.java          |  345 ++++
 .../ext/java/javolution/text/package-info.java  |   67 +
 .../ext/java/javolution/util/FastBitSet.java    |  361 ++++
 .../java/javolution/util/FastCollection.java    |  715 +++++++
 .../src/ext/java/javolution/util/FastMap.java   |  422 +++++
 .../src/ext/java/javolution/util/FastSet.java   |  146 ++
 .../ext/java/javolution/util/FastSortedMap.java |  205 ++
 .../ext/java/javolution/util/FastSortedSet.java |  153 ++
 .../java/javolution/util/FastSortedTable.java   |  137 ++
 .../src/ext/java/javolution/util/FastTable.java |  453 +++++
 .../src/ext/java/javolution/util/Index.java     |  262 +++
 .../util/doc-files/FastTable-WCET.png           |  Bin 0 -> 36829 bytes
 .../javolution/util/doc-files/architecture.png  |  Bin 0 -> 11414 bytes
 .../java/javolution/util/function/Consumer.java |   29 +
 .../javolution/util/function/Equalities.java    |   79 +
 .../java/javolution/util/function/Equality.java |   77 +
 .../java/javolution/util/function/Function.java |   33 +
 .../javolution/util/function/Iteration.java     |   32 +
 .../javolution/util/function/MultiVariable.java |   54 +
 .../javolution/util/function/Predicate.java     |   32 +
 .../java/javolution/util/function/Reducer.java  |   26 +
 .../java/javolution/util/function/Reducers.java |  229 +++
 .../javolution/util/function/Splittable.java    |   53 +
 .../java/javolution/util/function/Supplier.java |   30 +
 .../javolution/util/function/package-info.java  |   25 +
 .../util/internal/ReadWriteLockImpl.java        |  138 ++
 .../internal/bitset/BitSetIteratorImpl.java     |   51 +
 .../util/internal/bitset/BitSetServiceImpl.java |  373 ++++
 .../collection/AtomicCollectionImpl.java        |  194 ++
 .../internal/collection/CollectionView.java     |  268 +++
 .../collection/DistinctCollectionImpl.java      |  102 +
 .../collection/FilteredCollectionImpl.java      |  111 ++
 .../collection/MappedCollectionImpl.java        |  101 +
 .../collection/ParallelCollectionImpl.java      |  120 ++
 .../collection/ReversedCollectionImpl.java      |   98 +
 .../collection/SequentialCollectionImpl.java    |   83 +
 .../collection/SharedCollectionImpl.java        |  270 +++
 .../collection/SortedCollectionImpl.java        |  109 ++
 .../collection/UnmodifiableCollectionImpl.java  |   98 +
 .../comparator/ArrayComparatorImpl.java         |   72 +
 .../comparator/IdentityComparatorImpl.java      |   42 +
 .../LexicalCaseInsensitiveComparatorImpl.java   |   73 +
 .../comparator/LexicalComparatorImpl.java       |   76 +
 .../comparator/LexicalFastComparatorImpl.java   |   30 +
 .../comparator/StandardComparatorImpl.java      |   48 +
 .../comparator/WrapperComparatorImpl.java       |   52 +
 .../util/internal/map/AtomicMapImpl.java        |  192 ++
 .../util/internal/map/FastMapImpl.java          |  250 +++
 .../util/internal/map/FractalMapImpl.java       |  121 ++
 .../util/internal/map/MapEntryImpl.java         |   46 +
 .../javolution/util/internal/map/MapView.java   |  363 ++++
 .../util/internal/map/ParallelMapImpl.java      |  130 ++
 .../util/internal/map/SequentialMapImpl.java    |   93 +
 .../util/internal/map/SharedMapImpl.java        |  240 +++
 .../util/internal/map/UnmodifiableMapImpl.java  |  109 ++
 .../map/sorted/AtomicSortedMapImpl.java         |   82 +
 .../internal/map/sorted/FastSortedMapImpl.java  |  115 ++
 .../util/internal/map/sorted/MapEntryImpl.java  |   50 +
 .../map/sorted/SharedSortedMapImpl.java         |  107 ++
 .../util/internal/map/sorted/SortedMapView.java |  163 ++
 .../internal/map/sorted/SubSortedMapImpl.java   |  143 ++
 .../map/sorted/UnmodifiableSortedMapImpl.java   |   85 +
 .../util/internal/set/AtomicSetImpl.java        |   31 +
 .../util/internal/set/FilteredSetImpl.java      |   43 +
 .../util/internal/set/MappedSetImpl.java        |   43 +
 .../javolution/util/internal/set/SetView.java   |   49 +
 .../util/internal/set/SharedSetImpl.java        |   52 +
 .../util/internal/set/UnmodifiableSetImpl.java  |   42 +
 .../set/sorted/AtomicSortedSetImpl.java         |   62 +
 .../set/sorted/SharedSortedSetImpl.java         |   88 +
 .../util/internal/set/sorted/SortedSetView.java |   60 +
 .../internal/set/sorted/SubSortedSetImpl.java   |  144 ++
 .../set/sorted/UnmodifiableSortedSetImpl.java   |   67 +
 .../util/internal/table/AtomicTableImpl.java    |  236 +++
 .../util/internal/table/FastTableImpl.java      |  210 +++
 .../util/internal/table/FractalTableImpl.java   |  172 ++
 .../util/internal/table/QuickSort.java          |   75 +
 .../util/internal/table/ReversedTableImpl.java  |   76 +
 .../util/internal/table/SharedTableImpl.java    |  315 ++++
 .../util/internal/table/SubTableImpl.java       |  101 +
 .../util/internal/table/TableIteratorImpl.java  |   93 +
 .../util/internal/table/TableView.java          |  259 +++
 .../internal/table/UnmodifiableTableImpl.java   |   84 +
 .../table/sorted/AtomicSortedTableImpl.java     |   55 +
 .../table/sorted/FastSortedTableImpl.java       |   67 +
 .../table/sorted/SharedSortedTableImpl.java     |   57 +
 .../internal/table/sorted/SortedTableView.java  |   68 +
 .../table/sorted/SubSortedTableImpl.java        |   87 +
 .../sorted/UnmodifiableSortedTableImpl.java     |   46 +
 .../ext/java/javolution/util/package-info.java  |   32 +
 .../javolution/util/service/BitSetService.java  |  116 ++
 .../util/service/CollectionService.java         |   39 +
 .../javolution/util/service/MapService.java     |   73 +
 .../javolution/util/service/SetService.java     |   24 +
 .../util/service/SortedMapService.java          |   41 +
 .../util/service/SortedSetService.java          |   33 +
 .../util/service/SortedTableService.java        |   36 +
 .../javolution/util/service/TableService.java   |   29 +
 .../javolution/util/service/package-info.java   |    6 +
 .../java/javolution/xml/DefaultXMLFormat.java   |   59 +
 .../src/ext/java/javolution/xml/QName.java      |  233 +++
 .../src/ext/java/javolution/xml/XMLBinding.java |  298 +++
 .../src/ext/java/javolution/xml/XMLContext.java |   74 +
 .../src/ext/java/javolution/xml/XMLFormat.java  | 1029 +++++++++++
 .../java/javolution/xml/XMLObjectReader.java    |  291 +++
 .../java/javolution/xml/XMLObjectWriter.java    |  311 ++++
 .../javolution/xml/XMLReferenceResolver.java    |  206 +++
 .../java/javolution/xml/XMLSerializable.java    |   47 +
 .../javolution/xml/doc-files/xmlDataBinding.png |  Bin 0 -> 15305 bytes
 .../javolution/xml/internal/XMLContextImpl.java |  151 ++
 .../xml/internal/stream/AttributesImpl.java     |  170 ++
 .../xml/internal/stream/EntitiesImpl.java       |  155 ++
 .../xml/internal/stream/NamespacesImpl.java     |  276 +++
 .../internal/stream/XMLInputFactoryImpl.java    |  106 ++
 .../internal/stream/XMLOutputFactoryImpl.java   |  151 ++
 .../internal/stream/XMLStreamReaderImpl.java    | 1523 +++++++++++++++
 .../internal/stream/XMLStreamWriterImpl.java    |  939 ++++++++++
 .../ext/java/javolution/xml/package-info.java   |  346 ++++
 .../ext/java/javolution/xml/sax/Attributes.java |  178 ++
 .../java/javolution/xml/sax/ContentHandler.java |  144 ++
 .../java/javolution/xml/sax/DefaultHandler.java |  116 ++
 .../java/javolution/xml/sax/SAX2ReaderImpl.java |  386 ++++
 .../ext/java/javolution/xml/sax/XMLReader.java  |  346 ++++
 .../java/javolution/xml/sax/XMLReaderImpl.java  |  363 ++++
 .../java/javolution/xml/sax/package-info.java   |    8 +
 .../java/javolution/xml/stream/Location.java    |   56 +
 .../javolution/xml/stream/NamespaceContext.java |   55 +
 .../javolution/xml/stream/XMLInputFactory.java  |  150 ++
 .../javolution/xml/stream/XMLOutputFactory.java |  169 ++
 .../xml/stream/XMLStreamConstants.java          |   98 +
 .../xml/stream/XMLStreamException.java          |  128 ++
 .../javolution/xml/stream/XMLStreamReader.java  |  604 ++++++
 .../javolution/xml/stream/XMLStreamWriter.java  |  365 ++++
 .../javolution/xml/stream/package-info.java     |   17 +
 .../javolution/xml/ws/WebServiceClient.java     |  223 +++
 .../java/javolution/xml/ws/package-info.java    |    5 +
 .../commons/sesame/model/StatementCommons.java  |  169 +-
 .../collections/EquivalenceHashSet2Test.java    |   62 +
 .../collections/EquivalenceHashSetTest.java     |  136 ++
 .../kiwi/reasoner/engine/ReasoningEngine.java   |   68 +-
 .../reasoner/model/program/Justification.java   |   12 +-
 .../test/engine/ReasoningEngineTest.java        |    3 +
 .../KiWiRDFSchemaRepositoryConnectionTest.java  |    1 +
 .../kiwi/persistence/KiWiConnection.java        |    2 +-
 .../kiwi/persistence/KiWiPersistence.java       |    5 +-
 .../kiwi/model/caching/TripleTable.java         |    2 +-
 199 files changed, 34925 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/pom.xml b/commons/marmotta-commons/pom.xml
index b0b9dfe..890d36a 100644
--- a/commons/marmotta-commons/pom.xml
+++ b/commons/marmotta-commons/pom.xml
@@ -28,6 +28,52 @@
     <artifactId>marmotta-commons</artifactId>
     <name>Apache Marmotta: Common Utilities</name>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.7</version>
+                <executions>
+                    <execution>
+                        <id>add-ext</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>src/ext/java</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>add-ext-test</id>
+                        <phase>generate-test-sources</phase>
+                        <goals>
+                            <goal>add-test-source</goal>
+                        </goals>
+                        <inherited>false</inherited>
+                        <configuration>
+                            <sources>
+                                <source>src/ext-test/java</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+            <resource>
+                <directory>src/ext/resources</directory>
+            </resource>
+        </resources>
+    </build>
+
+
     <dependencies>
         <dependency>
             <groupId>com.google.guava</groupId>
@@ -83,6 +129,28 @@
             <scope>test</scope>
         </dependency>
 
+        <!-- for fast hash sets and maps with custom equivalence relations -->
+
+        <!-- TODO: for now we use the source code in ext/ because it contains some bug fixes -->
+        <!--
+        <dependency>
+            <groupId>org.javolution</groupId>
+            <artifactId>javolution-core-java</artifactId>
+            <version>6.0.1-SNAPSHOT</version>
+        </dependency>
+        -->
+
+        <!-- OSGi dependencies for Javolution -->
+        <dependency> <!-- OSGI Core Library -->
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.1</version>
+        </dependency>
+        <dependency> <!-- OSGI Compendium (log service) -->
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.3.1</version>
+        </dependency>
 
     </dependencies>
     

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java b/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
new file mode 100644
index 0000000..bee5ca0
--- /dev/null
+++ b/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
@@ -0,0 +1,331 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Random;
+
+import javolution.context.LogContext;
+import javolution.osgi.internal.OSGiServices;
+import javolution.test.Perfometer;
+
+/**
+ * Validation and performance tests of FastTable.
+ */
+public class FastTableTest {
+    
+    static final boolean INITIALIZE_REALTIME_CLASSES = OSGiServices
+            .initializeRealtimeClasses();
+
+    @SuppressWarnings("rawtypes")
+    Perfometer<Class<? extends List>> addPerf = new Perfometer<Class<? extends List>>(
+            "java.util.List#add(Object)") {
+        List<Object> list;
+
+        @SuppressWarnings("unchecked")
+        public void initialize() throws Exception {
+            list = getInput().newInstance();
+        }
+
+        protected void run(boolean measure) {
+            Object obj = new Object();
+            if (measure) list.add(obj);
+        }
+    };
+
+    @SuppressWarnings("rawtypes")
+    Perfometer<Class<? extends List>> insertPerf = new Perfometer<Class<? extends List>>(
+            "java.util.List#add(int, Object)") {
+        List<Object> list;
+        Random random;
+
+        @SuppressWarnings("unchecked")
+        public void initialize() throws Exception {
+            list = getInput().newInstance();
+            random = new Random(-1);
+        }
+
+        protected void run(boolean measure) {
+            Object obj = new Object();
+            int i = random.nextInt(list.size() + 1);
+            if (measure) list.add(i, obj);
+        }
+
+        protected void validate() {
+            assert list.size() == getNbrOfIterations();
+        }
+    };
+
+    @SuppressWarnings("rawtypes")
+    Perfometer<Class<? extends List>> newPerf = new Perfometer<Class<? extends List>>(
+            "new java.util.List()") {
+        Class<? extends List> cls;
+
+        protected void initialize() throws Exception {
+            cls = getInput();
+        }
+
+        protected void run(boolean measure) throws Exception {
+            if (measure) cls.newInstance();
+        }
+    };
+
+    @SuppressWarnings("rawtypes")
+    Perfometer<Class<? extends List>> removePerf = new Perfometer<Class<? extends List>>(
+            "java.util.List#remove(int)") {
+        List<Object> list;
+        Random random;
+
+        @SuppressWarnings("unchecked")
+        public void initialize() throws Exception {
+            list = getInput().newInstance();
+            random = new Random(-1);
+            for (int i = 0; i < getNbrOfIterations(); i++) {
+                list.add(new Object());
+            }
+        }
+
+        protected void run(boolean measure) {
+            int i = random.nextInt(list.size());
+            if (measure) list.remove(i);
+        }
+
+        protected void validate() {
+            assert list.size() == 0;
+        }
+    };
+
+    private final long ONE_SECOND_IN_NS = 1000 * 1000 * 1000L;
+    private Random random = new Random();
+
+    public void testDequeuOperations() {
+        Deque<Integer> ft = new FastTable<Integer>();
+        Deque<Integer> ad = new ArrayDeque<Integer>();
+        for (long start = System.nanoTime(), time = start; time < start + 2
+                * ONE_SECOND_IN_NS; time = System.nanoTime()) {
+            long seed = random.nextLong();
+            Throwable found = anyDequeOperation(seed, ft);
+            Throwable expected = anyDequeOperation(seed, ad);
+            assertEquals(found, expected);
+            assert areEquals(ad, ft) : found.getMessage() + "\nFound:    " + ft
+                    + "\nExpected: " + ad;
+        }
+        LogContext.info("FastTable - Deque Operations Validated!");
+    }
+
+    public void testListOperations() {
+        List<Integer> ft = new FastTable<Integer>();
+        List<Integer> al = new ArrayList<Integer>();
+        for (long start = System.nanoTime(), time = start; time < start + 2
+                * ONE_SECOND_IN_NS; time = System.nanoTime()) {
+            long seed = random.nextLong();
+            Throwable found = anyListOperation(seed, ft);
+            Throwable expected = anyListOperation(seed, al);
+            assertEquals(found, expected);
+            assert al.equals(ft) && ft.equals(al) : found.getMessage()
+                    + "\nFound:    " + ft + "\nExpected: " + al;
+        }
+        LogContext.info("FastTable - List Operations Validated!");
+    }
+
+    public void testPerformance() {
+        int N = 10000;
+        newPerf.measure(ArrayList.class, 1).print();
+        newPerf.measure(LinkedList.class, 1).print();
+        newPerf.measure(FastTable.class, 1).print();
+        addPerf.measure(ArrayList.class, N).print();
+        addPerf.measure(LinkedList.class, N).print();
+        addPerf.measure(FastTable.class, N).print();
+        insertPerf.measure(ArrayList.class, N).print();
+        insertPerf.measure(LinkedList.class, N).print();
+        insertPerf.measure(FastTable.class, N).print();
+        removePerf.measure(ArrayList.class, N).print();
+        removePerf.measure(LinkedList.class, N).print(); 
+        removePerf.measure(FastTable.class, N).print();
+    }
+
+    private Throwable anyDequeOperation(long seed, Deque<Integer> deque) {
+        random.setSeed(seed);
+        int operation = random.nextInt(20);
+        String test = "N/A";
+        try {
+            switch (operation) {
+                case 1: {
+                    test = "Test add(E)";
+                    deque.add(random.nextInt());
+                    break;
+                }
+                case 2: {
+                    test = "Test addFirst(E)";
+                    deque.addFirst(random.nextInt());
+                    break;
+                }
+                case 3: {
+                    test = "Test addLast(E)";
+                    deque.addLast(random.nextInt());
+                    break;
+                }
+                case 4: {
+                    test = "Test removeFirst(E)";
+                    deque.removeFirst();
+                    break;
+                }
+                case 5: {
+                    test = "Test removeLast(E)";
+                    deque.removeLast();
+                    break;
+                }
+                case 6: {
+                    test = "Test peekFirst/peekLast/element/pop/push/pollFirst/pollLast";
+                    deque.push(random.nextInt());
+                    deque.addFirst(deque.peekLast());
+                    deque.addLast(deque.peekFirst());
+                    deque.add(deque.element());
+                    deque.addFirst(deque.pop());
+                    deque.push(random.nextInt());
+                    deque.addLast(deque.pollFirst());
+                    deque.addFirst(deque.pollLast());
+                    break;
+                }
+                case 7: {
+                    test = "Test descendingIterator";
+                    int obj = random.nextInt();
+                    for (Iterator<Integer> i = deque.descendingIterator(); i
+                            .hasNext(); i.next()) {
+                        if (random.nextInt(deque.size()) == 0) obj = i.next();
+                    }
+                    deque.add(obj);
+                    break;
+                }
+                default:
+                    if (deque.size() > 100000) deque.clear();
+                    deque.add(random.nextInt());
+            }
+        } catch (Throwable error) {
+            return error;
+        }
+        return new Throwable(test);
+    }
+
+    private Throwable anyListOperation(long seed, List<Integer> list) {
+        random.setSeed(seed);
+        int operation = random.nextInt(20);
+        String test = "N/A";
+        try {
+            switch (operation) {
+                case 1: {
+                    test = "Test add(int, E)";
+                    int i = random.nextInt(list.size() + 1);
+                    list.add(i, random.nextInt());
+                    break;
+                }
+                case 2: {
+                    test = "Test remove(int)";
+                    int i = random.nextInt(list.size());
+                    list.remove(i);
+                    break;
+                }
+                case 3: {
+                    test = "Test add(E)";
+                    list.add(random.nextInt());
+                    break;
+                }
+                case 4: {
+                    test = "Test contains(Object)";
+                    int r = random.nextInt();
+                    int i = random.nextInt(list.size() + 1);
+                    list.add(i, r);
+                    list.add(list.contains(r) ? 1 : 0);
+                    break;
+                }
+                case 5: {
+                    test = "Test indexOf/lastIndexOf";
+                    int r = random.nextInt();
+                    list.add(random.nextInt(list.size() + 1), r);
+                    list.add(random.nextInt(list.size() + 1), r);
+                    int first = list.indexOf(r);
+                    int last = list.lastIndexOf(r);
+                    list.add(first);
+                    list.add(last);
+                    break;
+                }
+                case 6: {
+                    test = "Test subList/addAll";
+                    int s = list.size();
+                    int i = random.nextInt(s);
+                    int j = random.nextInt(s);
+                    if (i > j) break; // ArrayList throw IllegalArgumentException instead of
+                    // IndexOutOfBoundsException (which is incorrect as per List.subList contract).
+                    list.addAll(list.subList(i, j));
+                    break;
+                }
+                case 7: {
+                    test = "Test subList/clear";
+                    int s = list.size();
+                    int i = random.nextInt(s);
+                    int j = random.nextInt(s);
+                    if (i > j) break;
+                    list.subList(i, j).clear();
+                    break;
+                }
+                case 8: {
+                    test = "Test subList/containsAll";
+                    int s = list.size();
+                    int i = random.nextInt(s);
+                    int j = random.nextInt(s);
+                    if (i > j) break;
+                    boolean containsAll = list.containsAll(list.subList(i, j));
+                    list.add(containsAll ? 1 : 0);
+                    break;
+                }
+                case 9: {
+                    test = "Test iterator";
+                    int j = 0;
+                    for (ListIterator<Integer> i = list.listIterator(); i
+                            .hasNext(); i.next()) {
+                        if (random.nextInt(list.size()) == 0) j = i.next();
+                        if (random.nextInt(list.size()) == 0) j = i.previous();
+                        if (random.nextInt(list.size()) == 0) i.remove();
+                    }
+                    list.add(j);
+                    break;
+                }
+                default:
+                    if (list.size() > 100000) list.clear();
+                    list.add(random.nextInt());
+            }
+        } catch (Throwable error) {
+            return error;
+        }
+        return new Throwable(test);
+    }
+
+    private boolean areEquals(Deque<?> left, Deque<?> right) {
+        if (left.size() != right.size()) return false;
+        for (Iterator<?> il = left.iterator(), ir = right.iterator(); il
+                .hasNext();) {
+            if (!il.next().equals(ir.next())) return false;
+        }
+        return true;
+    }
+
+    private void assertEquals(Throwable found, Throwable expected) {
+        if (found.getClass().equals(expected.getClass())) return;
+        found.printStackTrace(System.err);
+        expected.printStackTrace(System.err);
+        assert false : "Exception mismatch found: " + found + ", expected: "
+                + expected;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javax/realtime/RealtimeThread.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javax/realtime/RealtimeThread.java b/commons/marmotta-commons/src/ext/java/javax/realtime/RealtimeThread.java
new file mode 100644
index 0000000..9823076
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javax/realtime/RealtimeThread.java
@@ -0,0 +1,13 @@
+package javax.realtime;
+/**
+ * Stub version (replaced by the actual class on RTSJ VM).
+ */
+public class RealtimeThread extends Thread {
+
+    /**
+     * Default constructor.
+     */
+    public RealtimeThread() {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
new file mode 100644
index 0000000..3258d53
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
@@ -0,0 +1,178 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import javolution.lang.Parallelizable;
+import javolution.context.SecurityContext.Permission;
+import javolution.lang.Realtime;
+
+/**
+ * <p> The parent class for all contexts. 
+ *     Contexts allow for cross cutting concerns (performance, logging, 
+ *     security, ...) to be addressed at run-time through OSGi published 
+ *     services without polluting the application code 
+ *     (<a href="http://en.wikipedia.org/wiki/Separation_of_concerns">
+ *     Separation of Concerns</a>).</p>
+ *     
+ * <p> Context configuration is performed in a {@code try, finally}
+ *     block statement and impacts only the current thread (although inherited 
+ *     by inner {@link ConcurrentContext} threads). 
+ * [code]
+ * AnyContext ctx = AnyContext.enter(); // Enters a context scope. 
+ * try {                             
+ *     ctx.configure(...); // Local configuration (optional).
+ *     ... // Current thread executes using the configured context.
+ * } finally {
+ *     ctx.exit(); 
+ * }[/code]</p>
+ *      
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+@Realtime
+@Parallelizable(comment = "Sequential configuration, parallel use")
+public abstract class AbstractContext {
+
+    /**
+     * Holds the last context entered (thread-local).
+     */
+    private static final ThreadLocal<AbstractContext> CURRENT = new ThreadLocal<AbstractContext>();
+
+    /**
+     * Holds the outer context or {@code null} if none (top context).
+     */
+    private AbstractContext outer;
+
+    /**
+     * Default constructor. 
+     */
+    protected AbstractContext() {}
+
+    /**
+     * Returns the current context for the current thread or {@code null}
+     * if this thread has no context (default).
+     */
+    public static AbstractContext current() {
+        return AbstractContext.CURRENT.get();
+    }
+
+    /**
+     * Returns the current context of specified type or {@code null} if none. 
+     */
+    @SuppressWarnings("unchecked")
+    protected static <T extends AbstractContext> T current(Class<T> type) {
+        AbstractContext ctx = AbstractContext.CURRENT.get();
+        while (ctx != null) {
+            if (type.isInstance(ctx))
+                return (T) ctx;
+            ctx = ctx.outer;
+        }
+        return null;
+    }
+
+    /**
+     * <p> Enters the scope of a custom context. This method raises a 
+     *    {@link 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]</p>   
+     *  
+     * @param  custom the custom context to enter.
+     * @throws IllegalArgumentException if the specified class default constructor
+     *         cannot be instantiated.
+     * @throws SecurityException if {@code SecurityContext.Permission(custom, "enter")} 
+     *         is not granted. 
+     * @see    SecurityContext.Permission
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends AbstractContext> T enter(Class<T> custom) {
+        SecurityContext.check(new Permission<T>(custom, "enter"));
+        try {
+            return (T) custom.newInstance().enterInner();
+        } catch (InstantiationException e) {
+            throw new IllegalArgumentException(
+                    "Cannot instantiate instance of " + custom, e);
+        } catch (IllegalAccessException e) {
+            throw new IllegalArgumentException("Cannot access " + custom, e);
+        }
+    }
+
+    /**
+     * 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]</p>
+     */
+    public static void inherit(AbstractContext ctx) {
+        CURRENT.set(ctx);
+    }
+
+    /**
+     * Enters the scope of an inner context which becomes the current context; 
+     * the previous current context becomes the outer of this context.
+     *  
+     * @return the inner context entered.
+     */
+    protected AbstractContext enterInner() {
+        AbstractContext inner = inner();
+        inner.outer = AbstractContext.CURRENT.get();
+        AbstractContext.CURRENT.set(inner);
+        return inner;
+    }
+
+    /**
+     * Exits the scope of this context; the outer of this context becomes  
+     * the current context.
+     * 
+     * @throws IllegalStateException if this context is not the current 
+     *         context.
+     */
+    public void exit() {
+        if (this != AbstractContext.CURRENT.get())
+            throw new IllegalStateException(
+                    "This context is not the current context");
+        AbstractContext.CURRENT.set(outer);
+        outer = null;
+    }
+
+    /**
+     * Returns the outer context of this context or {@code null} if this 
+     * context has no outer context.
+     */
+    protected AbstractContext getOuter() {
+        return outer;
+    }
+
+    /**
+     * Returns a new inner instance of this context inheriting the properties 
+     * of this context. The new instance can be configured independently 
+     * from its parent. 
+     */
+    protected abstract AbstractContext inner();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
new file mode 100644
index 0000000..8e1442a
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
@@ -0,0 +1,258 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import javolution.lang.Configurable;
+import javolution.lang.MathLib;
+import javolution.osgi.internal.OSGiServices;
+
+/**
+ * <p> A context able to take advantage of concurrent algorithms on 
+ *     multi-processors systems.</p>
+ *     
+ * <p> When a thread enters a concurrent context, it may performs concurrent
+ *     executions by calling the {@link #execute(Runnable)} static method.
+ *     The logic is then executed by a concurrent thread or by the current 
+ *     thread itself if there is no concurrent thread immediately available 
+ *     (the number of concurrent threads is limited, see {@link #CONCURRENCY}).
+ * [code]
+ * ConcurrentContext ctx = ConcurrentContext.enter(); 
+ * try { 
+ *     ctx.execute(new Runnable() {...}); 
+ *     ctx.execute(new Runnable() {...});  
+ * } finally {
+ *     ctx.exit(); // Waits for all concurrent executions to complete.
+ *                 // Re-exports any exception raised during concurrent executions. 
+ * }[/code]</p>
+ * 
+ * <p> or equivalent shorter notation:
+ * [code]
+ * ConcurrentContext.execute(new Runnable() {...}, new Runnable() {...});[/code]</p>
+ *     
+ * <p> Only after all concurrent executions are completed, is the current 
+ *     thread allowed to exit the scope of the concurrent context 
+ *     (internal synchronization).</p>
+ *     
+ * <p> Concurrent logics always execute within the same {@link AbstractContext
+ *     context} as the calling thread.</p>
+ *
+ * <p> Concurrent contexts ensure the same behavior whether or not the execution
+ *     is performed by the current thread or a concurrent thread. Any error or 
+ *     runtime exception raised during the concurrent logic executions is 
+ *     propagated to the current thread.</p>
+ *
+ * <p> Concurrent contexts are easy to use, and provide automatic 
+ *     load-balancing between processors with almost no overhead. 
+ *     Here is a concurrent/recursive quick/merge sort using anonymous inner 
+ *     classes.
+ * [code]
+ * static void concurrentSort(final FastTable<? extends Comparable> table) {
+ *     final int size = table.size();
+ *     if (size < 100) { 
+ *         table.sort(); // Direct quick sort.
+ *     } else {
+ *         // Splits table in two and sort both part concurrently.
+ *         final FastTable<? extends Comparable> t1 = new FastTable();
+ *         final FastTable<? extends Comparable> t2 = new FastTable();
+ *         ConcurrentContext ctx = ConcurrentContext.enter();
+ *         try {
+ *             ctx.execute(new Runnable() {
+ *                 public void run() {
+ *                     t1.addAll(table.subList(0, size / 2));
+ *                     concurrentSort(t1); // Recursive.
+ *                 }
+ *             });
+ *             ctx.execute(new Runnable() {
+ *                 public void run() {
+ *                     t2.addAll(table.subList(size / 2, size));
+ *                     concurrentSort(t2); // Recursive.
+ *                 }
+ *             });
+ *         } finally {
+ *           ctx.exit(); // Joins.
+ *         }
+ *         // Merges results.
+ *         for (int i=0, i1=0, i2=0; i < size; i++) {
+ *             if (i1 >= t1.size()) {
+ *                 table.set(i, t2.get(i2++));
+ *             } else if (i2 >= t2.size()) {
+ *                 table.set(i, t1.get(i1++));
+ *             } else {
+ *                 Comparable o1 = t1.get(i1);
+ *                 Comparable o2 = t2.get(i2);
+ *                 if (o1.compareTo(o2) < 0) {
+ *                     table.set(i, o1);
+ *                     i1++;
+ *                  } else {
+ *                     table.set(i, o2);
+ *                     i2++;
+ *                  }
+ *             }
+ *         }
+ *     }
+ * }[/code]</p>
+ *     
+ * <p> Here is another example using {@link #execute(java.lang.Runnable[]) 
+ *     execute(Runnable ...)} static method 
+ *    (Karatsuba recursive multiplication for large integers).
+ * [code]
+ *  public LargeInteger times(LargeInteger that) {
+ *      if (that._size <= 1) {
+ *          return times(that.longValue()); // Direct multiplication.
+ *      } else { // Karatsuba multiplication in O(n^log2(3))
+ *          int bitLength = this.bitLength();
+ *          int n = (bitLength >> 1) + (bitLength & 1);
+ *                 
+ *          // this = a + 2^n b,   that = c + 2^n d
+ *          LargeInteger b = this.shiftRight(n);
+ *          LargeInteger a = this.minus(b.shiftLeft(n));
+ *          LargeInteger d = that.shiftRight(n);
+ *          LargeInteger c = that.minus(d.shiftLeft(n));
+ *          Multiply ac = new Multiply(a, c);
+ *          Multiply bd = new Multiply(b, d);
+ *          Multiply abcd = new Multiply(a.plus(b), c.plus(d));
+ *          ConcurrentContext.execute(ac, bd, abcd); // Convenience method.  
+ *          // a*c + ((a+b)*(c+d)-a*c-b*d) 2^n + b*d 2^2n 
+ *          return  ac.result.plus(abcd.result.minus(ac.result.plus(bd.result)).shiftWordLeft(n))
+ *              .plus(bd.result.shiftWordLeft(n << 1));
+ *      }
+ *  }
+ *  private static class Multiply implements Runnable {
+ *      LargeInteger left, right, result;
+ *      Multiply(LargeInteger left, LargeInteger right) {
+ *         this.left = left;
+ *         this.right = right;
+ *      }
+ *      public void run() {
+ *         result = left.times(right); // Recursive.
+ *      }
+ *  }[/code]</p>
+ *          
+ * <p> Concurrency can be adjusted or disabled. The default concurrency 
+ *     is defined by the {@link #CONCURRENCY} configurable. 
+ * [code]
+ * ConcurrentContext ctx = ConcurrentContext.enter(); 
+ * try { 
+ *    ctx.setConcurrency(0); // Disables concurrency
+ *    runAnalysis();         // Performs analysis sequentially.
+ * } finally {
+ *    ctx.exit(); // Back to previous concurrency settings.  
+ * }[/code]</p>
+ * 
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+public abstract class ConcurrentContext extends AbstractContext {
+
+    /**
+     * Holds the maximum concurrency  
+     * (default {@code Runtime.getRuntime().availableProcessors() - 1}).
+     * The maximum concurrency is configurable. For example, the JVM option 
+     * {@code -Djavolution.context.ConcurrentContext#CONCURRENCY=0}
+     * disables concurrency. 
+     */
+    public static final Configurable<Integer> CONCURRENCY = new Configurable<Integer>() {
+        @Override
+        protected Integer getDefault() {
+            return Runtime.getRuntime().availableProcessors() - 1;
+        }
+
+        @Override
+        protected Integer initialized(Integer value) {
+            return MathLib.min(value, 65536); // Hard-limiting
+        }
+
+        @Override
+        protected Integer reconfigured(Integer oldCount, Integer newCount) {
+            throw new UnsupportedOperationException(
+                    "Concurrency reconfiguration not supported.");
+        }
+    };
+
+    /**
+     * Default constructor.
+     */
+    protected ConcurrentContext() {}
+
+    /**
+     * Enters and returns a new concurrent context instance.
+     */
+    public static ConcurrentContext enter() {
+        ConcurrentContext ctx = current(ConcurrentContext.class);
+        if (ctx == null) { // Root.
+            ctx = OSGiServices.getConcurrentContext();
+        }
+        return (ConcurrentContext) ctx.enterInner();
+    }
+
+    /**
+     * 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]
+     * 
+     * @param  logics the logics to execute concurrently if possible.
+     */
+    public static void execute(Runnable... logics) {
+        ConcurrentContext ctx = ConcurrentContext.enter();
+        try {
+            for (Runnable logic : logics) {
+                ctx.execute(logic);
+            }
+        } finally {
+            ctx.exit();
+        }
+    }
+
+    /**
+     * 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.
+     * 
+     * @param  logic the logic to be executed concurrently when possible.
+     */
+    public abstract void execute(Runnable logic);
+
+    /**
+     * Sets the maximum concurrency. Setting a value greater than the 
+     * {@link #getConcurrency() current concurrency} has no effect 
+     * (concurrency can only be reduced).
+     */
+    public abstract void setConcurrency(int concurrency);
+
+    /**
+     * 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).
+     */
+    public abstract int getConcurrency();
+
+    /**
+     * Exits the scope of this concurrent context; this method blocks until 
+     * all the concurrent executions are completed.
+     * 
+     * @throws RuntimeException re-exports any exception raised during concurrent
+     *         executions.
+     * @throws Error re-exports any error raised during concurrent executions.
+     * @throws IllegalStateException if this context is not the current 
+     *         context.
+     */
+    @Override
+    public void exit() { // Redefine here for documentation purpose.
+        super.exit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
new file mode 100644
index 0000000..a17b595
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
@@ -0,0 +1,39 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+/**
+ * <p> The parent class for all serializer/deserializer contexts.
+ *     The context format type (plain text, XML, JSON, ...) is specified by 
+ *     sub-classes. Classes may identify the plain text format through the  
+ *     {@link javolution.text.DefaultTextFormat DefaultTextFormat} annotation
+ *     or the default XML format through the 
+ *     {@link javolution.xml.DefaultXMLFormat DefaultXMLFormat} annotation.
+ * [code]
+ * @DefaultTextFormat(Complex.Cartesian.class)
+ * @DefaultXMLFormat(Complex.XML.class)
+ * public Complex {
+ *     public static final class Cartesian extends javolution.text.TextFormat<Complex> { ... }
+ *     public static final class Polar extends javolution.text.TextFormat<Complex> { ... }
+ *     public static final class XML extends javolution.text.XMLFormat<Complex> { ... }
+ *     ...
+ * }
+ * [/code]</p>
+ * 
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+public abstract class FormatContext extends AbstractContext {
+
+    /**
+     * Default constructor.
+     */
+    protected FormatContext() {}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
new file mode 100644
index 0000000..e4c5c28
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
@@ -0,0 +1,125 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import javolution.context.SecurityContext.Permission;
+import javolution.lang.Configurable;
+import javolution.osgi.internal.OSGiServices;
+
+/**
+ * <p> A context holding locally scoped {@link Parameter parameters} values.</p>
+ * <p> For example, when performing modulo arithmetics the actual modulo 
+ *     being used is usually the same for most operations and does not need 
+ *     to be specified for each operation.
+ * [code]
+ * import javolution.context.LocalContext.Parameter;
+ * public class ModuloInteger extends Number {
+ *     public static final Parameter<Integer> MODULO = new Parameter<Integer>() {
+ *          protected Integer getDefault() { return -1; }
+ *     }; 
+ *     public ModuloInteger times(ModuloInteger that) { ... }    
+ * }     
+ * LocalContext ctx = LocalContext.enter(); 
+ * try {
+ *     ctx.supersede(ModuloInteger.MODULO, 13); // Sets local modulo value.
+ *     x = a.times(b).plus(c.times(d)); // Operations modulo 13
+ *     ...
+ * } finally {
+ *     ctx.exit(); // Reverts to previous modulo setting. 
+ * }[/code]</p>
+ *     
+ * <p> As for any context, local context settings are inherited during 
+ *     {@link ConcurrentContext} executions.</p> 
+ *
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+public abstract class LocalContext extends AbstractContext {
+
+    /**
+     * A {@link Configurable configurable} parameter whose value can 
+     * be locally superseded within the scope of {@link LocalContext}.</p>
+     */
+    public static abstract class Parameter<T> extends Configurable<T> {
+
+        /**
+         * Holds the general permission to supersede any parameter value 
+         * (action "supersede").
+         */
+        public static final Permission<Parameter<?>> SUPERSEDE_PERMISSION = new Permission<Parameter<?>>(
+                Parameter.class, "supersede");
+
+        /**
+         * Holds this instance supersede permission.
+         */
+        private final Permission<Parameter<T>> supersedePermission;
+
+        /**
+         * Creates a new parameter (configurable).
+         */
+        public Parameter() {
+            this.supersedePermission = new Permission<Parameter<T>>(
+                    Parameter.class, "supersede", this);
+        }
+
+        /**
+         * Returns the permission to locally supersede the current value 
+         * of this instance.
+         */
+        public Permission<Parameter<T>> getSupersedePermission() {
+            return supersedePermission;
+        }
+
+        /**
+         * Returns the current parameter value (the default value if not 
+         * reconfigured nor {@link LocalContext#supersede superseded}).
+         */
+        public T get() {
+            LocalContext ctx = current(LocalContext.class);
+            return (ctx != null) ? ctx.getValue(this, super.get()) : super.get();
+        }
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected LocalContext() {}
+
+    /**
+     * Enters and returns a new local context instance.
+     */
+    public static LocalContext enter() {
+        LocalContext ctx = current(LocalContext.class);
+        if (ctx == null) { // Root.
+            ctx = OSGiServices.getLocalContext();
+        }
+        return (LocalContext) ctx.enterInner();
+    }
+
+    /**
+     * Supersedes the value of the specified parameter. 
+     * 
+     * @param  param the local parameter whose local value is overridden.
+     * @param  localValue the new local value.
+     * @throws SecurityException if the permission to override the specified 
+     *         parameter is not granted.
+     * @throws NullPointerException if the specified local value is {@code null}.
+     */
+    public abstract <T> void supersede(Parameter<T> param, T localValue);
+
+    /**
+     * Returns the local value of the specified parameter or the specified 
+     * default value if not {@link LocalContext#supersede superseded}. 
+     * 
+     * @param param the local parameter whose local value is returned.
+     * @param defaultValue the parameter value if not superseded.
+     */
+    protected abstract <T> T getValue(Parameter<T> param, T defaultValue);
+    
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
new file mode 100644
index 0000000..2856244
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
@@ -0,0 +1,157 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import javolution.lang.Configurable;
+import javolution.osgi.internal.OSGiServices;
+import javolution.text.TextContext;
+
+/**
+ * <p> Asynchronous logging context integrated with the OSGi logging framework.
+ *     The logging back-end, or how the log entries are displayed, stored, or
+ *     processed is unspecified but always performed asynchronously. 
+ *     When running outside OSGi, log messages are sent to {@link System#out}. 
+ *     Message formatting itself is always performed synchronously using the 
+ *     current {@link TextContext}.</p> 
+ *     
+ * <p> Logging contexts support automatic prefixing/suffixing of any information 
+ *     relevant to the user/developer (thread info, user id, and so on). 
+ * [code]
+ * void run() {
+ *     LogContext ctx = LogContext.enter(); 
+ *     try {
+ *         // Prefix the executing thread to any message being logged.
+ *         ctx.prefix("[Thread: ", Thead.currentThread(), "] "); 
+ *         ... 
+ *      } finally {
+ *         ctx.exit();
+ *      }
+ *  }[/code]</p>
+ *  
+ *  <p> Applications should separate messages elements by commas and not 
+ *      use {@link String} concatenations when calling log methods otherwise 
+ *      the concatenation is performed even when log events are filtered out.
+ * [code]
+ * LogContext ctx = LogContext.enter();
+ * try {
+ *     ctx.setLevel(Level.INFO); // Does not log debug messages. 
+ *     ... 
+ *     LogContext.debug("Index: ", index, " at maximum value"); // GOOD, no formatting performed !
+ *     LogContext.debug("Index: " + index + " at maximum value"); // BAD, formatting performed even though nothing is logged !
+ *     ...
+ * } finally {
+ *     ctx.exit();
+ * }[/code]</p>
+ * 
+ * <p> In general, the {@link Level#DEBUG} level provides information only 
+ *     relevant to developers and can be turned off after deployment.</p> 
+ *  
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ * @see <a href="https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging">Understanding OSGi Logging</a>
+ */
+public abstract class LogContext extends AbstractContext {
+
+    /**
+     * Defines the logging levels.
+     */
+    public enum Level {
+
+        DEBUG, INFO, WARNING, ERROR, FATAL
+
+    }
+
+    /**
+     * Holds the default logging level (<code>DEBUG</code>).
+     * This level is configurable. For example, running with 
+     * the option <code>-Djavolution.context.LogContext#LEVEL=WARNING</code>  
+     * causes the debug/info not to be logged. 
+     */
+    public static final Configurable<Level> LEVEL = new Configurable<Level>() {
+        @Override
+        protected Level getDefault() {
+            return Level.DEBUG;
+        }
+        @Override
+        public Level parse(String str) {
+            return Level.valueOf(str);
+        }
+    };
+
+    /**
+     * Logs the specified debug message. 
+     */
+    public static void debug(Object... message) {
+        currentLogContext().log(Level.DEBUG, message);
+    }
+
+    /**
+     * Enters and returns a new log context instance.
+     */
+    public static LogContext enter() {
+        return (LogContext) currentLogContext().enterInner();
+    }
+
+    /**
+     * Logs the specified error message (which may include any {@link Throwable}
+     * instance).
+     */
+    public static void error(Object... message) {
+        currentLogContext().log(Level.ERROR, message);
+    }
+
+    /**
+     * Logs the specified info message. 
+     */
+    public static void info(Object... message) {
+        currentLogContext().log(Level.INFO, message);
+    }
+
+    /**
+     * Logs the specified warning message. 
+     */
+    public static void warning(Object... message) {
+        currentLogContext().log(Level.WARNING, message);
+    }
+
+    private static LogContext currentLogContext() {
+        LogContext ctx = current(LogContext.class);
+        if (ctx != null)
+            return ctx;
+        return OSGiServices.getLogContext();
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected LogContext() {}
+
+    /**
+     * Prefixes all messages being logged by the specified prefixes 
+     * (prefixing existing prefixes if any).
+     */
+    public abstract void prefix(Object... prefixes);
+
+    /**
+     * Set the logging level, messages below that level are not logged.
+     */
+    public abstract void setLevel(Level level);
+
+    /**
+     * Suffixes all messages being logged by the specified suffixes
+     * (suffixing existing suffixes if any).
+     */
+    public abstract void suffix(Object... suffixes);
+
+    /**
+     * Logs the specified message at the specified level.
+     */
+    protected abstract void log(Level level, Object... message);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
new file mode 100644
index 0000000..6fab057
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
@@ -0,0 +1,256 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2007 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import javolution.osgi.internal.OSGiServices;
+
+/**
+ * <p> A high-level security context integrated with OSGi.</p>
+ *     
+ * <p> When granting/revoking permission the order is important. 
+ *     For example, the following code revokes all configurable permissions 
+ *     except for setting the concurrency level.
+ * [code]
+ * SecurityContext ctx = SecurityContext.enter(); 
+ * try {
+ *     ctx.revoke(Configurable.RECONFIGURE_PERMISSION);
+ *     ctx.grant(ConcurrentContext.CONCURRENCY.getReconfigurePermission());
+ *     ...
+ *     ConcurrentContext.CONCURRENCY.reconfigure(0); // Ok (permission specifically granted).
+ *     ...
+ *  } finally {
+ *     ctx.exit(); // Back to previous security settings. 
+ *  }[/code]</p>
+ * 
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public abstract class SecurityContext extends AbstractContext {
+
+    /**
+     * A permission associated to a specific class/action/instance. 
+     * There are three levels of permission possible, at 
+     * the class/category level, at the action level and at the instance level.
+     * Any permission granted/revoked at the higher level is explicitly 
+     * granted/revoked at the lower level. The order in which the permission 
+     * are granted/revoked is important. For example, it is possible to grant 
+     * a permission at the class level, then to revoke it at the action or 
+     * instance level. In which case, for that class the permission is granted 
+     * for all actions/instances except for those actions/instances for which the 
+     * permission has been explicitly revoked.
+     */
+    public static class Permission<T> {
+
+        /**
+         * Holds the global permission for anything.
+         */
+        public static final Permission<Object> ALL = new Permission<Object>(
+                null);
+
+        private final Class<? super T> category;
+
+        private final String action;
+
+        private final T instance;
+
+        /**
+         * Creates a security permission for all actions of the specified category.
+         */
+        public Permission(Class<? super T> category) {
+            this(category, null, null);
+        }
+
+        /**
+         * Creates a security permission for the specified action of the 
+         * specified category.
+         */
+        public Permission(Class<? super T> category, String action) {
+            this(category, action, null);
+        }
+
+        /**
+         * Creates a security permission for the specified instance and the 
+         * specified action of the specified category.
+         */
+        public Permission(Class<? super T> category, String action, T instance) {
+            this.category = category;
+            this.action = action;
+            this.instance = instance;
+        }
+
+        /**
+         * Returns the permission category or <code>null</code> for all categories.
+         */
+        public Class<? super T> getCategory() {
+            return category;
+        }
+
+        /**
+         * Returns the permission action or <code>null</code> for all actions.
+         */
+        public String getAction() {
+            return action;
+        }
+
+        /**
+         * Returns the permission instance or <code>null</code> for all instances.
+         */
+        public T getInstance() {
+            return instance;
+        }
+
+        /**
+         * Checks if the specified permission is automatically granted/revoked 
+         * by 'this' permission being granted/revoked.
+         * 
+         * @param that the permission to check.
+         * @return <code>true</code> if this permission being granted/revoked 
+         *         implies that the specified permission is granted/revoked;
+         *         <code>false</code> otherwise.
+         */
+        public boolean implies(Permission<?> that) {
+            if (category == null)
+                return true;
+            if (!category.isAssignableFrom(that.category))
+                return false;
+            if (action == null)
+                return true;
+            if (!action.equals(that.action))
+                return false;
+            if (instance == null)
+                return true;
+            if (!instance.equals(that.instance))
+                return false;
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            if (category == null)
+                return "All permissions";
+            if (action == null)
+                return "Permission for any action on " + category.getName();
+            if (instance == null)
+                return "Permission for " + action + " on " + category.getName();
+            return "Permission for " + action + " on instance " + instance
+                    + " of " + category.getName();
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == this)
+                return true;
+            if (!(obj instanceof Permission))
+                return false;
+            Permission<?> that = (Permission<?>) obj;
+            if ((category == null) && (that.category != null))
+                return false;
+            if ((category != null) && (!category.equals(that.category)))
+                return false;
+            if ((action == null) && (that.action != null))
+                return false;
+            if ((action != null) && (!action.equals(that.action)))
+                return false;
+            if ((instance == null) && (that.instance != null))
+                return false;
+            if ((instance != null) && (!instance.equals(that.instance)))
+                return false;
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return (category != null ? category.hashCode() : 0)
+                    + (action != null ? action.hashCode() : 0)
+                    + (instance != null ? instance.hashCode() : 0);
+        }
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected SecurityContext() {}
+
+    /**
+     * Enters and returns a new security context instance.
+     * 
+     * @return the new security context implementation entered. 
+     */
+    public static SecurityContext enter() {
+        return (SecurityContext) currentSecurityContext().enterInner();
+    }
+
+    /**
+     * Checks if the specified permission is granted. 
+     *
+     * @param permission the permission to check.
+     * @throws SecurityException if the specified permission is not granted.
+     */
+    public static void check(Permission<?> permission) {
+        if (!currentSecurityContext().isGranted(permission))
+            throw new SecurityException(permission + " is not granted.");
+    }
+
+    /**
+     * Indicates if the specified permission is granted.
+     *
+     * @param permission the permission to check.
+     */
+    public abstract boolean isGranted(Permission<?> permission);
+
+    /**
+     * Grants the specified permission.
+     * 
+     * @param permission the permission to grant.
+     * @param certificate  the certificate used to grant that permission or 
+     *        <code>null</code> if none.
+     * @throws SecurityException if the specified permission cannot be granted.
+     */
+    public abstract void grant(Permission<?> permission, Object certificate);
+
+    /**
+     * Revokes the specified permission.
+     * 
+     * @param permission the permission to grant.
+     * @param certificate  the certificate used to grant that permission or 
+     *        <code>null</code> if none.
+     * @throws SecurityException if the specified permission cannot be revoked.
+     */
+    public abstract void revoke(Permission<?> permission, Object certificate);
+
+    /**
+     * Grants the specified permission (convenience method).
+     * 
+     * @param permission the permission to grant.
+     * @throws SecurityException if the specified permission cannot be granted.
+     */
+    public final void grant(Permission<?> permission) {
+        grant(permission, null);
+    }
+
+    /**
+     * Revokes the specified permission (convenience method).
+     * 
+     * @param permission the permission to grant.
+     * @throws SecurityException if the specified permission cannot be revoked.
+     */
+    public final void revoke(Permission<?> permission) {
+        revoke(permission, null);
+    }
+
+    /**
+     * Returns the current security context. 
+     */
+    private static SecurityContext currentSecurityContext() {
+        SecurityContext ctx = current(SecurityContext.class);
+        if (ctx != null)
+            return ctx;
+        return OSGiServices.getSecurityContext();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
new file mode 100644
index 0000000..fe7cdba
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
@@ -0,0 +1,125 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2007 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context;
+
+import java.io.File;
+import java.io.Serializable;
+
+import javolution.lang.Configurable;
+import javolution.osgi.internal.OSGiServices;
+
+/**
+ * <p> A context for persistent storage integrated with OSGi and
+ *     {@link SecurityContext}.</p>
+ *     
+ * <p> How the data is going to be stored (database, files) is implementation
+ *     dependent. But how the resources are structured (hierarchical, semantics)
+ *     is defined by the client implementing the {@link Resource} class. 
+ * [code]
+ * class SemanticResource<T> extends SemanticEntity implements Resource<T> { ... }
+ * ...
+ * StorageContext ctx = StorageContext.enter(); // Enters the current storage service.
+ * try {
+ *     // Stores resource.
+ *     SemanticResource<Image> logoId = new SemanticResource<Image>(
+ *          "http://purl.org/goodrelations/v1#Logo|MyCompany");
+ *     ctx.write(logoId, logoImg);  // May raise SecurityException. 
+ *     ...
+ *     // Retrieves resource.
+ *     Image logoImg = ctx.read(logoId); // May raise SecurityException. 
+ *  } finally {
+ *     ctx.exit(); 
+ *  }[/code]</p>
+ *  
+ * <p> Permission to read/write resource values may or not be granted at all 
+ *     or only for particular resources. Sensitive data should always be 
+ *     encrypted (e.g. using a {@code SecuredStorageContext} sub-class).
+ *     There is no limit in the size of the data being stored (except the actual 
+ *     storage available). It is nonetheless recommended to split large data 
+ *     set in smaller resources to allow for partial/concurrent retrieval.</p> 
+ * 
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public abstract class StorageContext extends AbstractContext {
+
+    /**
+     * Holds the default storage location for file based-implementations
+     * (default {@code new File("storage")}).
+     */
+    public static final Configurable<File> FILE_STORAGE_LOCATION = new Configurable<File>() {
+        @Override
+        protected File getDefault() {
+            return new File("storage");
+        }
+
+        protected File parse(String pathname) {
+            return new File(pathname);
+        }
+    };
+    
+   /**
+     * A resource identifier. 
+     * 
+     * @param <T> The resource type (the type of the value stored).
+     */
+    public interface Resource<T> {
+
+        /**
+         * Returns an unique identifier for this resource.
+         */
+        public String uniqueID();
+
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected StorageContext() {}
+
+    /**
+     * Enters and returns a storage context instance.
+     */
+    public static StorageContext enter() {
+        return (StorageContext) currentStorageContext().enterInner();
+    }
+
+    /**
+     * Reads the persistent value of the specified resource value. 
+     * 
+     * @param resource the entity whose persistent value is returned.
+     * @return the resource value or <code>null</code> if none.
+     * @throws SecurityException if the permission to read the resource 
+     *         is not granted ({@code new 
+     *         Permission<Resource<V>>(Resource.class, "read", resource)}).
+     */
+    public abstract <V extends Serializable> V read(Resource<V> resource)
+            throws SecurityException;
+
+    /**
+     * Writes the persistent value of the specified resource.
+     * 
+     * @param resource the entity whose persistent value is stored.
+     * @param value the persistent value.
+     * @throws SecurityException if the permission to write the resource 
+     *         is not granted ({@code new 
+     *         Permission<Resource<V>>(Resource.class, "write", resource)}).
+     */
+    public abstract <V extends Serializable> void write(Resource<V> resource,
+            V value) throws SecurityException;
+
+    /**
+     * Returns the current storage context. 
+     */
+    private static StorageContext currentStorageContext() {
+        StorageContext ctx = current(StorageContext.class);
+        if (ctx != null) return ctx;
+        return OSGiServices.getStorageContext();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
new file mode 100644
index 0000000..1a3d341
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
@@ -0,0 +1,120 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context.internal;
+
+import javolution.context.ConcurrentContext;
+import javolution.lang.MathLib;
+
+/**
+ * Holds the default implementation of ConcurrentContext.
+ */
+public final class ConcurrentContextImpl extends ConcurrentContext {
+
+    private int completedCount; // Nbr of concurrent task completed.
+    private Throwable error; // Any error raised.
+
+    private int initiatedCount; // Nbr of concurrent task initiated.
+    private final ConcurrentContextImpl parent;
+    private ConcurrentThreadImpl[] threads;
+    private int lastThreadInitiated; // Holds index of the last thread initiated. 
+
+    /**
+     * Default constructor (root).
+     */
+    public ConcurrentContextImpl() {
+        this.parent = null;
+        int nbThreads = ConcurrentContext.CONCURRENCY.get();
+        threads = new ConcurrentThreadImpl[nbThreads];
+        for (int i = 0; i < nbThreads; i++) {
+            threads[i] = new ConcurrentThreadImpl();
+            threads[i].start();
+        }
+    }
+
+    /**
+     * Inner implementation.
+     */
+    public ConcurrentContextImpl(ConcurrentContextImpl parent) {
+        this.parent = parent;
+        this.threads = parent.threads; // Inherit threads from parents.
+    }
+
+    // Informs this context of the completion of a task (with possible error).
+    public synchronized void completed(Throwable error) {
+        if (error != null) {
+            this.error = error;
+        }
+        completedCount++;
+        this.notify();
+    }
+
+    @Override
+    public void execute(Runnable logic) {
+        if (threads.length > 0) { 
+            int i = lastThreadInitiated;
+            while (true) { // Searches available thread. 
+                i++;
+                if (i >= threads.length) i = 0;
+                if (threads[i].execute(logic, this)) {
+                    initiatedCount++;
+                    lastThreadInitiated = i;
+                    return;
+                }
+                if (i == lastThreadInitiated) break; // Cycled through.    
+            }
+        }
+        // No concurrent thread to do the job, lets do it ourself.
+        try {
+            logic.run();
+        } catch (Throwable e) {
+            error = e;
+        }
+    }
+
+    @Override
+    public synchronized void exit() {
+        super.exit();
+        try {
+            while (initiatedCount != completedCount) {
+                this.wait();
+            }
+        } catch (InterruptedException ex) {
+            this.error = ex;
+        }
+        if (error == null)
+            return; // Everything fine.
+        if (error instanceof RuntimeException)
+            throw (RuntimeException) error;
+        if (error instanceof Error)
+            throw (Error) error;
+        throw new RuntimeException(error);
+    }
+
+    @Override
+    public int getConcurrency() {
+        return threads.length;
+    }
+
+    @Override
+    public void setConcurrency(int concurrency) {
+        // The setting of the concurrency can only reduce the number 
+        // of threads available in the context.
+        int nbThreads = MathLib.min(parent.threads.length, concurrency);
+        threads = new ConcurrentThreadImpl[nbThreads];
+        for (int i = 0; i < nbThreads; i++) { // Reused from parent threads.
+            threads[i] = parent.threads[i];
+        }
+    }
+
+    @Override
+    protected ConcurrentContext inner() {
+        return new ConcurrentContextImpl(this);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
new file mode 100644
index 0000000..78ca5c4
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
@@ -0,0 +1,74 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context.internal;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.realtime.RealtimeThread;
+
+import javolution.context.AbstractContext;
+
+/**
+ * A worker thread executing in a concurrent context.
+ */
+public class ConcurrentThreadImpl extends RealtimeThread { 
+
+    private static int count;
+    private ConcurrentContextImpl context;
+    private AtomicBoolean isBusy = new AtomicBoolean();
+    private Runnable logic;
+    private int priority;
+
+    /**
+     * Default constructor.
+     */
+    public ConcurrentThreadImpl() {
+        this.setName("ConcurrentThread-" + ++count);
+        setDaemon(true);
+    }
+
+    /**
+     * Executes the specified logic by this thread if ready; returns
+     * {@code false} if this thread is busy.
+     */
+    public boolean execute(Runnable logic, ConcurrentContextImpl inContext) {
+        if (!isBusy.compareAndSet(false, true))
+            return false;
+        synchronized (this) {
+            this.priority = Thread.currentThread().getPriority();
+            this.context = inContext;
+            this.logic = logic;
+            this.notify();
+        }
+        return true;
+    }
+
+    @Override
+    public void run() {
+        while (true) { // Main loop.
+            try {
+                synchronized (this) {
+                    while (logic == null) this.wait();
+                }
+                this.setPriority(priority);
+                AbstractContext.inherit(context);
+                logic.run();
+                context.completed(null);
+            } catch (Throwable error) {
+                context.completed(error);
+            }
+            // Clean up.
+            logic = null;
+            context = null;
+            AbstractContext.inherit(null);
+            isBusy.set(false);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
new file mode 100644
index 0000000..ff8685d
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
@@ -0,0 +1,44 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context.internal;
+
+import javolution.context.LocalContext;
+import javolution.util.FastMap;
+
+/**
+ * Holds the default implementation of LocalContext.
+ */
+public final class LocalContextImpl extends LocalContext {
+
+    private FastMap<Parameter<?>, Object> localSettings = new FastMap<Parameter<?>, Object>();
+    private LocalContextImpl parent;
+
+    @Override
+    protected LocalContext inner() {
+        LocalContextImpl ctx = new LocalContextImpl();
+        ctx.parent = this;
+        return ctx;
+    }
+
+    @Override
+    public <T> void supersede(Parameter<T> param, T localValue) {
+        if (localValue == null) throw new NullPointerException();
+        localSettings.put(param, localValue);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected <T> T getValue(Parameter<T> param, T defaultValue) {
+        Object value = localSettings.get(param);
+        if (value != null) return (T) value;
+        if (parent != null) return parent.getValue(param, defaultValue);
+        return defaultValue;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
new file mode 100644
index 0000000..3005d03
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
@@ -0,0 +1,91 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ * 
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.context.internal;
+
+import javolution.context.LogContext;
+import javolution.osgi.internal.OSGiServices;
+import javolution.text.TextBuilder;
+
+import org.osgi.service.log.LogService;
+
+/**
+ * The default implementation of LogContext.
+ */
+public final class LogContextImpl extends LogContext {
+
+    private static final Object[] NONE = new Object[0];
+    private static final int[] TO_OSGI_LEVEL = { LogService.LOG_DEBUG,
+            LogService.LOG_INFO, LogService.LOG_WARNING, LogService.LOG_ERROR };
+
+    private Level level; // Null to use configurable LEVEL.
+    private Object[] prefix = NONE;
+    private Object[] suffix = NONE;
+
+    @Override
+    public void prefix(Object... pfx) {
+        Object[] tmp = new Object[prefix.length + pfx.length];
+        System.arraycopy(pfx, 0, tmp, 0, pfx.length);
+        System.arraycopy(prefix, 0, tmp, pfx.length, prefix.length);
+        prefix = tmp;
+    }
+
+    @Override
+    public void setLevel(Level level) {
+        this.level = level;
+    }
+
+    @Override
+    public void suffix(Object... sfx) {
+        Object[] tmp = new Object[suffix.length + sfx.length];
+        System.arraycopy(suffix, 0, tmp, 0, suffix.length);
+        System.arraycopy(sfx, 0, tmp, suffix.length, sfx.length);
+        suffix = tmp;
+    }
+
+    @Override
+    protected LogContext inner() {
+        LogContextImpl ctx = new LogContextImpl();
+        ctx.prefix = prefix;
+        ctx.suffix = suffix;
+        ctx.level = level;
+        return ctx;
+    }
+
+    @Override
+    protected void log(Level level, Object... message) {
+        if (level.compareTo(currentLevel()) < 0)
+            return;
+        TextBuilder tmp = new TextBuilder();
+        Throwable exception = null;
+        for (Object pfx : prefix) {
+            tmp.append(pfx); // Uses TextContext for formatting.
+        }
+        for (Object obj : message) {
+            if ((exception == null) && (obj instanceof Throwable)) {
+                exception = (Throwable) obj;
+            } else {
+                tmp.append(obj); // Uses TextContext for formatting.
+            }
+        }
+        for (Object sfx : suffix) {
+            tmp.append(sfx); // Uses TextContext for formatting.
+        }
+        int osgiLevel = TO_OSGI_LEVEL[level.ordinal()];
+        String msg = tmp.toString();
+        Object[] logServices = OSGiServices.getLogServices();
+        for (Object logService : logServices) {
+            ((LogService)logService).log(osgiLevel, msg, exception);
+        }
+    }
+    private Level currentLevel() {
+        if (LEVEL == null) return Level.DEBUG; // Only during class initialization.
+        if (level == null) return LEVEL.get();
+        return level;
+    }
+}