blob: fc0e49b8bc14a335162a7dc272678a9e2df2fee9 [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.service;
17
18import java.util.concurrent.CompletableFuture;
19
20import org.onosproject.store.primitives.DefaultAtomicIdGenerator;
21
22/**
23 * An async ID generator for generating globally unique numbers.
24 */
25public interface AsyncAtomicIdGenerator extends DistributedPrimitive {
26
27 @Override
28 default Type primitiveType() {
29 return Type.ID_GENERATOR;
30 }
31
32 /**
33 * Returns the next globally unique numeric ID.
34 *
35 * @return a future to be completed with the next globally unique identifier
36 */
37 CompletableFuture<Long> nextId();
38
39 /**
40 * Returns a new {@link AtomicIdGenerator} that is backed by this instance.
41 *
42 * @param timeoutMillis timeout duration for the returned ConsistentMap operations
43 * @return new {@code AtomicIdGenerator} instance
44 */
45 default AtomicIdGenerator asAtomicIdGenerator(long timeoutMillis) {
46 return new DefaultAtomicIdGenerator(this, timeoutMillis);
47 }
48
49 /**
50 * Returns a new {@link AtomicIdGenerator} that is backed by this instance and with a default operation timeout.
51 *
52 * @return new {@code AtomicIdGenerator} instance
53 */
54 default AtomicIdGenerator asAtomicIdGenerator() {
55 return new DefaultAtomicIdGenerator(this, DEFAULT_OPERTATION_TIMEOUT_MILLIS);
56 }
57}