@@ -0,0 +1,2945 @@
+/*%0A * Copyright 2017-present Open Networking Foundation%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.atomix.primitives.queue.impl;%0A%0Aimport io.atomix.primitives.queue.AsyncWorkQueue;%0Aimport io.atomix.primitives.queue.Task;%0Aimport io.atomix.primitives.queue.WorkQueueStats;%0A%0Aimport java.util.Collection;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.Executor;%0Aimport java.util.function.Consumer;%0Aimport java.util.function.Function;%0Aimport java.util.stream.Collectors;%0A%0Aimport static com.google.common.base.MoreObjects.toStringHelper;%0A%0A/**%0A * Transcoding async work queue.%0A */%0Apublic class TranscodingAsyncWorkQueue%3CV1, V2%3E implements AsyncWorkQueue%3CV1%3E %7B%0A%0A  private final AsyncWorkQueue%3CV2%3E backingQueue;%0A  private final Function%3CV1, V2%3E valueEncoder;%0A  private final Function%3CV2, V1%3E valueDecoder;%0A%0A  public TranscodingAsyncWorkQueue(AsyncWorkQueue%3CV2%3E backingQueue, Function%3CV1, V2%3E valueEncoder, Function%3CV2, V1%3E valueDecoder) %7B%0A    this.backingQueue = backingQueue;%0A    this.valueEncoder = valueEncoder;%0A    this.valueDecoder = valueDecoder;%0A  %7D%0A%0A  @Override%0A  public String name() %7B%0A    return backingQueue.name();%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CVoid%3E addMultiple(Collection%3CV1%3E items) %7B%0A    return backingQueue.addMultiple(items.stream().map(valueEncoder).collect(Collectors.toList()));%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CCollection%3CTask%3CV1%3E%3E%3E take(int maxItems) %7B%0A    return backingQueue.take(maxItems)%0A        .thenApply(tasks -%3E tasks.stream().map(t -%3E t.map(valueDecoder))%0A            .collect(Collectors.toList()));%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CVoid%3E complete(Collection%3CString%3E taskIds) %7B%0A    return backingQueue.complete(taskIds);%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CVoid%3E registerTaskProcessor(Consumer%3CV1%3E taskProcessor, int parallelism, Executor executor) %7B%0A    return backingQueue.registerTaskProcessor(v -%3E taskProcessor.accept(valueDecoder.apply(v)), parallelism, executor);%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CVoid%3E stopProcessing() %7B%0A    return backingQueue.stopProcessing();%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CWorkQueueStats%3E stats() %7B%0A    return backingQueue.stats();%0A  %7D%0A%0A  @Override%0A  public CompletableFuture%3CVoid%3E close() %7B%0A    return backingQueue.close();%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return toStringHelper(this)%0A        .add(%22backingValue%22, backingQueue)%0A        .toString();%0A  %7D%0A%7D%0A

Add transcoding work queue.