blob: e6b62d775e4f7f0903816919c72b87e61c1197cb [file] [log] [blame]
Jon Halld198b882016-05-18 16:44:40 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.primitives.impl;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableSet;
20import org.onosproject.cluster.NodeId;
21
22import java.util.Set;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Describes a request for update events in an EventuallyConsistentMap.
28 */
29final class UpdateRequest<K> {
30
31 private final NodeId sender;
32 private final Set<K> keys;
33
34 /**
35 * Creates a new update request.
36 *
37 * @param sender the sender's node ID
38 * @param keys keys requested
39 */
40 public UpdateRequest(NodeId sender, Set<K> keys) {
41 this.sender = checkNotNull(sender);
42 this.keys = ImmutableSet.copyOf(keys);
43 }
44
45 /**
46 * Returns the sender's node ID.
47 *
48 * @return the sender's node ID
49 */
50 public NodeId sender() {
51 return sender;
52 }
53
54 /**
55 * Returns the keys.
56 *
57 * @return the keys
58 */
59 public Set<K> keys() {
60 return keys;
61 }
62
63 @Override
64 public String toString() {
65 return MoreObjects.toStringHelper(getClass())
66 .add("sender", sender)
67 .add("keys", keys())
68 .toString();
69 }
70
71 @SuppressWarnings("unused")
72 private UpdateRequest() {
73 this.sender = null;
74 this.keys = null;
75 }
76}