blob: baf2b8aa507e2f5cedbf518af1692963a720be8d [file] [log] [blame]
Jordan Halterman5a1053e2017-05-19 18:03:47 -07001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.primitives.impl;
17
18import java.util.concurrent.CompletableFuture;
19import java.util.concurrent.Executor;
20
21import org.onosproject.store.service.AsyncAtomicIdGenerator;
22
23/**
24 * {@link AsyncAtomicIdGenerator} that executes asynchronous callbacks on a user provided
25 * {@link Executor}.
26 */
27public class ExecutingAsyncAtomicIdGenerator extends ExecutingDistributedPrimitive implements AsyncAtomicIdGenerator {
28 private final AsyncAtomicIdGenerator delegateIdGenerator;
29
30 public ExecutingAsyncAtomicIdGenerator(
31 AsyncAtomicIdGenerator delegateIdGenerator, Executor orderedExecutor, Executor threadPoolExecutor) {
32 super(delegateIdGenerator, orderedExecutor, threadPoolExecutor);
33 this.delegateIdGenerator = delegateIdGenerator;
34 }
35
36 @Override
37 public CompletableFuture<Long> nextId() {
38 return asyncFuture(delegateIdGenerator.nextId());
39 }
40}