diff options
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/store')
54 files changed, 0 insertions, 4736 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/AbstractStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/AbstractStore.java deleted file mode 100644 index a3005e45..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/AbstractStore.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store; - -import java.util.List; - -import org.onosproject.event.Event; - -import static com.google.common.base.Preconditions.checkState; - -/** - * Base implementation of a store. - */ -public class AbstractStore<E extends Event, D extends StoreDelegate<E>> - implements Store<E, D> { - - protected D delegate; - - @Override - public void setDelegate(D delegate) { - checkState(this.delegate == null || this.delegate == delegate, - "Store delegate already set"); - this.delegate = delegate; - } - - @Override - public void unsetDelegate(D delegate) { - if (this.delegate == delegate) { - this.delegate = null; - } - } - - @Override - public boolean hasDelegate() { - return delegate != null; - } - - /** - * Notifies the delegate with the specified event. - * - * @param event event to delegate - */ - protected void notifyDelegate(E event) { - if (delegate != null) { - delegate.notify(event); - } - } - - /** - * Notifies the delegate with the specified list of events. - * - * @param events list of events to delegate - */ - protected void notifyDelegate(List<E> events) { - for (E event: events) { - notifyDelegate(event); - } - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/Store.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/Store.java deleted file mode 100644 index 8d5b53c4..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/Store.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store; - -import org.onosproject.event.Event; - -/** - * Abstraction of a entity capable of storing and/or distributing information - * across a cluster. - */ -public interface Store<E extends Event, D extends StoreDelegate<E>> { - - /** - * Sets the delegate on the store. - * - * @param delegate new store delegate - * @throws java.lang.IllegalStateException if a delegate is already - * currently set on the store and is a different one that - */ - void setDelegate(D delegate); - - /** - * Withdraws the delegate from the store. - * - * @param delegate store delegate to withdraw - * @throws java.lang.IllegalArgumentException if the delegate is not - * currently set on the store - */ - void unsetDelegate(D delegate); - - /** - * Indicates whether the store has a delegate. - * - * @return true if delegate is set - */ - boolean hasDelegate(); - -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/StoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/StoreDelegate.java deleted file mode 100644 index 71ca8cc0..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/StoreDelegate.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store; - -import org.onosproject.event.Event; - -/** - * Entity associated with a store and capable of receiving notifications of - * events within the store. - */ -public interface StoreDelegate<E extends Event> { - - /** - * Notifies the delegate via the specified event. - * - * @param event store generated event - */ - void notify(E event); - -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/Timestamp.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/Timestamp.java deleted file mode 100644 index 44238ff2..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/Timestamp.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Opaque version structure. - * <p> - * Classes implementing this interface must also implement - * {@link #hashCode()} and {@link #equals(Object)}. - */ -public interface Timestamp extends Comparable<Timestamp> { - - @Override - int hashCode(); - - @Override - boolean equals(Object obj); - - /** - * Tests if this timestamp is newer than the specified timestamp. - * - * @param other timestamp to compare against - * @return true if this instance is newer - */ - default boolean isNewerThan(Timestamp other) { - return this.compareTo(checkNotNull(other)) > 0; - } - - /** - * Tests if this timestamp is older than the specified timestamp. - * - * @param other timestamp to compare against - * @return true if this instance is older - */ - default boolean isOlderThan(Timestamp other) { - return this.compareTo(checkNotNull(other)) < 0; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterCommunicationService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterCommunicationService.java deleted file mode 100644 index 161a8528..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterCommunicationService.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.onosproject.cluster.NodeId; - -/** - * Service for assisting communications between controller cluster nodes. - */ -public interface ClusterCommunicationService { - - /** - * Adds a new subscriber for the specified message subject. - * - * @param subject message subject - * @param subscriber message subscriber - * @param executor executor to use for running handler. - * @deprecated in Cardinal Release - */ - @Deprecated - void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor); - - /** - * Broadcasts a message to all controller nodes. - * - * @param message message to send - * @param subject message subject - * @param encoder function for encoding message to byte[] - * @param <M> message type - */ - <M> void broadcast(M message, - MessageSubject subject, - Function<M, byte[]> encoder); - - /** - * Broadcasts a message to all controller nodes including self. - * - * @param message message to send - * @param subject message subject - * @param encoder function for encoding message to byte[] - * @param <M> message type - */ - <M> void broadcastIncludeSelf(M message, - MessageSubject subject, - Function<M, byte[]> encoder); - - /** - * Sends a message to the specified controller node. - * - * @param message message to send - * @param subject message subject - * @param encoder function for encoding message to byte[] - * @param toNodeId destination node identifier - * @param <M> message type - * @return future that is completed when the message is sent - */ - <M> CompletableFuture<Void> unicast(M message, - MessageSubject subject, - Function<M, byte[]> encoder, - NodeId toNodeId); - - /** - * Multicasts a message to a set of controller nodes. - * - * @param message message to send - * @param subject message subject - * @param encoder function for encoding message to byte[] - * @param nodeIds recipient node identifiers - * @param <M> message type - */ - <M> void multicast(M message, - MessageSubject subject, - Function<M, byte[]> encoder, - Set<NodeId> nodeIds); - - /** - * Sends a message and expects a reply. - * - * @param message message to send - * @param subject message subject - * @param encoder function for encoding request to byte[] - * @param decoder function for decoding response from byte[] - * @param toNodeId recipient node identifier - * @param <M> request type - * @param <R> reply type - * @return reply future - */ - <M, R> CompletableFuture<R> sendAndReceive(M message, - MessageSubject subject, - Function<M, byte[]> encoder, - Function<byte[], R> decoder, - NodeId toNodeId); - - /** - * Adds a new subscriber for the specified message subject. - * - * @param subject message subject - * @param decoder decoder for resurrecting incoming message - * @param handler handler function that processes the incoming message and produces a reply - * @param encoder encoder for serializing reply - * @param executor executor to run this handler on - * @param <M> incoming message type - * @param <R> reply message type - */ - <M, R> void addSubscriber(MessageSubject subject, - Function<byte[], M> decoder, - Function<M, R> handler, - Function<R, byte[]> encoder, - Executor executor); - - /** - * Adds a new subscriber for the specified message subject. - * - * @param subject message subject - * @param decoder decoder for resurrecting incoming message - * @param handler handler function that processes the incoming message and produces a reply - * @param encoder encoder for serializing reply - * @param <M> incoming message type - * @param <R> reply message type - */ - <M, R> void addSubscriber(MessageSubject subject, - Function<byte[], M> decoder, - Function<M, CompletableFuture<R>> handler, - Function<R, byte[]> encoder); - - /** - * Adds a new subscriber for the specified message subject. - * - * @param subject message subject - * @param decoder decoder to resurrecting incoming message - * @param handler handler for handling message - * @param executor executor to run this handler on - * @param <M> incoming message type - */ - <M> void addSubscriber(MessageSubject subject, - Function<byte[], M> decoder, - Consumer<M> handler, - Executor executor); - - /** - * Removes a subscriber for the specified message subject. - * - * @param subject message subject - */ - void removeSubscriber(MessageSubject subject); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessage.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessage.java deleted file mode 100644 index 46560e4c..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessage.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Objects; - -import org.onlab.util.ByteArraySizeHashPrinter; -import org.onosproject.cluster.NodeId; - -import com.google.common.base.Charsets; -import com.google.common.base.MoreObjects; - -// TODO: Should payload type be ByteBuffer? -/** - * Base message for cluster-wide communications. - */ -public class ClusterMessage { - - private final NodeId sender; - private final MessageSubject subject; - private final byte[] payload; - private transient byte[] response; - - /** - * Creates a cluster message. - * - * @param sender message sender - * @param subject message subject - * @param payload message payload - */ - public ClusterMessage(NodeId sender, MessageSubject subject, byte[] payload) { - this.sender = sender; - this.subject = subject; - this.payload = payload; - } - - /** - * Returns the id of the controller sending this message. - * - * @return message sender id. - */ - public NodeId sender() { - return sender; - } - - /** - * Returns the message subject indicator. - * - * @return message subject - */ - public MessageSubject subject() { - return subject; - } - - /** - * Returns the message payload. - * - * @return message payload. - */ - public byte[] payload() { - return payload; - } - - /** - * Records the response to be sent to the sender. - * - * @param data response payload - */ - public void respond(byte[] data) { - response = data; - } - - /** - * Returns the response to be sent to the sender. - * - * @return response bytes - */ - public byte[] response() { - return response; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("sender", sender) - .add("subject", subject) - .add("payload", ByteArraySizeHashPrinter.of(payload)) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof ClusterMessage)) { - return false; - } - - ClusterMessage that = (ClusterMessage) o; - - return Objects.equals(this.sender, that.sender) && - Objects.equals(this.subject, that.subject) && - Arrays.equals(this.payload, that.payload); - } - - /** - * Serializes this instance. - * @return bytes - */ - public byte[] getBytes() { - byte[] senderBytes = sender.toString().getBytes(Charsets.UTF_8); - byte[] subjectBytes = subject.value().getBytes(Charsets.UTF_8); - int capacity = 12 + senderBytes.length + subjectBytes.length + payload.length; - ByteBuffer buffer = ByteBuffer.allocate(capacity); - buffer.putInt(senderBytes.length); - buffer.put(senderBytes); - buffer.putInt(subjectBytes.length); - buffer.put(subjectBytes); - buffer.putInt(payload.length); - buffer.put(payload); - return buffer.array(); - } - - /** - * Decodes a new ClusterMessage from raw bytes. - * @param bytes raw bytes - * @return cluster message - */ - public static ClusterMessage fromBytes(byte[] bytes) { - ByteBuffer buffer = ByteBuffer.wrap(bytes); - byte[] senderBytes = new byte[buffer.getInt()]; - buffer.get(senderBytes); - byte[] subjectBytes = new byte[buffer.getInt()]; - buffer.get(subjectBytes); - byte[] payloadBytes = new byte[buffer.getInt()]; - buffer.get(payloadBytes); - - return new ClusterMessage(new NodeId(new String(senderBytes, Charsets.UTF_8)), - new MessageSubject(new String(subjectBytes, Charsets.UTF_8)), - payloadBytes); - } - - @Override - public int hashCode() { - return Objects.hash(sender, subject, payload); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessageHandler.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessageHandler.java deleted file mode 100644 index ce770a81..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/ClusterMessageHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -/** - * Interface for handling cluster messages. - */ -public interface ClusterMessageHandler { - - /** - * Handles/Processes the cluster message. - * @param message cluster message. - */ - void handle(ClusterMessage message); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/Endpoint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/Endpoint.java deleted file mode 100644 index 2ac50dfd..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/Endpoint.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Objects; - -import org.onlab.packet.IpAddress; - -import com.google.common.base.MoreObjects; - -/** - * Representation of a TCP/UDP communication end point. - */ -public final class Endpoint { - - private final int port; - private final IpAddress ip; - - public Endpoint(IpAddress host, int port) { - this.ip = checkNotNull(host); - this.port = port; - } - - public IpAddress host() { - return ip; - } - - public int port() { - return port; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ip", ip) - .add("port", port) - .toString(); - } - - @Override - public int hashCode() { - return Objects.hash(ip, port); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Endpoint that = (Endpoint) obj; - return Objects.equals(this.port, that.port) && - Objects.equals(this.ip, that.ip); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessageSubject.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessageSubject.java deleted file mode 100644 index 8d5e313d..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessageSubject.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Objects; - -/** - * Representation of a message subject. - * Cluster messages have associated subjects that dictate how they get handled - * on the receiving side. - */ -public final class MessageSubject { - - private final String value; - - public MessageSubject(String value) { - this.value = checkNotNull(value); - } - - public String value() { - return value; - } - - @Override - public String toString() { - return value; - } - - @Override - public int hashCode() { - return value.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - MessageSubject that = (MessageSubject) obj; - return Objects.equals(this.value, that.value); - } - - // for serializer - protected MessageSubject() { - this.value = ""; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessagingService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessagingService.java deleted file mode 100644 index 6ccd4835..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/MessagingService.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.cluster.messaging; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.function.Consumer; -import java.util.function.Function; - -/** - * Interface for low level messaging primitives. - */ -public interface MessagingService { - - /** - * Sends a message asynchronously to the specified communication end point. - * The message is specified using the type and payload. - * @param ep end point to send the message to. - * @param type type of message. - * @param payload message payload bytes. - * @return future that is completed when the message is sent - */ - CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload); - - /** - * Sends a message synchronously and waits for a response. - * @param ep end point to send the message to. - * @param type type of message. - * @param payload message payload. - * @return a response future - */ - CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload); - - /** - * Registers a new message handler for message type. - * @param type message type. - * @param handler message handler - * @param executor executor to use for running message handler logic. - */ - void registerHandler(String type, Consumer<byte[]> handler, Executor executor); - - /** - * Registers a new message handler for message type. - * @param type message type. - * @param handler message handler - * @param executor executor to use for running message handler logic. - */ - void registerHandler(String type, Function<byte[], byte[]> handler, Executor executor); - - /** - * Registers a new message handler for message type. - * @param type message type. - * @param handler message handler - */ - void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler); - - /** - * Unregister current handler, if one exists for message type. - * @param type message type - */ - void unregisterHandler(String type); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/package-info.java deleted file mode 100644 index 582c50ed..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/cluster/messaging/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Cluster messaging APIs for the use by the various distributed stores. - */ -package org.onosproject.store.cluster.messaging; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/package-info.java deleted file mode 100644 index b6269ea5..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Abstractions for creating and interacting with distributed stores. - */ -package org.onosproject.store; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java deleted file mode 100644 index cfaf314c..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.concurrent.CompletableFuture; - -/** - * An async atomic counter dispenses monotonically increasing values. - */ -public interface AsyncAtomicCounter { - - /** - * Atomically increment by one the current value. - * - * @return updated value - */ - CompletableFuture<Long> incrementAndGet(); - - /** - * Atomically increment by one the current value. - * - * @return previous value - */ - CompletableFuture<Long> getAndIncrement(); - - /** - * Atomically adds the given value to the current value. - * - * @param delta the value to add - * @return previous value - */ - CompletableFuture<Long> getAndAdd(long delta); - - /** - * Atomically adds the given value to the current value. - * - * @param delta the value to add - * @return updated value - */ - CompletableFuture<Long> addAndGet(long delta); - - /** - * Returns the current value of the counter without modifying it. - * - * @return current value - */ - CompletableFuture<Long> get(); - - - /** - * Atomically sets the given value to the current value. - * - * @param value new value - * @return future void - */ - CompletableFuture<Void> set(long value); - - /** - * Atomically sets the given counter to the updated value if the current value is the expected value, otherwise - * no change occurs. - * @param expectedValue the expected current value of the counter - * @param updateValue the new value to be set - * @return true if the update occurred and the expected value was equal to the current value, false otherwise - */ - CompletableFuture<Boolean> compareAndSet(long expectedValue, long updateValue); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java deleted file mode 100644 index fee8cfa6..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import java.util.Collection; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; - -/** - * A distributed, strongly consistent map whose methods are all executed asynchronously. - * <p> - * This map offers strong read-after-update (where update == create/update/delete) - * consistency. All operations to the map are serialized and applied in a consistent - * manner. - * <p> - * The stronger consistency comes at the expense of availability in - * the event of a network partition. A network partition can be either due to - * a temporary disruption in network connectivity between participating nodes - * or due to a node being temporarily down. - * </p><p> - * All values stored in this map are versioned and the API supports optimistic - * concurrency by allowing conditional updates that take into consideration - * the version or value that was previously read. - * </p><p> - * This map does not allow null values. All methods can throw a ConsistentMapException - * (which extends RuntimeException) to indicate failures. - * - */ -public interface AsyncConsistentMap<K, V> { - - /** - * Returns the number of entries in the map. - * - * @return a future for map size. - */ - CompletableFuture<Integer> size(); - - /** - * Returns true if the map is empty. - * - * @return a future whose value will be true if map has no entries, false otherwise. - */ - CompletableFuture<Boolean> isEmpty(); - - /** - * Returns true if this map contains a mapping for the specified key. - * - * @param key key - * @return a future whose value will be true if map contains key, false otherwise. - */ - CompletableFuture<Boolean> containsKey(K key); - - /** - * Returns true if this map contains the specified value. - * - * @param value value - * @return a future whose value will be true if map contains value, false otherwise. - */ - CompletableFuture<Boolean> containsValue(V value); - - /** - * Returns the value (and version) to which the specified key is mapped, or null if this - * map contains no mapping for the key. - * - * @param key the key whose associated value (and version) is to be returned - * @return a future value (and version) to which the specified key is mapped, or null if - * this map contains no mapping for the key - */ - CompletableFuture<Versioned<V>> get(K key); - - /** - * If the specified key is not already associated with a value (or is mapped to null), - * attempts to compute its value using the given mapping function and enters it into - * this map unless null. - * If a conflicting concurrent modification attempt is detected, the returned future - * will be completed exceptionally with ConsistentMapException.ConcurrentModification. - * @param key key with which the specified value is to be associated - * @param mappingFunction the function to compute a value - * @return the current (existing or computed) value associated with the specified key, - * or null if the computed value is null - */ - CompletableFuture<Versioned<V>> computeIfAbsent(K key, - Function<? super K, ? extends V> mappingFunction); - - /** - * If the value for the specified key is present and non-null, attempts to compute a new - * mapping given the key and its current mapped value. - * If the computed value is null, the current mapping will be removed from the map. - * If a conflicting concurrent modification attempt is detected, the returned future - * will be completed exceptionally with ConsistentMapException.ConcurrentModification. - * @param key key with which the specified value is to be associated - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or null if computed value is null - */ - CompletableFuture<Versioned<V>> computeIfPresent(K key, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * Attempts to compute a mapping for the specified key and its current mapped value (or - * null if there is no current mapping). - * If the computed value is null, the current mapping (if one exists) will be removed from the map. - * If a conflicting concurrent modification attempt is detected, the returned future - * will be completed exceptionally with ConsistentMapException.ConcurrentModification. - * @param key key with which the specified value is to be associated - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or null if computed value is null - */ - CompletableFuture<Versioned<V>> compute(K key, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * If the value for the specified key satisfies a condition, attempts to compute a new - * mapping given the key and its current mapped value. - * If the computed value is null, the current mapping will be removed from the map. - * If a conflicting concurrent modification attempt is detected, the returned future - * will be completed exceptionally with ConsistentMapException.ConcurrentModification. - * @param key key with which the specified value is to be associated - * @param condition condition that should evaluate to true for the computation to proceed - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or the old value if condition evaluates to false - */ - CompletableFuture<Versioned<V>> computeIf(K key, - Predicate<? super V> condition, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * Associates the specified value with the specified key in this map (optional operation). - * If the map previously contained a mapping for the key, the old value is replaced by the - * specified value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value (and version) associated with key, or null if there was - * no mapping for key. - */ - CompletableFuture<Versioned<V>> put(K key, V value); - - /** - * Associates the specified value with the specified key in this map (optional operation). - * If the map previously contained a mapping for the key, the old value is replaced by the - * specified value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return new value. - */ - CompletableFuture<Versioned<V>> putAndGet(K key, V value); - - /** - * Removes the mapping for a key from this map if it is present (optional operation). - * - * @param key key whose value is to be removed from the map - * @return the value (and version) to which this map previously associated the key, - * or null if the map contained no mapping for the key. - */ - CompletableFuture<Versioned<V>> remove(K key); - - /** - * Removes all of the mappings from this map (optional operation). - * The map will be empty after this call returns. - * @return future that will be successfully completed when the map is cleared - */ - CompletableFuture<Void> clear(); - - /** - * Returns a Set view of the keys contained in this map. - * This method differs from the behavior of java.util.Map.keySet() in that - * what is returned is a unmodifiable snapshot view of the keys in the ConsistentMap. - * Attempts to modify the returned set, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return a set of the keys contained in this map - */ - CompletableFuture<Set<K>> keySet(); - - /** - * Returns the collection of values (and associated versions) contained in this map. - * This method differs from the behavior of java.util.Map.values() in that - * what is returned is a unmodifiable snapshot view of the values in the ConsistentMap. - * Attempts to modify the returned collection, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return a collection of the values (and associated versions) contained in this map - */ - CompletableFuture<Collection<Versioned<V>>> values(); - - /** - * Returns the set of entries contained in this map. - * This method differs from the behavior of java.util.Map.entrySet() in that - * what is returned is a unmodifiable snapshot view of the entries in the ConsistentMap. - * Attempts to modify the returned set, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return set of entries contained in this map. - */ - CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet(); - - /** - * If the specified key is not already associated with a value - * associates it with the given value and returns null, else returns the current value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with the specified key or null - * if key does not already mapped to a value. - */ - CompletableFuture<Versioned<V>> putIfAbsent(K key, V value); - - /** - * Removes the entry for the specified key only if it is currently - * mapped to the specified value. - * - * @param key key with which the specified value is associated - * @param value value expected to be associated with the specified key - * @return true if the value was removed - */ - CompletableFuture<Boolean> remove(K key, V value); - - /** - * Removes the entry for the specified key only if its current - * version in the map is equal to the specified version. - * - * @param key key with which the specified version is associated - * @param version version expected to be associated with the specified key - * @return true if the value was removed - */ - CompletableFuture<Boolean> remove(K key, long version); - - /** - * Replaces the entry for the specified key only if currently mapped - * to the specified value. - * - * @param key key with which the specified value is associated - * @param oldValue value expected to be associated with the specified key - * @param newValue value to be associated with the specified key - * @return true if the value was replaced - */ - CompletableFuture<Boolean> replace(K key, V oldValue, V newValue); - - /** - * Replaces the entry for the specified key only if it is currently mapped to the - * specified version. - * - * @param key key key with which the specified value is associated - * @param oldVersion version expected to be associated with the specified key - * @param newValue value to be associated with the specified key - * @return true if the value was replaced - */ - CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue); - - /** - * Registers the specified listener to be notified whenever the map is updated. - * - * @param listener listener to notify about map events - */ - void addListener(MapEventListener<K, V> listener); - - /** - * Unregisters the specified listener such that it will no longer - * receive map change notifications. - * - * @param listener listener to unregister - */ - void removeListener(MapEventListener<K, V> listener); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java deleted file mode 100644 index 3c9e02c8..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Distributed version of java.util.concurrent.atomic.AtomicLong. - */ -public interface AtomicCounter { - - /** - * Atomically increment by one the current value. - * - * @return updated value - */ - long incrementAndGet(); - - /** - * Atomically increment by one the current value. - * - * @return previous value - */ - long getAndIncrement(); - - /** - * Atomically adds the given value to the current value. - * - * @param delta the value to add - * @return previous value - */ - long getAndAdd(long delta); - - /** - * Atomically adds the given value to the current value. - * - * @param delta the value to add - * @return updated value - */ - long addAndGet(long delta); - - /** - * Atomically sets the given value to the current value. - * - * @param value the value to set - */ - void set(long value); - - /** - * Atomically sets the given counter to the updated value if the current value is the expected value, otherwise - * no change occurs. - * @param expectedValue the expected current value of the counter - * @param updateValue the new value to be set - * @return true if the update occurred and the expected value was equal to the current value, false otherwise - */ - boolean compareAndSet(long expectedValue, long updateValue); - - /** - * Returns the current value of the counter without modifying it. - * - * @return current value - */ - long get(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounterBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounterBuilder.java deleted file mode 100644 index 41a19f0d..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicCounterBuilder.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Builder for AtomicCounter. - */ -public interface AtomicCounterBuilder { - - /** - * Sets the name for the atomic counter. - * <p> - * Each atomic counter is identified by a unique name. - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the atomic counter - * @return this AtomicCounterBuilder - */ - AtomicCounterBuilder withName(String name); - - /** - * Creates this counter on the partition that spans the entire cluster. - * <p> - * When partitioning is disabled, the counter state will be - * ephemeral and does not survive a full cluster restart. - * </p> - * <p> - * Note: By default partitions are enabled. - * </p> - * @return this AtomicCounterBuilder - */ - AtomicCounterBuilder withPartitionsDisabled(); - - /** - * Instantiates Metering service to gather usage and performance metrics. - * By default, usage data will be stored. - * - * @return this AtomicCounterBuilder - */ - AtomicCounterBuilder withMeteringDisabled(); - - /** - * Builds a AtomicCounter based on the configuration options - * supplied to this builder. - * - * @return new AtomicCounter - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - AtomicCounter build(); - - /** - * Builds a AsyncAtomicCounter based on the configuration options - * supplied to this builder. - * - * @return new AsyncAtomicCounter - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - AsyncAtomicCounter buildAsyncCounter(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java deleted file mode 100644 index dfa0fb3c..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Distributed version of java.util.concurrent.atomic.AtomicReference. - * - * @param <V> value type - */ -public interface AtomicValue<V> { - - /** - * Atomically sets the value to the given updated value if the current value is equal to the expected value. - * <p> - * IMPORTANT: Equality is based on the equality of the serialized byte[] representations. - * <p> - * @param expect the expected value - * @param update the new value - * @return true if successful. false return indicates that the actual value was not equal to the expected value. - */ - boolean compareAndSet(V expect, V update); - - /** - * Gets the current value. - * @return current value - */ - V get(); - - /** - * Atomically sets to the given value and returns the old value. - * @param value the new value - * @return previous value - */ - V getAndSet(V value); - - /** - * Sets to the given value. - * @param value new value - */ - void set(V value); - - /** - * Registers the specified listener to be notified whenever the atomic value is updated. - * - * @param listener listener to notify about events - */ - void addListener(AtomicValueEventListener<V> listener); - - /** - * Unregisters the specified listener such that it will no longer - * receive atomic value update notifications. - * - * @param listener listener to unregister - */ - void removeListener(AtomicValueEventListener<V> listener); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueBuilder.java deleted file mode 100644 index 3478ce00..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueBuilder.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Builder for constructing new AtomicValue instances. - * - * @param <V> atomic value type - */ -public interface AtomicValueBuilder<V> { - /** - * Sets the name for the atomic value. - * <p> - * Each atomic value is identified by a unique name. - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the atomic value - * @return this AtomicValueBuilder for method chaining - */ - AtomicValueBuilder<V> withName(String name); - - /** - * Sets a serializer that can be used to serialize the value. - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param serializer serializer - * @return this AtomicValueBuilder for method chaining - */ - AtomicValueBuilder<V> withSerializer(Serializer serializer); - - /** - * Creates this atomic value on the partition that spans the entire cluster. - * <p> - * When partitioning is disabled, the value state will be - * ephemeral and does not survive a full cluster restart. - * </p> - * <p> - * Note: By default partitions are enabled. - * </p> - * @return this AtomicValueBuilder for method chaining - */ - AtomicValueBuilder<V> withPartitionsDisabled(); - - /** - * Instantiates Metering service to gather usage and performance metrics. - * By default, usage data will be stored. - * - * @return this AtomicValueBuilder for method chaining - */ - AtomicValueBuilder<V> withMeteringDisabled(); - - /** - * Builds a AtomicValue based on the configuration options - * supplied to this builder. - * - * @return new AtomicValue - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - AtomicValue<V> build(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEvent.java deleted file mode 100644 index 1bce1365..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEvent.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Objects; - -import com.google.common.base.MoreObjects; - -/** - * Representation of a AtomicValue update notification. - * - * @param <V> atomic value type - */ -public final class AtomicValueEvent<V> { - - /** - * AtomicValueEvent type. - */ - public enum Type { - - /** - * Value was updated. - */ - UPDATE, - } - - private final String name; - private final Type type; - private final V value; - - /** - * Creates a new event object. - * - * @param name AtomicValue name - * @param type the type of the event - * @param value the new value - */ - public AtomicValueEvent(String name, Type type, V value) { - this.name = name; - this.type = type; - this.value = value; - } - - /** - * Returns the AtomicValue name. - * - * @return name of atomic value - */ - public String name() { - return name; - } - - /** - * Returns the type of the event. - * - * @return the type of the event - */ - public Type type() { - return type; - } - - /** - * Returns the new updated value. - * - * @return the value - */ - public V value() { - return value; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof AtomicValueEvent)) { - return false; - } - - AtomicValueEvent that = (AtomicValueEvent) o; - return Objects.equals(this.name, that.name) && - Objects.equals(this.type, that.type) && - Objects.equals(this.value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(name, type, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("name", name) - .add("type", type) - .add("value", value) - .toString(); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEventListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEventListener.java deleted file mode 100644 index b29d903b..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/AtomicValueEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Listener to be notified about updates to a AtomicValue. - */ -public interface AtomicValueEventListener<V> { - /** - * Reacts to the specified event. - * - * @param event the event - */ - void event(AtomicValueEvent<V> event); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java deleted file mode 100644 index 289da202..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; - -/** - * A distributed, strongly consistent key-value map. - * <p> - * This map offers strong read-after-update (where update == create/update/delete) - * consistency. All operations to the map are serialized and applied in a consistent - * manner. - * <p> - * The stronger consistency comes at the expense of availability in - * the event of a network partition. A network partition can be either due to - * a temporary disruption in network connectivity between participating nodes - * or due to a node being temporarily down. - * </p><p> - * All values stored in this map are versioned and the API supports optimistic - * concurrency by allowing conditional updates that take into consideration - * the version or value that was previously read. - * </p><p> - * This map does not allow null values. All methods can throw a ConsistentMapException - * (which extends RuntimeException) to indicate failures. - * - */ -public interface ConsistentMap<K, V> { - - /** - * Returns the number of entries in the map. - * - * @return map size. - */ - int size(); - - /** - * Returns true if the map is empty. - * - * @return true if map has no entries, false otherwise - */ - boolean isEmpty(); - - /** - * Returns true if this map contains a mapping for the specified key. - * - * @param key key - * @return true if map contains key, false otherwise - */ - boolean containsKey(K key); - - /** - * Returns true if this map contains the specified value. - * - * @param value value - * @return true if map contains value, false otherwise. - */ - boolean containsValue(V value); - - /** - * Returns the value (and version) to which the specified key is mapped, or null if this - * map contains no mapping for the key. - * - * @param key the key whose associated value (and version) is to be returned - * @return the value (and version) to which the specified key is mapped, or null if - * this map contains no mapping for the key - */ - Versioned<V> get(K key); - - /** - * If the specified key is not already associated with a value (or is mapped to null), - * attempts to compute its value using the given mapping function and enters it into - * this map unless null. - * - * @param key key with which the specified value is to be associated - * @param mappingFunction the function to compute a value - * @return the current (existing or computed) value associated with the specified key, - * or null if the computed value is null. Method throws {@code ConsistentMapException.ConcurrentModification} - * if a concurrent modification of map is detected - */ - Versioned<V> computeIfAbsent(K key, - Function<? super K, ? extends V> mappingFunction); - - /** - * Attempts to compute a mapping for the specified key and its current mapped value (or - * null if there is no current mapping). - * If the computed value is null, the current mapping will be removed from the map. - * - * @param key key with which the specified value is to be associated - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or null if none. - * This method throws {@code ConsistentMapException.ConcurrentModification} - * if a concurrent modification of map is detected - */ - Versioned<V> compute(K key, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * If the value for the specified key is present and non-null, attempts to compute a new - * mapping given the key and its current mapped value. - * If the computed value is null, the current mapping will be removed from the map. - * - * @param key key with which the specified value is to be associated - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or null if none. - * This method throws {@code ConsistentMapException.ConcurrentModification} - * if a concurrent modification of map is detected - */ - Versioned<V> computeIfPresent(K key, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * If the value for the specified key satisfies a condition, attempts to compute a new - * mapping given the key and its current mapped value. - * If the computed value is null, the current mapping will be removed from the map. - * - * @param key key with which the specified value is to be associated - * @param condition condition that should evaluate to true for the computation to proceed - * @param remappingFunction the function to compute a value - * @return the new value associated with the specified key, or the old value if condition evaluates to false. - * This method throws {@code ConsistentMapException.ConcurrentModification} if a concurrent - * modification of map is detected - */ - Versioned<V> computeIf(K key, - Predicate<? super V> condition, - BiFunction<? super K, ? super V, ? extends V> remappingFunction); - - /** - * Associates the specified value with the specified key in this map (optional operation). - * If the map previously contained a mapping for the key, the old value is replaced by the - * specified value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value (and version) associated with key, or null if there was - * no mapping for key. - */ - Versioned<V> put(K key, V value); - - /** - * Associates the specified value with the specified key in this map (optional operation). - * If the map previously contained a mapping for the key, the old value is replaced by the - * specified value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return new value. - */ - Versioned<V> putAndGet(K key, V value); - - /** - * Removes the mapping for a key from this map if it is present (optional operation). - * - * @param key key whose value is to be removed from the map - * @return the value (and version) to which this map previously associated the key, - * or null if the map contained no mapping for the key. - */ - Versioned<V> remove(K key); - - /** - * Removes all of the mappings from this map (optional operation). - * The map will be empty after this call returns. - */ - void clear(); - - /** - * Returns a Set view of the keys contained in this map. - * This method differs from the behavior of java.util.Map.keySet() in that - * what is returned is a unmodifiable snapshot view of the keys in the ConsistentMap. - * Attempts to modify the returned set, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return a set of the keys contained in this map - */ - Set<K> keySet(); - - /** - * Returns the collection of values (and associated versions) contained in this map. - * This method differs from the behavior of java.util.Map.values() in that - * what is returned is a unmodifiable snapshot view of the values in the ConsistentMap. - * Attempts to modify the returned collection, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return a collection of the values (and associated versions) contained in this map - */ - Collection<Versioned<V>> values(); - - /** - * Returns the set of entries contained in this map. - * This method differs from the behavior of java.util.Map.entrySet() in that - * what is returned is a unmodifiable snapshot view of the entries in the ConsistentMap. - * Attempts to modify the returned set, whether direct or via its iterator, - * result in an UnsupportedOperationException. - * - * @return set of entries contained in this map. - */ - Set<Entry<K, Versioned<V>>> entrySet(); - - /** - * If the specified key is not already associated with a value - * associates it with the given value and returns null, else returns the current value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with the specified key or null - * if key does not already mapped to a value. - */ - Versioned<V> putIfAbsent(K key, V value); - - /** - * Removes the entry for the specified key only if it is currently - * mapped to the specified value. - * - * @param key key with which the specified value is associated - * @param value value expected to be associated with the specified key - * @return true if the value was removed - */ - boolean remove(K key, V value); - - /** - * Removes the entry for the specified key only if its current - * version in the map is equal to the specified version. - * - * @param key key with which the specified version is associated - * @param version version expected to be associated with the specified key - * @return true if the value was removed - */ - boolean remove(K key, long version); - - /** - * Replaces the entry for the specified key only if currently mapped - * to the specified value. - * - * @param key key with which the specified value is associated - * @param oldValue value expected to be associated with the specified key - * @param newValue value to be associated with the specified key - * @return true if the value was replaced - */ - boolean replace(K key, V oldValue, V newValue); - - /** - * Replaces the entry for the specified key only if it is currently mapped to the - * specified version. - * - * @param key key key with which the specified value is associated - * @param oldVersion version expected to be associated with the specified key - * @param newValue value to be associated with the specified key - * @return true if the value was replaced - */ - boolean replace(K key, long oldVersion, V newValue); - - /** - * Registers the specified listener to be notified whenever the map is updated. - * - * @param listener listener to notify about map events - */ - void addListener(MapEventListener<K, V> listener); - - /** - * Unregisters the specified listener such that it will no longer - * receive map change notifications. - * - * @param listener listener to unregister - */ - void removeListener(MapEventListener<K, V> listener); - - /** - * Returns a java.util.Map instance backed by this ConsistentMap. - * @return java.util.Map - */ - Map<K, V> asJavaMap(); -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapBuilder.java deleted file mode 100644 index 847adaf6..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapBuilder.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import org.onosproject.core.ApplicationId; - -/** - * Builder for consistent maps. - * - * @param <K> type for map key - * @param <V> type for map value - */ -public interface ConsistentMapBuilder<K, V> { - - /** - * Sets the name of the map. - * <p> - * Each consistent map is identified by a unique map name. - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the consistent map - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withName(String name); - - /** - * Sets the owner applicationId for the map. - * <p> - * Note: If {@code purgeOnUninstall} option is enabled, applicationId - * must be specified. - * </p> - * - * @param id applicationId owning the consistent map - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id); - - /** - * Sets a serializer that can be used to serialize - * both the keys and values inserted into the map. The serializer - * builder should be pre-populated with any classes that will be - * put into the map. - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param serializer serializer - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withSerializer(Serializer serializer); - - /** - * Disables distribution of map entries across multiple database partitions. - * <p> - * When partitioning is disabled, the returned map will have a single partition - * that spans the entire cluster. Furthermore, the changes made to the map are - * ephemeral and do not survive a full cluster restart. - * </p> - * <p> - * Disabling partitions is more appropriate when the returned map is used for - * coordination activities such as leader election and not for long term data persistence. - * </p> - * <p> - * Note: By default partitions are enabled and entries in the map are durable. - * </p> - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withPartitionsDisabled(); - - /** - * Disables map updates. - * <p> - * Attempt to update the built map will throw {@code UnsupportedOperationException}. - * - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withUpdatesDisabled(); - - /** - * Purges map contents when the application owning the map is uninstalled. - * <p> - * When this option is enabled, the caller must provide a applicationId via - * the {@code withAppliationId} builder method. - * <p> - * By default map entries will NOT be purged when owning application is uninstalled. - * - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withPurgeOnUninstall(); - - /** - * Instantiates Metering service to gather usage and performance metrics. - * By default, usage data will be stored. - * - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withMeteringDisabled(); - - /** - * Provides weak consistency for map gets. - * <p> - * While this can lead to improved read performance, it can also make the behavior - * heard to reason. Only turn this on if you know what you are doing. By default - * reads are strongly consistent. - * - * @return this ConsistentMapBuilder - */ - ConsistentMapBuilder<K, V> withRelaxedReadConsistency(); - - /** - * Builds an consistent map based on the configuration options - * supplied to this builder. - * - * @return new consistent map - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - ConsistentMap<K, V> build(); - - /** - * Builds an async consistent map based on the configuration options - * supplied to this builder. - * - * @return new async consistent map - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - AsyncConsistentMap<K, V> buildAsyncMap(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapException.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapException.java deleted file mode 100644 index 94ed649f..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/ConsistentMapException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -/** - * Top level exception for ConsistentMap failures. - */ -@SuppressWarnings("serial") -public class ConsistentMapException extends StorageException { - public ConsistentMapException() { - } - - public ConsistentMapException(Throwable t) { - super(t); - } - - /** - * ConsistentMap operation timeout. - */ - public static class Timeout extends ConsistentMapException { - } - - /** - * ConsistentMap update conflicts with an in flight transaction. - */ - public static class ConcurrentModification extends ConsistentMapException { - } - - /** - * ConsistentMap operation interrupted. - */ - public static class Interrupted extends ConsistentMapException { - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DatabaseUpdate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DatabaseUpdate.java deleted file mode 100644 index a62d3823..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DatabaseUpdate.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import com.google.common.base.MoreObjects; - -/** - * Database update operation. - * - */ -public final class DatabaseUpdate { - - /** - * Type of database update operation. - */ - public enum Type { - /** - * Insert/Update entry without any checks. - */ - PUT, - /** - * Insert an entry iff there is no existing entry for that key. - */ - PUT_IF_ABSENT, - - /** - * Update entry if the current version matches specified version. - */ - PUT_IF_VERSION_MATCH, - - /** - * Update entry if the current value matches specified value. - */ - PUT_IF_VALUE_MATCH, - - /** - * Remove entry without any checks. - */ - REMOVE, - - /** - * Remove entry if the current version matches specified version. - */ - REMOVE_IF_VERSION_MATCH, - - /** - * Remove entry if the current value matches specified value. - */ - REMOVE_IF_VALUE_MATCH, - } - - private Type type; - private String mapName; - private String key; - private byte[] value; - private byte[] currentValue; - private long currentVersion = -1; - - /** - * Returns the type of update operation. - * @return type of update. - */ - public Type type() { - return type; - } - - /** - * Returns the name of map being updated. - * @return map name. - */ - public String mapName() { - return mapName; - } - - /** - * Returns the item key being updated. - * @return item key - */ - public String key() { - return key; - } - - /** - * Returns the new value. - * @return item's target value. - */ - public byte[] value() { - return value; - } - - /** - * Returns the expected current value in the database value for the key. - * @return current value in database. - */ - public byte[] currentValue() { - return currentValue; - } - - /** - * Returns the expected current version in the database for the key. - * @return expected version. - */ - public long currentVersion() { - return currentVersion; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("type", type) - .add("mapName", mapName) - .add("key", key) - .add("value", value) - .add("currentValue", currentValue) - .add("currentVersion", currentVersion) - .toString(); - } - - /** - * Creates a new builder instance. - * - * @return builder. - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** - * DatabaseUpdate builder. - * - */ - public static final class Builder { - - private DatabaseUpdate update = new DatabaseUpdate(); - - public DatabaseUpdate build() { - validateInputs(); - return update; - } - - public Builder withType(Type type) { - update.type = checkNotNull(type, "type cannot be null"); - return this; - } - - public Builder withMapName(String mapName) { - update.mapName = checkNotNull(mapName, "mapName cannot be null"); - return this; - } - - public Builder withKey(String key) { - update.key = checkNotNull(key, "key cannot be null"); - return this; - } - - public Builder withCurrentValue(byte[] value) { - update.currentValue = checkNotNull(value, "currentValue cannot be null"); - return this; - } - - public Builder withValue(byte[] value) { - update.value = checkNotNull(value, "value cannot be null"); - return this; - } - - public Builder withCurrentVersion(long version) { - checkArgument(version >= 0, "version cannot be negative"); - update.currentVersion = version; - return this; - } - - private void validateInputs() { - checkNotNull(update.type, "type must be specified"); - checkNotNull(update.mapName, "map name must be specified"); - checkNotNull(update.key, "key must be specified"); - switch (update.type) { - case PUT: - case PUT_IF_ABSENT: - checkNotNull(update.value, "value must be specified."); - break; - case PUT_IF_VERSION_MATCH: - checkNotNull(update.value, "value must be specified."); - checkState(update.currentVersion >= 0, "current version must be specified"); - break; - case PUT_IF_VALUE_MATCH: - checkNotNull(update.value, "value must be specified."); - checkNotNull(update.currentValue, "currentValue must be specified."); - break; - case REMOVE: - break; - case REMOVE_IF_VERSION_MATCH: - checkState(update.currentVersion >= 0, "current version must be specified"); - break; - case REMOVE_IF_VALUE_MATCH: - checkNotNull(update.currentValue, "currentValue must be specified."); - break; - default: - throw new IllegalStateException("Unknown operation type"); - } - } - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java deleted file mode 100644 index cc0b00d3..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.concurrent.CompletableFuture; - -/** - * A distributed collection designed for holding elements prior to processing. - * A queue provides insertion, extraction and inspection operations. The extraction operation - * is designed to be non-blocking. - * - * @param <E> queue entry type - */ -public interface DistributedQueue<E> { - - /** - * Returns total number of entries in the queue. - * @return queue size - */ - long size(); - - /** - * Returns true if queue has elements in it. - * @return true is queue has elements, false otherwise - */ - default boolean isEmpty() { - return size() == 0; - } - - /** - * Inserts an entry into the queue. - * @param entry entry to insert - */ - void push(E entry); - - /** - * If the queue is non-empty, an entry will be removed from the queue and the returned future - * will be immediately completed with it. If queue is empty when this call is made, the returned - * future will be eventually completed when an entry is added to the queue. - * @return queue entry - */ - CompletableFuture<E> pop(); - - /** - * Returns an entry from the queue without removing it. If the queue is empty returns null. - * @return queue entry or null if queue is empty - */ - E peek(); -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueueBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueueBuilder.java deleted file mode 100644 index 646dc28c..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedQueueBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Builder for distributed queue. - * - * @param <E> type queue elements. - */ -public interface DistributedQueueBuilder<E> { - - /** - * Sets the name of the queue. - * <p> - * Each queue is identified by a unique name. - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the queue - * @return this DistributedQueueBuilder for method chaining - */ - DistributedQueueBuilder<E> withName(String name); - - /** - * Sets a serializer that can be used to serialize - * the elements pushed into the queue. The serializer - * builder should be pre-populated with any classes that will be - * put into the queue. - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param serializer serializer - * @return this DistributedQueueBuilder for method chaining - */ - DistributedQueueBuilder<E> withSerializer(Serializer serializer); - - /** - * - * - * @return this DistributedQueueBuilder for method chaining - */ - DistributedQueueBuilder<E> withMeteringDisabled(); - - - /** - * Disables persistence of queues entries. - * <p> - * When persistence is disabled, a full cluster restart will wipe out all - * queue entries. - * </p> - * @return this DistributedQueueBuilder for method chaining - */ - DistributedQueueBuilder<E> withPersistenceDisabled(); - - /** - * Builds a queue based on the configuration options - * supplied to this builder. - * - * @return new distributed queue - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - DistributedQueue<E> build(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java deleted file mode 100644 index 460206ec..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Set; - -/** - * A distributed collection designed for holding unique elements. - * - * @param <E> set entry type - */ -public interface DistributedSet<E> extends Set<E> { - - /** - * Registers the specified listener to be notified whenever - * the set is updated. - * - * @param listener listener to notify about set update events - */ - void addListener(SetEventListener<E> listener); - - /** - * Unregisters the specified listener. - * - * @param listener listener to unregister. - */ - void removeListener(SetEventListener<E> listener); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java deleted file mode 100644 index f5a44c93..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import org.onosproject.core.ApplicationId; - -/** - * Builder for distributed set. - * - * @param <E> type set elements. - */ -public interface DistributedSetBuilder<E> { - - /** - * Sets the name of the set. - * <p> - * Each set is identified by a unique name. - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the set - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withName(String name); - - /** - * Sets the owner applicationId for the set. - * <p> - * Note: If {@code purgeOnUninstall} option is enabled, applicationId - * must be specified. - * </p> - * - * @param id applicationId owning the set - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withApplicationId(ApplicationId id); - - /** - * Sets a serializer that can be used to serialize - * the elements add to the set. The serializer - * builder should be pre-populated with any classes that will be - * put into the set. - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param serializer serializer - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withSerializer(Serializer serializer); - - /** - * Disables set updates. - * <p> - * Attempt to update the built set will throw {@code UnsupportedOperationException}. - * - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withUpdatesDisabled(); - - /** - * Provides weak consistency for set reads. - * <p> - * While this can lead to improved read performance, it can also make the behavior - * heard to reason. Only turn this on if you know what you are doing. By default - * reads are strongly consistent. - * - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withRelaxedReadConsistency(); - - /** - * Disables distribution of set entries across multiple database partitions. - * <p> - * When partitioning is disabled, the returned set will have a single partition - * that spans the entire cluster. Furthermore, the changes made to the set are - * ephemeral and do not survive a full cluster restart. - * </p> - * <p> - * Disabling partitions is more appropriate when the returned set is used for - * simple coordination activities and not for long term data persistence. - * </p> - * <p> - * Note: By default partitions are enabled and entries in the set are durable. - * </p> - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withPartitionsDisabled(); - - /** - * Instantiate Metrics service to gather usage and performance metrics. - * By default usage information is enabled - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withMeteringDisabled(); - - /** - * Purges set contents when the application owning the set is uninstalled. - * <p> - * When this option is enabled, the caller must provide a applicationId via - * the {@code withAppliationId} builder method. - * <p> - * By default set contents will NOT be purged when owning application is uninstalled. - * - * @return this DistributedSetBuilder - */ - DistributedSetBuilder<E> withPurgeOnUninstall(); - - /** - * Builds an set based on the configuration options - * supplied to this builder. - * - * @return new set - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - DistributedSet<E> build(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java deleted file mode 100644 index 06395b8e..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.function.BiFunction; - -/** - * A distributed, eventually consistent map. - * <p> - * This map does not offer read after writes consistency. Operations are - * serialized via the timestamps issued by the clock service. If two updates - * are in conflict, the update with the more recent timestamp will endure. - * </p><p> - * The interface is mostly similar to {@link java.util.Map} with some minor - * semantic changes and the addition of a listener framework (because the map - * can be mutated by clients on other instances, not only through the local Java - * API). - * </p><p> - * Clients are expected to register an - * {@link EventuallyConsistentMapListener} if they - * are interested in receiving notifications of update to the map. - * </p><p> - * Null values are not allowed in this map. - * </p> - */ -public interface EventuallyConsistentMap<K, V> { - - /** - * Returns the number of key-value mappings in this map. - * - * @return number of key-value mappings - */ - int size(); - - /** - * Returns true if this map is empty. - * - * @return true if this map is empty, otherwise false - */ - boolean isEmpty(); - - /** - * Returns true if the map contains a mapping for the specified key. - * - * @param key the key to check if this map contains - * @return true if this map has a mapping for the key, otherwise false - */ - boolean containsKey(K key); - - /** - * Returns true if the map contains a mapping from any key to the specified - * value. - * - * @param value the value to check if this map has a mapping for - * @return true if this map has a mapping to this value, otherwise false - */ - boolean containsValue(V value); - - /** - * Returns the value mapped to the specified key. - * - * @param key the key to look up in this map - * @return the value mapped to the key, or null if no mapping is found - */ - V get(K key); - - /** - * Associates the specified value to the specified key in this map. - * <p> - * Note: this differs from the specification of {@link java.util.Map} - * because it does not return the previous value associated with the key. - * Clients are expected to register an - * {@link EventuallyConsistentMapListener} if - * they are interested in receiving notification of updates to the map. - * </p><p> - * Null values are not allowed in the map. - * </p> - * - * @param key the key to add a mapping for in this map - * @param value the value to associate with the key in this map - */ - void put(K key, V value); - - /** - * Removes the mapping associated with the specified key from the map. - * <p> - * Clients are expected to register an {@link EventuallyConsistentMapListener} if - * they are interested in receiving notification of updates to the map. - * </p> - * - * @param key the key to remove the mapping for - * @return previous value associated with key, or null if there was no mapping for key. - */ - V remove(K key); - - /** - * Removes the given key-value mapping from the map, if it exists. - * <p> - * This actually means remove any values up to and including the timestamp - * given by the map's timestampProvider. - * Any mappings that produce an earlier timestamp than this given key-value - * pair will be removed, and any mappings that produce a later timestamp - * will supersede this remove. - * </p><p> - * Note: this differs from the specification of {@link java.util.Map} - * because it does not return a boolean indication whether a value was removed. - * Clients are expected to register an - * {@link EventuallyConsistentMapListener} if - * they are interested in receiving notification of updates to the map. - * </p> - * - * @param key the key to remove the mapping for - * @param value the value mapped to the key - */ - void remove(K key, V value); - - /** - * Attempts to compute a mapping for the specified key and its current mapped - * value (or null if there is no current mapping). - * <p> - * If the function returns null, the mapping is removed (or remains absent if initially absent). - * @param key map key - * @param recomputeFunction function to recompute a new value - * @return new value - */ - V compute(K key, BiFunction<K, V, V> recomputeFunction); - - /** - * Adds mappings for all key-value pairs in the specified map to this map. - * <p> - * This will be more efficient in communication than calling individual put - * operations. - * </p> - * - * @param m a map of values to add to this map - */ - void putAll(Map<? extends K, ? extends V> m); - - /** - * Removes all mappings from this map. - */ - void clear(); - - /** - * Returns a set of the keys in this map. Changes to the set are not - * reflected back to the map. - * - * @return set of keys in the map - */ - Set<K> keySet(); - - /** - * Returns a collections of values in this map. Changes to the collection - * are not reflected back to the map. - * - * @return collection of values in the map - */ - Collection<V> values(); - - /** - * Returns a set of mappings contained in this map. Changes to the set are - * not reflected back to the map. - * - * @return set of key-value mappings in this map - */ - Set<Map.Entry<K, V>> entrySet(); - - /** - * Adds the specified listener to the map which will be notified whenever - * the mappings in the map are changed. - * - * @param listener listener to register for events - */ - void addListener(EventuallyConsistentMapListener<K, V> listener); - - /** - * Removes the specified listener from the map such that it will no longer - * receive change notifications. - * - * @param listener listener to deregister for events - */ - void removeListener(EventuallyConsistentMapListener<K, V> listener); - - /** - * Shuts down the map and breaks communication between different instances. - * This allows the map objects to be cleaned up and garbage collected. - * Calls to any methods on the map subsequent to calling destroy() will - * throw a {@link java.lang.RuntimeException}. - */ - void destroy(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapBuilder.java deleted file mode 100644 index 9471321c..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapBuilder.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import org.onlab.util.KryoNamespace; -import org.onosproject.cluster.NodeId; -import org.onosproject.store.Timestamp; - -import java.util.Collection; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.function.BiFunction; - -/** - * Builder for eventually consistent maps. - * - * @param <K> type for map keys - * @param <V> type for map values - */ -public interface EventuallyConsistentMapBuilder<K, V> { - - /** - * Sets the name of the map. - * <p> - * Each map is identified by a string map name. EventuallyConsistentMapImpl - * objects in different JVMs that use the same map name will form a - * distributed map across JVMs (provided the cluster service is aware of - * both nodes). - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param name name of the map - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withName(String name); - - /** - * Sets a serializer builder that can be used to create a serializer that - * can serialize both the keys and values put into the map. The serializer - * builder should be pre-populated with any classes that will be put into - * the map. - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param serializerBuilder serializer builder - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withSerializer( - KryoNamespace.Builder serializerBuilder); - - /** - * Sets the function to use for generating timestamps for map updates. - * <p> - * The client must provide an {@code BiFunction<K, V, Timestamp>} - * which can generate timestamps for a given key. The function is free - * to generate timestamps however it wishes, however these timestamps will - * be used to serialize updates to the map so they must be strict enough - * to ensure updates are properly ordered for the use case (i.e. in some - * cases wallclock time will suffice, whereas in other cases logical time - * will be necessary). - * </p> - * <p> - * Note: This is a mandatory parameter. - * </p> - * - * @param timestampProvider provides a new timestamp - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withTimestampProvider( - BiFunction<K, V, Timestamp> timestampProvider); - - /** - * Sets the executor to use for processing events coming in from peers. - * - * @param executor event executor - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withEventExecutor( - ExecutorService executor); - - /** - * Sets the executor to use for sending events to peers. - * - * @param executor event executor - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withCommunicationExecutor( - ExecutorService executor); - - /** - * Sets the executor to use for background anti-entropy tasks. - * - * @param executor event executor - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withBackgroundExecutor( - ScheduledExecutorService executor); - - /** - * Sets a function that can determine which peers to replicate updates to. - * <p> - * The default function replicates to all nodes. - * </p> - * - * @param peerUpdateFunction function that takes a K, V input and returns - * a collection of NodeIds to replicate the event - * to - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withPeerUpdateFunction( - BiFunction<K, V, Collection<NodeId>> peerUpdateFunction); - - /** - * Prevents this map from writing tombstones of items that have been - * removed. This may result in zombie items reappearing after they have - * been removed. - * <p> - * The default behavior is tombstones are enabled. - * </p> - * - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withTombstonesDisabled(); - - /** - * Configures how often to run the anti-entropy background task. - * <p> - * The default anti-entropy period is 5 seconds. - * </p> - * - * @param period anti-entropy period - * @param unit time unit for the period - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withAntiEntropyPeriod( - long period, TimeUnit unit); - - /** - * Configure anti-entropy to converge faster at the cost of doing more work - * for each anti-entropy cycle. Suited to maps with low update rate where - * convergence time is more important than throughput. - * <p> - * The default behavior is to do less anti-entropy work at the cost of - * slower convergence. - * </p> - * - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withFasterConvergence(); - - /** - * Configure the map to persist data to disk. - * <p> - * The default behavior is no persistence - * </p> - * - * @return this EventuallyConsistentMapBuilder - */ - EventuallyConsistentMapBuilder<K, V> withPersistence(); - - /** - * Builds an eventually consistent map based on the configuration options - * supplied to this builder. - * - * @return new eventually consistent map - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - EventuallyConsistentMap<K, V> build(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapEvent.java deleted file mode 100644 index 5814534e..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapEvent.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import com.google.common.base.MoreObjects; - -import java.util.Objects; - -/** - * Representation of a EventuallyConsistentMap update notification. - */ -public final class EventuallyConsistentMapEvent<K, V> { - - public enum Type { - /** - * Entry added to map or existing entry updated. - */ - PUT, - - /** - * Entry removed from map. - */ - REMOVE - } - - private final String name; - private final Type type; - private final K key; - private final V value; - - /** - * Creates a new event object. - * - * @param name map name - * @param type the type of the event - * @param key the key the event concerns - * @param value the value mapped to the key - */ - public EventuallyConsistentMapEvent(String name, Type type, K key, V value) { - this.name = name; - this.type = type; - this.key = key; - this.value = value; - } - - /** - * Returns the map name. - * - * @return name of map - */ - public String name() { - return name; - } - - /** - * Returns the type of the event. - * - * @return the type of the event - */ - public Type type() { - return type; - } - - /** - * Returns the key this event concerns. - * - * @return the key - */ - public K key() { - return key; - } - - /** - * Returns the value associated with this event. If type is REMOVE, - * this is the value that was removed. If type is PUT, this is - * the new value. - * - * @return the value - */ - public V value() { - return value; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof EventuallyConsistentMapEvent)) { - return false; - } - - EventuallyConsistentMapEvent that = (EventuallyConsistentMapEvent) o; - return Objects.equals(this.type, that.type) && - Objects.equals(this.key, that.key) && - Objects.equals(this.value, that.value) && - Objects.equals(this.name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(type, key, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("name", name) - .add("type", type) - .add("key", key) - .add("value", value) - .toString(); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapListener.java deleted file mode 100644 index b2399a48..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMapListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Listener to be notified about updates to a EventuallyConsistentMap. - */ -public interface EventuallyConsistentMapListener<K, V> { - - /** - * Reacts to the specified event. - * - * @param event the event - */ - void event(EventuallyConsistentMapEvent<K, V> event); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/LogicalClockService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/LogicalClockService.java deleted file mode 100644 index 7592b126..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/LogicalClockService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import org.onosproject.store.Timestamp; - -/** - * Service that issues logical timestamps. - * <p> - * Logical timestamps are useful for establishing a total ordering of - * arbitrary cluster wide events without relying on a fully synchronized - * system clock (wall clock) - */ -public interface LogicalClockService { - - /** - * Generates a new logical timestamp. - * - * @return timestamp - */ - Timestamp getTimestamp(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEvent.java deleted file mode 100644 index 6e671351..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEvent.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Objects; - -import com.google.common.base.MoreObjects; - -/** - * Representation of a ConsistentMap update notification. - * - * @param <K> key type - * @param <V> value type - */ -public class MapEvent<K, V> { - - /** - * MapEvent type. - */ - public enum Type { - /** - * Entry inserted into the map. - */ - INSERT, - - /** - * Existing map entry updated. - */ - UPDATE, - - /** - * Entry removed from map. - */ - REMOVE - } - - private final String name; - private final Type type; - private final K key; - private final Versioned<V> value; - - /** - * Creates a new event object. - * - * @param name map name - * @param type type of event - * @param key key the event concerns - * @param value value key is mapped to - */ - public MapEvent(String name, Type type, K key, Versioned<V> value) { - this.name = name; - this.type = type; - this.key = key; - this.value = value; - } - - /** - * Returns the map name. - * - * @return name of map - */ - public String name() { - return name; - } - - /** - * Returns the type of the event. - * - * @return the type of event - */ - public Type type() { - return type; - } - - /** - * Returns the key this event concerns. - * - * @return the key - */ - public K key() { - return key; - } - - /** - * Returns the value associated with this event. If type is REMOVE, - * this is the value that was removed. If type is INSERT/UPDATE, this is - * the new value. - * - * @return the value - */ - public Versioned<V> value() { - return value; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof MapEvent)) { - return false; - } - - MapEvent<K, V> that = (MapEvent) o; - return Objects.equals(this.name, that.name) && - Objects.equals(this.type, that.type) && - Objects.equals(this.key, that.key) && - Objects.equals(this.value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(name, type, key, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("name", name) - .add("type", type) - .add("key", key) - .add("value", value) - .toString(); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEventListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEventListener.java deleted file mode 100644 index 359f4653..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Listener to be notified about updates to a ConsistentMap. - */ -public interface MapEventListener<K, V> { - /** - * Reacts to the specified event. - * - * @param event the event - */ - void event(MapEvent<K, V> event); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapInfo.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapInfo.java deleted file mode 100644 index 5db17049..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MapInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Metadata information for a consistent map. - */ -public class MapInfo { - private final String name; - private final int size; - - public MapInfo(String name, int size) { - this.name = name; - this.size = size; - } - - /** - * Returns the name of the map. - * - * @return map name - */ - public String name() { - return name; - } - - /** - * Returns the number of entries in the map. - * - * @return map size - */ - public int size() { - return size; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MultiValuedTimestamp.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MultiValuedTimestamp.java deleted file mode 100644 index e068b8e9..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MultiValuedTimestamp.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import com.google.common.base.MoreObjects; -import com.google.common.collect.ComparisonChain; -import org.onosproject.store.Timestamp; - -import java.util.Objects; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * A logical timestamp that derives its value from two input values. The first - * value always takes precedence over the second value when comparing timestamps. - */ -public class MultiValuedTimestamp<T extends Comparable<T>, U extends Comparable<U>> - implements Timestamp { - - private final T value1; - private final U value2; - - /** - * Creates a new timestamp based on two values. The first value has higher - * precedence than the second when comparing timestamps. - * - * @param value1 first value - * @param value2 second value - */ - public MultiValuedTimestamp(T value1, U value2) { - this.value1 = checkNotNull(value1); - this.value2 = checkNotNull(value2); - } - - @Override - public int compareTo(Timestamp o) { - checkArgument(o instanceof MultiValuedTimestamp, - "Must be MultiValuedTimestamp", o); - MultiValuedTimestamp that = (MultiValuedTimestamp) o; - - return ComparisonChain.start() - .compare(this.value1, that.value1) - .compare(this.value2, that.value2) - .result(); - } - - @Override - public int hashCode() { - return Objects.hash(value1, value2); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof MultiValuedTimestamp)) { - return false; - } - MultiValuedTimestamp that = (MultiValuedTimestamp) obj; - return Objects.equals(this.value1, that.value1) && - Objects.equals(this.value2, that.value2); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("value1", value1) - .add("value2", value2) - .toString(); - } - - /** - * Returns the first value. - * - * @return first value - */ - public T value1() { - return value1; - } - - /** - * Returns the second value. - * - * @return second value - */ - public U value2() { - return value2; - } - - // Default constructor for serialization - @SuppressWarnings("unused") - private MultiValuedTimestamp() { - this.value1 = null; - this.value2 = null; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexExecutionService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexExecutionService.java deleted file mode 100644 index d05f3b91..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexExecutionService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/** - * Service for mutually exclusive job execution. - */ -public interface MutexExecutionService { - - /** - * Runs the specified task in a mutually exclusive fashion. - * @param task task to run - * @param exclusionPath path on which different instances synchronize - * @param executor executor to use for running the task - * @return future that is completed when the task execution completes. - */ - CompletableFuture<Void> execute(MutexTask task, String exclusionPath, Executor executor); -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexTask.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexTask.java deleted file mode 100644 index ba5ee47f..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/MutexTask.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * The MutexTask interface should be implemented by any class whose - * instances distributed across controllers are intended to be executed - * in a mutually exclusive fashion. - */ -public interface MutexTask { - - /** - * Begins the execution of a mutually exclusive task. - * The start method will be called once the "lock" is acquired. - * After the start method returns the lock is released and some other - * instance can take over execution. - */ - void start(); - - /** - * This method will be called when exclusivity of task execution - * can no longer be guaranteed. The implementation should take necessary steps - * to halt task execution in order to ensure correctness. - */ - void stop(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/PartitionInfo.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/PartitionInfo.java deleted file mode 100644 index a0f06481..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/PartitionInfo.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import com.google.common.collect.ImmutableList; - -import java.util.List; - -/** - * Contains information about a database partition. - */ -public class PartitionInfo { - private final String name; - private final long term; - private final List<String> members; - private final String leader; - - /** - * Class constructor. - * - * @param name partition name - * @param term term number - * @param members partition members - * @param leader leader name - */ - public PartitionInfo(String name, long term, List<String> members, String leader) { - this.name = name; - this.term = term; - this.members = ImmutableList.copyOf(members); - this.leader = leader; - } - - /** - * Returns the name of the partition. - * - * @return partition name - */ - public String name() { - return name; - } - - /** - * Returns the term number. - * - * @return term number - */ - public long term() { - return term; - } - - /** - * Returns the list of partition members. - * - * @return partition members - */ - public List<String> members() { - return members; - } - - /** - * Returns the partition leader. - * - * @return partition leader - */ - public String leader() { - return leader; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Serializer.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Serializer.java deleted file mode 100644 index 6245175f..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Serializer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import java.util.Arrays; -import java.util.List; - -import org.onlab.util.KryoNamespace; - -import com.google.common.collect.Lists; - -/** - * Interface for serialization of store artifacts. - */ -public interface Serializer { - /** - * Serialize the specified object. - * @param object object to serialize. - * @return serialized bytes. - * @param <T> encoded type - */ - <T> byte[] encode(T object); - - /** - * Deserialize the specified bytes. - * @param bytes byte array to deserialize. - * @return deserialized object. - * @param <T> decoded type - */ - <T> T decode(byte[] bytes); - - /** - * Creates a new Serializer instance from a KryoNamespace. - * - * @param kryo kryo namespace - * @return Serializer instance - */ - static Serializer using(KryoNamespace kryo) { - return using(Arrays.asList(kryo)); - } - - static Serializer using(List<KryoNamespace> namespaces, Class<?>... classes) { - KryoNamespace.Builder builder = new KryoNamespace.Builder(); - namespaces.forEach(builder::register); - Lists.newArrayList(classes).forEach(builder::register); - builder.register(MapEvent.class, MapEvent.Type.class, Versioned.class); - KryoNamespace namespace = builder.build(); - return new Serializer() { - @Override - public <T> byte[] encode(T object) { - return namespace.serialize(object); - } - - @Override - public <T> T decode(byte[] bytes) { - return namespace.deserialize(bytes); - } - }; - } - - static Serializer forTypes(Class<?>... classes) { - return using(KryoNamespace.newBuilder() - .register(classes) - .register(MapEvent.class, MapEvent.Type.class) - .build()); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEvent.java deleted file mode 100644 index a869e722..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEvent.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Objects; - -import com.google.common.base.MoreObjects; - -/** - * Representation of a DistributedSet update notification. - * - * @param <E> set element type - */ -public final class SetEvent<E> { - - /** - * SetEvent type. - */ - public enum Type { - /** - * Entry added to the set. - */ - ADD, - - /** - * Entry removed from the set. - */ - REMOVE - } - - private final String name; - private final Type type; - private final E entry; - - /** - * Creates a new event object. - * - * @param name set name - * @param type type of the event - * @param entry entry the event concerns - */ - public SetEvent(String name, Type type, E entry) { - this.name = name; - this.type = type; - this.entry = entry; - } - - /** - * Returns the set name. - * - * @return name of set - */ - public String name() { - return name; - } - - /** - * Returns the type of the event. - * - * @return type of the event - */ - public Type type() { - return type; - } - - /** - * Returns the entry this event concerns. - * - * @return the entry - */ - public E entry() { - return entry; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof SetEvent)) { - return false; - } - - SetEvent that = (SetEvent) o; - return Objects.equals(this.name, that.name) && - Objects.equals(this.type, that.type) && - Objects.equals(this.entry, that.entry); - } - - @Override - public int hashCode() { - return Objects.hash(name, type, entry); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("name", name) - .add("type", type) - .add("entry", entry) - .toString(); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEventListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEventListener.java deleted file mode 100644 index a64994ef..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/SetEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Listener to be notified about updates to a DistributedSet. - */ -public interface SetEventListener<E> { - /** - * Reacts to the specified event. - * - * @param event the event - */ - void event(SetEvent<E> event); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java deleted file mode 100644 index 22591044..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * Service for administering storage instances. - */ -public interface StorageAdminService { - - /** - * Returns information about all partitions in the system. - * - * @return list of partition information - */ - List<PartitionInfo> getPartitionInfo(); - - /** - * Returns information about all the consistent maps in the system. - * - * @return list of map information - */ - List<MapInfo> getMapInfo(); - - /** - * Returns information about all the atomic counters in the system. - * If 2 counters belonging to 2 different databases have the same name, - * then only one counter from one database is returned. - * - * @return mapping from counter name to that counter's next value - */ - Map<String, Long> getCounters(); - - /** - * Returns information about all the atomic partitioned database counters in the system. - * - * @return mapping from counter name to that counter's next value - */ - Map<String, Long> getPartitionedDatabaseCounters(); - - /** - * Returns information about all the atomic in-memory database counters in the system. - * - * @return mapping from counter name to that counter's next value - */ - Map<String, Long> getInMemoryDatabaseCounters(); - - /** - * Returns all the transactions in the system. - * - * @return collection of transactions - */ - Collection<Transaction> getTransactions(); - - /** - * Redrives stuck transactions while removing those that are done. - */ - void redriveTransactions(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageException.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageException.java deleted file mode 100644 index a66fc3ed..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -/** - * Top level exception for Store failures. - */ -@SuppressWarnings("serial") -public class StorageException extends RuntimeException { - public StorageException() { - } - - public StorageException(Throwable t) { - super(t); - } - - /** - * Store operation timeout. - */ - public static class Timeout extends StorageException { - } - - /** - * Store update conflicts with an in flight transaction. - */ - public static class ConcurrentModification extends StorageException { - } - - /** - * Store operation interrupted. - */ - public static class Interrupted extends StorageException { - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageService.java deleted file mode 100644 index f6b411d3..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/StorageService.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Storage service. - * <p> - * This service provides builders for various distributed primitives. - * <p> - * It is expected that services and applications will leverage the primitives indirectly provided by - * this service for their distributed state management and coordination. - */ -public interface StorageService { - - /** - * Creates a new EventuallyConsistentMapBuilder. - * - * @param <K> key type - * @param <V> value type - * @return builder for an eventually consistent map - */ - <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder(); - - /** - * Creates a new ConsistentMapBuilder. - * - * @param <K> key type - * @param <V> value type - * @return builder for a consistent map - */ - <K, V> ConsistentMapBuilder<K, V> consistentMapBuilder(); - - /** - * Creates a new DistributedSetBuilder. - * - * @param <E> set element type - * @return builder for an distributed set - */ - <E> DistributedSetBuilder<E> setBuilder(); - - /** - * Creates a new DistributedQueueBuilder. - * - * @param <E> queue entry type - * @return builder for an distributed queue - */ - <E> DistributedQueueBuilder<E> queueBuilder(); - - /** - * Creates a new AtomicCounterBuilder. - * - * @return atomic counter builder - */ - AtomicCounterBuilder atomicCounterBuilder(); - - /** - * Creates a new AtomicValueBuilder. - * - * @param <V> atomic value type - * @return atomic value builder - */ - <V> AtomicValueBuilder<V> atomicValueBuilder(); - - /** - * Creates a new transaction context builder. - * - * @return a builder for a transaction context. - */ - TransactionContextBuilder transactionContextBuilder(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Transaction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Transaction.java deleted file mode 100644 index 330d8468..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Transaction.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import java.util.List; - -/** - * An immutable transaction object. - */ -public interface Transaction { - - enum State { - /** - * Indicates a new transaction that is about to be prepared. All transactions - * start their life in this state. - */ - PREPARING, - - /** - * Indicates a transaction that is successfully prepared i.e. all participants voted to commit - */ - PREPARED, - - /** - * Indicates a transaction that is about to be committed. - */ - COMMITTING, - - /** - * Indicates a transaction that has successfully committed. - */ - COMMITTED, - - /** - * Indicates a transaction that is about to be rolled back. - */ - ROLLINGBACK, - - /** - * Indicates a transaction that has been rolled back and all locks are released. - */ - ROLLEDBACK - } - - /** - * Returns the transaction Id. - * - * @return transaction id - */ - long id(); - - /** - * Returns the list of updates that are part of this transaction. - * - * @return list of database updates - */ - List<DatabaseUpdate> updates(); - - /** - * Returns the current state of this transaction. - * - * @return transaction state - */ - State state(); - - /** - * Returns true if this transaction has completed execution. - * - * @return true is yes, false otherwise - */ - default boolean isDone() { - return state() == State.COMMITTED || state() == State.ROLLEDBACK; - } - - /** - * Returns a new transaction that is created by transitioning this one to the specified state. - * - * @param newState destination state - * @return a new transaction instance similar to the current one but its state set to specified state - */ - Transaction transition(State newState); - - /** - * Returns the system time when the transaction was last updated. - * - * @return last update time - */ - long lastUpdated(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java deleted file mode 100644 index ef972536..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -/** - * Provides a context for transactional operations. - * <p> - * A transaction context is a vehicle for grouping operations into a unit with the - * properties of atomicity, isolation, and durability. Transactions also provide the - * ability to maintain an application's invariants or integrity constraints, - * supporting the property of consistency. Together these properties are known as ACID. - * <p> - * A transaction context provides a boundary within which transactions - * are run. It also is a place where all modifications made within a transaction - * are cached until the point when the transaction commits or aborts. It thus ensures - * isolation of work happening with in the transaction boundary. Within a transaction - * context isolation level is REPEATABLE_READS i.e. only data that is committed can be read. - * The only uncommitted data that can be read is the data modified by the current transaction. - */ -public interface TransactionContext { - - /** - * Returns the unique transactionId. - * - * @return transaction id - */ - long transactionId(); - - /** - * Returns if this transaction context is open. - * - * @return true if open, false otherwise - */ - boolean isOpen(); - - /** - * Starts a new transaction. - */ - void begin(); - - /** - * Commits a transaction that was previously started thereby making its changes permanent - * and externally visible. - * - * @return true if this transaction succeeded, otherwise false. - */ - boolean commit(); - - /** - * Aborts any changes made in this transaction context and discarding all locally cached updates. - */ - void abort(); - - /** - * Returns a transactional map data structure with the specified name. - * - * @param <K> key type - * @param <V> value type - * @param mapName name of the transactional map - * @param serializer serializer to use for encoding/decoding keys and values of the map - * @return Transactional Map - */ - <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContextBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContextBuilder.java deleted file mode 100644 index e9f3a020..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContextBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -/** - * Interface definition for a transaction context builder. - */ -public interface TransactionContextBuilder { - - /** - * Disables distribution of map entries across multiple database partitions. - * <p> - * When partitioning is disabled, the returned map will have a single - * partition that spans the entire cluster. Furthermore, the changes made to - * the map are ephemeral and do not survive a full cluster restart. - * </p> - * <p> - * Note: By default, partitions are enabled. This feature is intended to - * simplify debugging. - * </p> - * - * @return this TransactionalContextBuilder - */ - TransactionContextBuilder withPartitionsDisabled(); - - /** - * Builds a TransactionContext based on configuration options supplied to this - * builder. - * - * @return a new TransactionalContext - * @throws java.lang.RuntimeException if a mandatory parameter is missing - */ - TransactionContext build(); -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionException.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionException.java deleted file mode 100644 index a3723ee7..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -/** - * Top level exception for Transaction failures. - */ -@SuppressWarnings("serial") -public class TransactionException extends StorageException { - public TransactionException() { - } - - public TransactionException(Throwable t) { - super(t); - } - - /** - * Transaction timeout. - */ - public static class Timeout extends TransactionException { - } - - /** - * Transaction interrupted. - */ - public static class Interrupted extends TransactionException { - } - - /** - * Transaction failure due to optimistic concurrency violation. - */ - public static class OptimisticConcurrencyFailure extends TransactionException { - } - - /** - * Transaction failure due to a conflicting transaction in progress. - */ - public static class ConcurrentModification extends TransactionException { - } -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionalMap.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionalMap.java deleted file mode 100644 index 657d9331..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionalMap.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -/** - * Transactional Map data structure. - * <p> - * A TransactionalMap is created by invoking {@link TransactionContext#getTransactionalMap getTransactionalMap} - * method. All operations performed on this map within a transaction boundary are invisible externally - * until the point when the transaction commits. A commit usually succeeds in the absence of conflicts. - * - * @param <K> type of key. - * @param <V> type of value. - */ -public interface TransactionalMap<K, V> { - - /** - * Returns the value to which the specified key is mapped, or null if this - * map contains no mapping for the key. - * - * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or null if - * this map contains no mapping for the key - */ - V get(K key); - - /** - * Associates the specified value with the specified key in this map (optional operation). - * If the map previously contained a mapping for the key, the old value is replaced by the - * specified value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with key, or null if there was - * no mapping for key. - */ - V put(K key, V value); - - /** - * Removes the mapping for a key from this map if it is present (optional operation). - * - * @param key key whose value is to be removed from the map - * @return the value to which this map previously associated the key, - * or null if the map contained no mapping for the key. - */ - V remove(K key); - - /** - * If the specified key is not already associated with a value - * associates it with the given value and returns null, else returns the current value. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with the specified key or null - * if key does not already mapped to a value. - */ - V putIfAbsent(K key, V value); - - /** - * Removes the entry for the specified key only if it is currently - * mapped to the specified value. - * - * @param key key with which the specified value is associated - * @param value value expected to be associated with the specified key - * @return true if the value was removed - */ - boolean remove(K key, V value); - - /** - * Replaces the entry for the specified key only if currently mapped - * to the specified value. - * - * @param key key with which the specified value is associated - * @param oldValue value expected to be associated with the specified key - * @param newValue value to be associated with the specified key - * @return true if the value was replaced - */ - boolean replace(K key, V oldValue, V newValue); -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Versioned.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Versioned.java deleted file mode 100644 index 89bd3029..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/Versioned.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.service; - -import java.util.function.Function; - -import org.joda.time.DateTime; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; - -/** - * Versioned value. - * - * @param <V> value type. - */ -public class Versioned<V> { - - private final V value; - private final long version; - private final long creationTime; - - /** - * Constructs a new versioned value. - * @param value value - * @param version version - * @param creationTime milliseconds of the creation event - * from the Java epoch of 1970-01-01T00:00:00Z - */ - public Versioned(V value, long version, long creationTime) { - this.value = value; - this.version = version; - this.creationTime = creationTime; - } - - /** - * Constructs a new versioned value. - * @param value value - * @param version version - */ - public Versioned(V value, long version) { - this(value, version, System.currentTimeMillis()); - } - - /** - * Returns the value. - * - * @return value. - */ - public V value() { - return value; - } - - /** - * Returns the version. - * - * @return version - */ - public long version() { - return version; - } - - /** - * Returns the system time when this version was created. - * <p> - * Care should be taken when relying on creationTime to - * implement any behavior in a distributed setting. Due - * to the possibility of clock skew it is likely that - * even creationTimes of causally related versions can be - * out or order. - * @return creation time - */ - public long creationTime() { - return creationTime; - } - - /** - * Maps this instance into another after transforming its - * value while retaining the same version and creationTime. - * @param transformer function for mapping the value - * @param <U> value type of the returned instance - * @return mapped instance - */ - public <U> Versioned<U> map(Function<V, U> transformer) { - return new Versioned<>(transformer.apply(value), version, creationTime); - } - - /** - * Returns the value of the specified Versioned object if non-null or else returns - * a default value. - * @param versioned versioned object - * @param defaultValue default value to return if versioned object is null - * @param <U> type of the versioned value - * @return versioned value or default value if versioned object is null - */ - public static <U> U valueOrElse(Versioned<U> versioned, U defaultValue) { - return versioned == null ? defaultValue : versioned.value(); - } - - @Override - public int hashCode() { - return Objects.hashCode(value, version, creationTime); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Versioned)) { - return false; - } - Versioned<V> that = (Versioned) other; - return Objects.equal(this.value, that.value) && - Objects.equal(this.version, that.version) && - Objects.equal(this.creationTime, that.creationTime); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("value", value) - .add("version", version) - .add("creationTime", new DateTime(creationTime)) - .toString(); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java deleted file mode 100644 index 4be7ede7..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.service; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.util.Objects; - -import org.onosproject.store.Timestamp; - -import com.google.common.base.MoreObjects; -import com.google.common.collect.ComparisonChain; - -/** - * A Timestamp that derives its value from the prevailing - * wallclock time on the controller where it is generated. - */ -public class WallClockTimestamp implements Timestamp { - - private final long unixTimestamp; - - public WallClockTimestamp() { - unixTimestamp = System.currentTimeMillis(); - } - - public WallClockTimestamp(long timestamp) { - unixTimestamp = timestamp; - } - - @Override - public int compareTo(Timestamp o) { - checkArgument(o instanceof WallClockTimestamp, - "Must be WallClockTimestamp", o); - WallClockTimestamp that = (WallClockTimestamp) o; - - return ComparisonChain.start() - .compare(this.unixTimestamp, that.unixTimestamp) - .result(); - } - @Override - public int hashCode() { - return Long.hashCode(unixTimestamp); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof WallClockTimestamp)) { - return false; - } - WallClockTimestamp that = (WallClockTimestamp) obj; - return Objects.equals(this.unixTimestamp, that.unixTimestamp); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("unixTimestamp", unixTimestamp) - .toString(); - } - - /** - * Returns the unixTimestamp. - * - * @return unix timestamp - */ - public long unixTimestamp() { - return unixTimestamp; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/package-info.java deleted file mode 100644 index 3d86e351..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Distributed core state management services. - */ -package org.onosproject.store.service; - |