blob: d0aa27778c61e98ce1a6329145a16f4eaca7509c [file] [log] [blame]
Madan Jampania090a112016-01-18 16:38:17 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampania090a112016-01-18 16:38:17 -08003 *
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
Madan Jampani1d3b6172016-04-28 13:22:57 -070018import java.util.Collection;
19import java.util.Collections;
Madan Jampanifa242182016-01-22 13:42:54 -080020import java.util.concurrent.CompletableFuture;
Madan Jampani1d3b6172016-04-28 13:22:57 -070021import java.util.function.Consumer;
Madan Jampanifa242182016-01-22 13:42:54 -080022
Madan Jampania090a112016-01-18 16:38:17 -080023import org.onosproject.core.ApplicationId;
24
25/**
26 * Interface for all distributed primitives.
27 */
28public interface DistributedPrimitive {
29
30 /**
31 * Type of distributed primitive.
32 */
Sho SHIMIZU07e31cf2016-08-15 11:46:38 -070033 enum Type {
Madan Jampania090a112016-01-18 16:38:17 -080034 /**
35 * Map with strong consistency semantics.
36 */
37 CONSISTENT_MAP,
38
39 /**
40 * Map with eventual consistency semantics.
41 */
42 EVENTUALLY_CONSISTENT_MAP,
43
44 /**
Aaron Kruglikov99702652016-04-11 16:24:18 -070045 * Consistent Multimap.
46 */
47 CONSISTENT_MULTIMAP,
48
49 /**
Jihwan Kimcf8f6b22016-11-12 13:07:04 +090050 * Distributed set.
Madan Jampania090a112016-01-18 16:38:17 -080051 */
52 SET,
53
54 /**
Aaron Kruglikoved88ff62016-08-01 16:02:09 -070055 * Tree map.
56 */
57 CONSISTENT_TREEMAP,
58
59 /**
Jihwan Kimcf8f6b22016-11-12 13:07:04 +090060 * Atomic counter.
Madan Jampania090a112016-01-18 16:38:17 -080061 */
62 COUNTER,
63
64 /**
Jordan Halterman5a1053e2017-05-19 18:03:47 -070065 * Numeric ID generator.
66 */
67 ID_GENERATOR,
68
69 /**
Jihwan Kimcf8f6b22016-11-12 13:07:04 +090070 * Atomic counter map.
71 */
72 COUNTER_MAP,
73
74 /**
Madan Jampania090a112016-01-18 16:38:17 -080075 * Atomic value.
76 */
77 VALUE,
78
79 /**
Madan Jampani819d61d2016-07-25 20:29:43 -070080 * Distributed work queue.
Madan Jampania090a112016-01-18 16:38:17 -080081 */
Madan Jampani819d61d2016-07-25 20:29:43 -070082 WORK_QUEUE,
Madan Jampani4124bc32016-01-30 23:53:56 -080083
84 /**
Madan Jampani79924fa2016-09-13 13:57:03 -070085 * Document tree.
86 */
87 DOCUMENT_TREE,
88
89 /**
Madan Jampani13f65152016-08-17 13:14:53 -070090 * Distributed topic.
91 */
92 TOPIC,
93
94 /**
Madan Jampani4124bc32016-01-30 23:53:56 -080095 * Leader elector.
96 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080097 LEADER_ELECTOR,
98
99 /**
100 * Transaction Context.
101 */
102 TRANSACTION_CONTEXT
Madan Jampania090a112016-01-18 16:38:17 -0800103 }
104
Madan Jampani1d3b6172016-04-28 13:22:57 -0700105 /**
106 * Status of distributed primitive.
107 */
Sho SHIMIZU07e31cf2016-08-15 11:46:38 -0700108 enum Status {
Madan Jampani1d3b6172016-04-28 13:22:57 -0700109
110 /**
111 * Signifies a state wherein the primitive is operating correctly and is capable of meeting the advertised
112 * consistency and reliability guarantees.
113 */
114 ACTIVE,
115
116 /**
117 * Signifies a state wherein the primitive is temporarily incapable of providing the advertised
118 * consistency properties.
119 */
120 SUSPENDED,
121
122 /**
123 * Signifies a state wherein the primitive has been shutdown and therefore cannot perform its functions.
124 */
125 INACTIVE
126 }
127
Jordan Halterman6440b092017-05-24 17:48:08 -0700128 /**
129 * Use {@link #DEFAULT_OPERATION_TIMEOUT_MILLIS} instead.
130 */
131 @Deprecated
132 long DEFAULT_OPERTATION_TIMEOUT_MILLIS = 5000L;
133
134 /**
135 * Default timeout for primitive operations.
136 */
137 long DEFAULT_OPERATION_TIMEOUT_MILLIS = 5000L;
Madan Jampanie17d3282016-02-03 15:30:57 -0800138
Madan Jampania090a112016-01-18 16:38:17 -0800139 /**
140 * Returns the name of this primitive.
141 * @return name
142 */
143 String name();
144
145 /**
146 * Returns the type of primitive.
147 * @return primitive type
148 */
Madan Jampani39fff102016-02-14 13:17:28 -0800149 Type primitiveType();
Madan Jampania090a112016-01-18 16:38:17 -0800150
151 /**
152 * Returns the application owning this primitive.
Jian Lidfba7392016-01-22 16:46:58 -0800153 * @return application id
Madan Jampania090a112016-01-18 16:38:17 -0800154 */
155 default ApplicationId applicationId() {
156 return null;
157 }
Madan Jampanifa242182016-01-22 13:42:54 -0800158
159 /**
160 * Purges state associated with this primitive.
161 * <p>
162 * Implementations can override and provide appropriate clean up logic for purging
163 * any state state associated with the primitive. Whether modifications made within the
164 * destroy method have local or global visibility is left unspecified.
Madan Jampani4124bc32016-01-30 23:53:56 -0800165 * @return {@code CompletableFuture} that is completed when the operation completes
Madan Jampanifa242182016-01-22 13:42:54 -0800166 */
167 default CompletableFuture<Void> destroy() {
168 return CompletableFuture.completedFuture(null);
169 }
Madan Jampani1d3b6172016-04-28 13:22:57 -0700170
171 /**
172 * Registers a listener to be called when the primitive's status changes.
173 * @param listener The listener to be called when the status changes.
174 */
175 default void addStatusChangeListener(Consumer<Status> listener) {}
176
177 /**
178 * Unregisters a previously registered listener to be called when the primitive's status changes.
179 * @param listener The listener to unregister
180 */
181 default void removeStatusChangeListener(Consumer<Status> listener) {}
182
183 /**
184 * Returns the collection of status change listeners previously registered.
185 * @return collection of status change listeners
186 */
187 default Collection<Consumer<Status>> statusChangeListeners() {
188 return Collections.emptyList();
189 }
Madan Jampania090a112016-01-18 16:38:17 -0800190}