Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-2016 Open Networking Laboratory |
| 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 | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 18 | import java.util.concurrent.CompletableFuture; |
| 19 | |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | |
| 22 | /** |
| 23 | * Interface for all distributed primitives. |
| 24 | */ |
| 25 | public interface DistributedPrimitive { |
| 26 | |
| 27 | /** |
| 28 | * Type of distributed primitive. |
| 29 | */ |
| 30 | public enum Type { |
| 31 | /** |
| 32 | * Map with strong consistency semantics. |
| 33 | */ |
| 34 | CONSISTENT_MAP, |
| 35 | |
| 36 | /** |
| 37 | * Map with eventual consistency semantics. |
| 38 | */ |
| 39 | EVENTUALLY_CONSISTENT_MAP, |
| 40 | |
| 41 | /** |
| 42 | * distributed set. |
| 43 | */ |
| 44 | SET, |
| 45 | |
| 46 | /** |
| 47 | * atomic counter. |
| 48 | */ |
| 49 | COUNTER, |
| 50 | |
| 51 | /** |
| 52 | * Atomic value. |
| 53 | */ |
| 54 | VALUE, |
| 55 | |
| 56 | /** |
| 57 | * Distributed queue. |
| 58 | */ |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 59 | QUEUE, |
| 60 | |
| 61 | /** |
| 62 | * Leader elector. |
| 63 | */ |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 64 | LEADER_ELECTOR, |
| 65 | |
| 66 | /** |
| 67 | * Transaction Context. |
| 68 | */ |
| 69 | TRANSACTION_CONTEXT |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 72 | static final long DEFAULT_OPERTATION_TIMEOUT_MILLIS = 5000L; |
| 73 | |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Returns the name of this primitive. |
| 76 | * @return name |
| 77 | */ |
| 78 | String name(); |
| 79 | |
| 80 | /** |
| 81 | * Returns the type of primitive. |
| 82 | * @return primitive type |
| 83 | */ |
Madan Jampani | 39fff10 | 2016-02-14 13:17:28 -0800 | [diff] [blame] | 84 | Type primitiveType(); |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Returns the application owning this primitive. |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 88 | * @return application id |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 89 | */ |
| 90 | default ApplicationId applicationId() { |
| 91 | return null; |
| 92 | } |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Purges state associated with this primitive. |
| 96 | * <p> |
| 97 | * Implementations can override and provide appropriate clean up logic for purging |
| 98 | * any state state associated with the primitive. Whether modifications made within the |
| 99 | * destroy method have local or global visibility is left unspecified. |
Madan Jampani | 4124bc3 | 2016-01-30 23:53:56 -0800 | [diff] [blame] | 100 | * @return {@code CompletableFuture} that is completed when the operation completes |
Madan Jampani | fa24218 | 2016-01-22 13:42:54 -0800 | [diff] [blame] | 101 | */ |
| 102 | default CompletableFuture<Void> destroy() { |
| 103 | return CompletableFuture.completedFuture(null); |
| 104 | } |
Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 105 | } |