class DistributedOperationQueue {

  public synchronized void addByThreadId(DistributedOperation distributedOperation, long threadId) {
    if (!allowAdd) return;
    // add to map(operation's key, operations)
    ArrayList<DistributedOperation> operationListByKey = operationMapByKey.get(distributedOperation.getKey());
    if (operationListByKey == null) {
      operationListByKey = new ArrayList<DistributedOperation>();
      operationMapByKey.put(distributedOperation.getKey(), operationListByKey);
    }
    operationListByKey.add(distributedOperation);

    // add to map(threadId, operations)
    ArrayList<DistributedOperation> operationListByThreadId = operationByThreadId.get(threadId);
    if (operationListByThreadId == null) {
      operationListByThreadId = new ArrayList<DistributedOperation>();
      operationByThreadId.put(threadId, operationListByThreadId);
    }
    operationListByThreadId.add(distributedOperation);
  }

}