blob: b19a04bbf612d394ea5e7dcdaf2db2c1700cd915 [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 /**
Madan Jampania090a112016-01-18 16:38:17 -080050 * distributed set.
51 */
52 SET,
53
54 /**
55 * atomic counter.
56 */
57 COUNTER,
58
59 /**
60 * Atomic value.
61 */
62 VALUE,
63
64 /**
Madan Jampani819d61d2016-07-25 20:29:43 -070065 * Distributed work queue.
Madan Jampania090a112016-01-18 16:38:17 -080066 */
Madan Jampani819d61d2016-07-25 20:29:43 -070067 WORK_QUEUE,
Madan Jampani4124bc32016-01-30 23:53:56 -080068
69 /**
Madan Jampani13f65152016-08-17 13:14:53 -070070 * Distributed topic.
71 */
72 TOPIC,
73
74 /**
Madan Jampani4124bc32016-01-30 23:53:56 -080075 * Leader elector.
76 */
Madan Jampanicadd70b2016-02-08 13:45:43 -080077 LEADER_ELECTOR,
78
79 /**
80 * Transaction Context.
81 */
82 TRANSACTION_CONTEXT
Madan Jampania090a112016-01-18 16:38:17 -080083 }
84
Madan Jampani1d3b6172016-04-28 13:22:57 -070085 /**
86 * Status of distributed primitive.
87 */
Sho SHIMIZU07e31cf2016-08-15 11:46:38 -070088 enum Status {
Madan Jampani1d3b6172016-04-28 13:22:57 -070089
90 /**
91 * Signifies a state wherein the primitive is operating correctly and is capable of meeting the advertised
92 * consistency and reliability guarantees.
93 */
94 ACTIVE,
95
96 /**
97 * Signifies a state wherein the primitive is temporarily incapable of providing the advertised
98 * consistency properties.
99 */
100 SUSPENDED,
101
102 /**
103 * Signifies a state wherein the primitive has been shutdown and therefore cannot perform its functions.
104 */
105 INACTIVE
106 }
107
Madan Jampani0d14a0c2016-06-02 14:36:28 -0700108 static final long DEFAULT_OPERTATION_TIMEOUT_MILLIS = 5000L;
Madan Jampanie17d3282016-02-03 15:30:57 -0800109
Madan Jampania090a112016-01-18 16:38:17 -0800110 /**
111 * Returns the name of this primitive.
112 * @return name
113 */
114 String name();
115
116 /**
117 * Returns the type of primitive.
118 * @return primitive type
119 */
Madan Jampani39fff102016-02-14 13:17:28 -0800120 Type primitiveType();
Madan Jampania090a112016-01-18 16:38:17 -0800121
122 /**
123 * Returns the application owning this primitive.
Jian Lidfba7392016-01-22 16:46:58 -0800124 * @return application id
Madan Jampania090a112016-01-18 16:38:17 -0800125 */
126 default ApplicationId applicationId() {
127 return null;
128 }
Madan Jampanifa242182016-01-22 13:42:54 -0800129
130 /**
131 * Purges state associated with this primitive.
132 * <p>
133 * Implementations can override and provide appropriate clean up logic for purging
134 * any state state associated with the primitive. Whether modifications made within the
135 * destroy method have local or global visibility is left unspecified.
Madan Jampani4124bc32016-01-30 23:53:56 -0800136 * @return {@code CompletableFuture} that is completed when the operation completes
Madan Jampanifa242182016-01-22 13:42:54 -0800137 */
138 default CompletableFuture<Void> destroy() {
139 return CompletableFuture.completedFuture(null);
140 }
Madan Jampani1d3b6172016-04-28 13:22:57 -0700141
142 /**
143 * Registers a listener to be called when the primitive's status changes.
144 * @param listener The listener to be called when the status changes.
145 */
146 default void addStatusChangeListener(Consumer<Status> listener) {}
147
148 /**
149 * Unregisters a previously registered listener to be called when the primitive's status changes.
150 * @param listener The listener to unregister
151 */
152 default void removeStatusChangeListener(Consumer<Status> listener) {}
153
154 /**
155 * Returns the collection of status change listeners previously registered.
156 * @return collection of status change listeners
157 */
158 default Collection<Consumer<Status>> statusChangeListeners() {
159 return Collections.emptyList();
160 }
Madan Jampania090a112016-01-18 16:38:17 -0800161}