Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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 | */ |
| 33 | public enum Type { |
| 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 | /** |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 50 | * distributed set. |
| 51 | */ |
| 52 | SET, |
| 53 | |
| 54 | /** |
| 55 | * atomic counter. |
| 56 | */ |
| 57 | COUNTER, |
| 58 | |
| 59 | /** |
| 60 | * Atomic value. |
| 61 | */ |
| 62 | VALUE, |
| 63 | |
| 64 | /** |
| 65 | * Distributed queue. |
| 66 | */ |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 67 | QUEUE, |
| 68 | |
| 69 | /** |
| 70 | * Leader elector. |
| 71 | */ |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 72 | LEADER_ELECTOR, |
| 73 | |
| 74 | /** |
| 75 | * Transaction Context. |
| 76 | */ |
| 77 | TRANSACTION_CONTEXT |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Status of distributed primitive. |
| 82 | */ |
| 83 | public enum Status { |
| 84 | |
| 85 | /** |
| 86 | * Signifies a state wherein the primitive is operating correctly and is capable of meeting the advertised |
| 87 | * consistency and reliability guarantees. |
| 88 | */ |
| 89 | ACTIVE, |
| 90 | |
| 91 | /** |
| 92 | * Signifies a state wherein the primitive is temporarily incapable of providing the advertised |
| 93 | * consistency properties. |
| 94 | */ |
| 95 | SUSPENDED, |
| 96 | |
| 97 | /** |
| 98 | * Signifies a state wherein the primitive has been shutdown and therefore cannot perform its functions. |
| 99 | */ |
| 100 | INACTIVE |
| 101 | } |
| 102 | |
Madan Jampani | 0d14a0c | 2016-06-02 14:36:28 -0700 | [diff] [blame] | 103 | static final long DEFAULT_OPERTATION_TIMEOUT_MILLIS = 5000L; |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 104 | |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 105 | /** |
| 106 | * Returns the name of this primitive. |
| 107 | * @return name |
| 108 | */ |
| 109 | String name(); |
| 110 | |
| 111 | /** |
| 112 | * Returns the type of primitive. |
| 113 | * @return primitive type |
| 114 | */ |
Madan Jampani | 39fff10 | 2016-02-14 13:17:28 -0800 | [diff] [blame] | 115 | Type primitiveType(); |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Returns the application owning this primitive. |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 119 | * @return application id |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 120 | */ |
| 121 | default ApplicationId applicationId() { |
| 122 | return null; |
| 123 | } |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Purges state associated with this primitive. |
| 127 | * <p> |
| 128 | * Implementations can override and provide appropriate clean up logic for purging |
| 129 | * any state state associated with the primitive. Whether modifications made within the |
| 130 | * destroy method have local or global visibility is left unspecified. |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 131 | * @return {@code CompletableFuture} that is completed when the operation completes |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 132 | */ |
| 133 | default CompletableFuture<Void> destroy() { |
| 134 | return CompletableFuture.completedFuture(null); |
| 135 | } |
Madan Jampani | 1d3b617 | 2016-04-28 13:22:57 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Registers a listener to be called when the primitive's status changes. |
| 139 | * @param listener The listener to be called when the status changes. |
| 140 | */ |
| 141 | default void addStatusChangeListener(Consumer<Status> listener) {} |
| 142 | |
| 143 | /** |
| 144 | * Unregisters a previously registered listener to be called when the primitive's status changes. |
| 145 | * @param listener The listener to unregister |
| 146 | */ |
| 147 | default void removeStatusChangeListener(Consumer<Status> listener) {} |
| 148 | |
| 149 | /** |
| 150 | * Returns the collection of status change listeners previously registered. |
| 151 | * @return collection of status change listeners |
| 152 | */ |
| 153 | default Collection<Consumer<Status>> statusChangeListeners() { |
| 154 | return Collections.emptyList(); |
| 155 | } |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 156 | } |