blob: 21c494b72843c7d10d4d167509ce0ae91920264c [file] [log] [blame]
Madan Jampania090a112016-01-18 16:38:17 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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 /**
Jihwan Kimcf8f6b22016-11-12 13:07:04 +090065 * Atomic counter map.
66 */
67 COUNTER_MAP,
68
69 /**
Madan Jampania090a112016-01-18 16:38:17 -080070 * Atomic value.
71 */
72 VALUE,
73
74 /**
Madan Jampani819d61d2016-07-25 20:29:43 -070075 * Distributed work queue.
Madan Jampania090a112016-01-18 16:38:17 -080076 */
Madan Jampani819d61d2016-07-25 20:29:43 -070077 WORK_QUEUE,
Madan Jampani4124bc32016-01-30 23:53:56 -080078
79 /**
Madan Jampani79924fa2016-09-13 13:57:03 -070080 * Document tree.
81 */
82 DOCUMENT_TREE,
83
84 /**
Madan Jampani13f65152016-08-17 13:14:53 -070085 * Distributed topic.
86 */
87 TOPIC,
88
89 /**
Madan Jampani4124bc32016-01-30 23:53:56 -080090 * Leader elector.
91 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080092 LEADER_ELECTOR,
93
94 /**
95 * Transaction Context.
96 */
97 TRANSACTION_CONTEXT
Madan Jampania090a112016-01-18 16:38:17 -080098 }
99
Madan Jampani1d3b6172016-04-28 13:22:57 -0700100 /**
101 * Status of distributed primitive.
102 */
Sho SHIMIZU07e31cf2016-08-15 11:46:38 -0700103 enum Status {
Madan Jampani1d3b6172016-04-28 13:22:57 -0700104
105 /**
106 * Signifies a state wherein the primitive is operating correctly and is capable of meeting the advertised
107 * consistency and reliability guarantees.
108 */
109 ACTIVE,
110
111 /**
112 * Signifies a state wherein the primitive is temporarily incapable of providing the advertised
113 * consistency properties.
114 */
115 SUSPENDED,
116
117 /**
118 * Signifies a state wherein the primitive has been shutdown and therefore cannot perform its functions.
119 */
120 INACTIVE
121 }
122
Madan Jampani0d14a0c2016-06-02 14:36:28 -0700123 static final long DEFAULT_OPERTATION_TIMEOUT_MILLIS = 5000L;
Madan Jampanie17d3282016-02-03 15:30:57 -0800124
Madan Jampania090a112016-01-18 16:38:17 -0800125 /**
126 * Returns the name of this primitive.
127 * @return name
128 */
129 String name();
130
131 /**
132 * Returns the type of primitive.
133 * @return primitive type
134 */
Madan Jampani39fff102016-02-14 13:17:28 -0800135 Type primitiveType();
Madan Jampania090a112016-01-18 16:38:17 -0800136
137 /**
138 * Returns the application owning this primitive.
Jian Lidfba7392016-01-22 16:46:58 -0800139 * @return application id
Madan Jampania090a112016-01-18 16:38:17 -0800140 */
141 default ApplicationId applicationId() {
142 return null;
143 }
Madan Jampanifa242182016-01-22 13:42:54 -0800144
145 /**
146 * Purges state associated with this primitive.
147 * <p>
148 * Implementations can override and provide appropriate clean up logic for purging
149 * any state state associated with the primitive. Whether modifications made within the
150 * destroy method have local or global visibility is left unspecified.
Madan Jampani4124bc32016-01-30 23:53:56 -0800151 * @return {@code CompletableFuture} that is completed when the operation completes
Madan Jampanifa242182016-01-22 13:42:54 -0800152 */
153 default CompletableFuture<Void> destroy() {
154 return CompletableFuture.completedFuture(null);
155 }
Madan Jampani1d3b6172016-04-28 13:22:57 -0700156
157 /**
158 * Registers a listener to be called when the primitive's status changes.
159 * @param listener The listener to be called when the status changes.
160 */
161 default void addStatusChangeListener(Consumer<Status> listener) {}
162
163 /**
164 * Unregisters a previously registered listener to be called when the primitive's status changes.
165 * @param listener The listener to unregister
166 */
167 default void removeStatusChangeListener(Consumer<Status> listener) {}
168
169 /**
170 * Returns the collection of status change listeners previously registered.
171 * @return collection of status change listeners
172 */
173 default Collection<Consumer<Status>> statusChangeListeners() {
174 return Collections.emptyList();
175 }
Madan Jampania090a112016-01-18 16:38:17 -0800176}