diff --git a/java/com.sap.sse.operationaltransformation/src/com/sap/sse/operationaltransformation/Operation.java b/java/com.sap.sse.operationaltransformation/src/com/sap/sse/operationaltransformation/Operation.java
index 840ab8a61c4..2f66f8f2e50 100755
--- a/java/com.sap.sse.operationaltransformation/src/com/sap/sse/operationaltransformation/Operation.java
+++ b/java/com.sap.sse.operationaltransformation/src/com/sap/sse/operationaltransformation/Operation.java
@@ -30,7 +30,7 @@ public interface Operation extends Cloneable {
/**
* If it is allowed to apply this operation {@link #requiresSynchronousExecution() asynchronously} then this method
- * should provide a key such that operations two operations that may potentially block each other return equal keys.
+ * should provide a key such that two operations that may potentially block each other return equal keys.
*
* * For example, if this operation, when applied, will insert a GPS fix into a competitor's track, its key should be diff --git a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/OperationQueueByKeyExecutor.java b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/OperationQueueByKeyExecutor.java index fa8a3a8583b..15fc4722775 100644 --- a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/OperationQueueByKeyExecutor.java +++ b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/OperationQueueByKeyExecutor.java @@ -8,7 +8,26 @@ import java.util.concurrent.Executor; import java.util.logging.Logger; import com.sap.sse.common.TimePoint; +import com.sap.sse.operationaltransformation.Operation; +/** + * Collaborates with {@link ReplicationReceiverImpl} to allow parallel execution of operations, but only for those + * that have different {@link Operation#getKeyForAsynchronousExecution() keys for asynchronous execution}. The receiver + * {@link #schedule(Object, Runnable) schedules} operations (wrapped as {@link Runnable}s) with an object of this type + * which puts it into a {@link Deque double-ended queue} specific to the key for asynchronous execution as provided by + * the operation. If it is the first operation in a new {@link Deque} then a task is scheduled for immediate execution + * which continues to poll the {@link Deque} and apply its operations until drained. This way, if the replication + * received continues to receive operations with the same key while the first operation with that key is being applied, + * the next operations with an equal key will be enqueued in the same queue and will be picked up by the already running + * task that is specific to the key. When the queue is drained, the task terminates and the queue is removed from + * {@link #operationQueuesByKey}.
+ * + * With this approach, only one task per equal key is scheduled with the {@link Executor} passed to the constructor, + * ensuring that operations with equal keys don't block each other during parallel execution. + * + * @author Axel Uhl (d043530) + * + */ public class OperationQueueByKeyExecutor { private static final Logger logger = Logger.getLogger(OperationQueueByKeyExecutor.class.getName()); diff --git a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationReceiverImpl.java b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationReceiverImpl.java index 36db6d779cd..e2ee5e584ae 100755 --- a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationReceiverImpl.java +++ b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationReceiverImpl.java @@ -140,6 +140,13 @@ public class ReplicationReceiverImpl implements ReplicationReceiver, Runnable { private final static Executor executor = ThreadPoolUtil.INSTANCE .createForegroundTaskThreadPoolExecutor(ReplicationReceiverImpl.class.getName()); + /** + * Generates a queue per distinct {@link Operation#getKeyForAsynchronousExecution() key} and schedules tasks to work + * on those queues. This way, only operations with different keys will be scheduled for parallel execution, + * therefore not blocking each other. For example, operations for fix insertions into the same track should have + * equal keys, thus getting scheduled through the same queue and hence not being applied in parallel to each other + * which would only let them wait for each other without creating any real parallelism. + */ private final OperationQueueByKeyExecutor operationQueueByKeyExecutor; /**