Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 18 | import java.util.Collection; |
| 19 | import java.util.Collections; |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 20 | import java.util.concurrent.CompletableFuture; |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 21 | import java.util.function.Consumer; |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 22 | |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | |
| 25 | /** |
| 26 | * Interface for all distributed primitives. |
| 27 | */ |
| 28 | public interface DistributedPrimitive { |
| 29 | |
| 30 | /** |
| 31 | * Type of distributed primitive. |
| 32 | */ |
Sho SHIMIZU | 07e31cf | 2016-08-15 11:46:38 -0700 | [diff] [blame] | 33 | enum Type { |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 34 | /** |
| 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 Kruglikov | 9970265 | 2016-04-11 16:24:18 -0700 | [diff] [blame] | 45 | * Consistent Multimap. |
| 46 | */ |
| 47 | CONSISTENT_MULTIMAP, |
| 48 | |
| 49 | /** |
Jihwan Kim | cf8f6b2 | 2016-11-12 13:07:04 +0900 | [diff] [blame] | 50 | * Distributed set. |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 51 | */ |
| 52 | SET, |
| 53 | |
| 54 | /** |
Aaron Kruglikov | ed88ff6 | 2016-08-01 16:02:09 -0700 | [diff] [blame] | 55 | * Tree map. |
| 56 | */ |
| 57 | CONSISTENT_TREEMAP, |
| 58 | |
| 59 | /** |
Jihwan Kim | cf8f6b2 | 2016-11-12 13:07:04 +0900 | [diff] [blame] | 60 | * Atomic counter. |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 61 | */ |
| 62 | COUNTER, |
| 63 | |
| 64 | /** |
Jordan Halterman | 5a1053e | 2017-05-19 18:03:47 -0700 | [diff] [blame] | 65 | * Numeric ID generator. |
| 66 | */ |
| 67 | ID_GENERATOR, |
| 68 | |
| 69 | /** |
Jihwan Kim | cf8f6b2 | 2016-11-12 13:07:04 +0900 | [diff] [blame] | 70 | * Atomic counter map. |
| 71 | */ |
| 72 | COUNTER_MAP, |
| 73 | |
| 74 | /** |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 75 | * Atomic value. |
| 76 | */ |
| 77 | VALUE, |
| 78 | |
| 79 | /** |
Madan Jampani | 819d61d | 2016-07-25 20:29:43 -0700 | [diff] [blame] | 80 | * Distributed work queue. |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 81 | */ |
Madan Jampani | 819d61d | 2016-07-25 20:29:43 -0700 | [diff] [blame] | 82 | WORK_QUEUE, |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
Madan Jampani | 79924fa | 2016-09-13 13:57:03 -0700 | [diff] [blame] | 85 | * Document tree. |
| 86 | */ |
| 87 | DOCUMENT_TREE, |
| 88 | |
| 89 | /** |
Madan Jampani | 13f6515 | 2016-08-17 13:14:53 -0700 | [diff] [blame] | 90 | * Distributed topic. |
| 91 | */ |
| 92 | TOPIC, |
| 93 | |
| 94 | /** |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 95 | * Leader elector. |
| 96 | */ |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 97 | LEADER_ELECTOR, |
| 98 | |
| 99 | /** |
| 100 | * Transaction Context. |
| 101 | */ |
Jordan Halterman | 4743258 | 2018-01-25 16:56:45 -0800 | [diff] [blame] | 102 | TRANSACTION_CONTEXT, |
| 103 | |
| 104 | /** |
| 105 | * Distributed lock. |
| 106 | */ |
| 107 | LOCK, |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Status of distributed primitive. |
| 112 | */ |
Sho SHIMIZU | 07e31cf | 2016-08-15 11:46:38 -0700 | [diff] [blame] | 113 | enum Status { |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Signifies a state wherein the primitive is operating correctly and is capable of meeting the advertised |
| 117 | * consistency and reliability guarantees. |
| 118 | */ |
| 119 | ACTIVE, |
| 120 | |
| 121 | /** |
| 122 | * Signifies a state wherein the primitive is temporarily incapable of providing the advertised |
| 123 | * consistency properties. |
| 124 | */ |
| 125 | SUSPENDED, |
| 126 | |
| 127 | /** |
| 128 | * Signifies a state wherein the primitive has been shutdown and therefore cannot perform its functions. |
| 129 | */ |
| 130 | INACTIVE |
| 131 | } |
| 132 | |
Jordan Halterman | 6440b09 | 2017-05-24 17:48:08 -0700 | [diff] [blame] | 133 | /** |
Jordan Halterman | 464145d | 2017-12-20 11:52:46 -0800 | [diff] [blame] | 134 | * Default timeout for primitive operations. |
| 135 | */ |
| 136 | long DEFAULT_OPERATION_TIMEOUT_MILLIS = 15000L; |
| 137 | |
| 138 | /** |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 139 | * Returns the name of this primitive. |
| 140 | * @return name |
| 141 | */ |
| 142 | String name(); |
| 143 | |
| 144 | /** |
| 145 | * Returns the type of primitive. |
| 146 | * @return primitive type |
| 147 | */ |
Madan Jampani | 39fff10 | 2016-02-14 13:17:28 -0800 | [diff] [blame] | 148 | Type primitiveType(); |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Returns the application owning this primitive. |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 152 | * @return application id |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 153 | */ |
| 154 | default ApplicationId applicationId() { |
| 155 | return null; |
| 156 | } |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * Purges state associated with this primitive. |
| 160 | * <p> |
| 161 | * Implementations can override and provide appropriate clean up logic for purging |
| 162 | * any state state associated with the primitive. Whether modifications made within the |
| 163 | * destroy method have local or global visibility is left unspecified. |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 164 | * @return {@code CompletableFuture} that is completed when the operation completes |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 165 | */ |
| 166 | default CompletableFuture<Void> destroy() { |
| 167 | return CompletableFuture.completedFuture(null); |
| 168 | } |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * Registers a listener to be called when the primitive's status changes. |
| 172 | * @param listener The listener to be called when the status changes. |
| 173 | */ |
| 174 | default void addStatusChangeListener(Consumer<Status> listener) {} |
| 175 | |
| 176 | /** |
| 177 | * Unregisters a previously registered listener to be called when the primitive's status changes. |
| 178 | * @param listener The listener to unregister |
| 179 | */ |
| 180 | default void removeStatusChangeListener(Consumer<Status> listener) {} |
| 181 | |
| 182 | /** |
| 183 | * Returns the collection of status change listeners previously registered. |
| 184 | * @return collection of status change listeners |
| 185 | */ |
| 186 | default Collection<Consumer<Status>> statusChangeListeners() { |
| 187 | return Collections.emptyList(); |
| 188 | } |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 189 | } |