blob: ebd2d10f2fae95cc6c37244e2270056064af9b46 [file] [log] [blame]
alshabib79e52872015-12-07 16:01:01 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabib79e52872015-12-07 16:01:01 -08003 *
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.incubator.store.mcast.impl;
17
18import com.google.common.collect.ImmutableSet;
alshabibe62b5072016-02-14 18:00:54 -080019import com.google.common.collect.Maps;
alshabib79e52872015-12-07 16:01:01 -080020import org.onosproject.net.ConnectPoint;
21
alshabibe62b5072016-02-14 18:00:54 -080022import java.util.Map;
alshabib79e52872015-12-07 16:01:01 -080023import java.util.Set;
24import java.util.concurrent.atomic.AtomicBoolean;
25import java.util.concurrent.atomic.AtomicReference;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * Simple entity maintaining a mapping between a source and a collection of sink
31 * connect points.
32 */
33public final class MulticastData {
34
35 private final AtomicReference<ConnectPoint> source =
36 new AtomicReference<>();
alshabibe62b5072016-02-14 18:00:54 -080037 private final Map<ConnectPoint, Boolean> sinks;
alshabib79e52872015-12-07 16:01:01 -080038 private final AtomicBoolean isEmpty = new AtomicBoolean();
39
40 private MulticastData() {
alshabibe62b5072016-02-14 18:00:54 -080041 this.sinks = Maps.newConcurrentMap();
alshabib79e52872015-12-07 16:01:01 -080042 isEmpty.set(true);
43 }
44
45 public MulticastData(ConnectPoint source) {
46 this.source.set(checkNotNull(source, "Multicast source cannot be null."));
alshabibe62b5072016-02-14 18:00:54 -080047 this.sinks = Maps.newConcurrentMap();
alshabib79e52872015-12-07 16:01:01 -080048 isEmpty.set(false);
49 }
50
51 public ConnectPoint source() {
52 return source.get();
53 }
54
55 public Set<ConnectPoint> sinks() {
alshabibe62b5072016-02-14 18:00:54 -080056 return ImmutableSet.copyOf(sinks.keySet());
alshabib79e52872015-12-07 16:01:01 -080057 }
58
59 public void setSource(ConnectPoint source) {
Madan Jampani72282af2016-02-23 14:23:52 -080060 // FIXME: violates immutability
alshabib79e52872015-12-07 16:01:01 -080061 isEmpty.set(false);
62 this.source.set(source);
63 }
64
65 public void appendSink(ConnectPoint sink) {
Jonathan Hart07eb0412016-02-08 16:42:29 -080066 checkNotNull(sink);
alshabibe62b5072016-02-14 18:00:54 -080067 sinks.put(sink, true);
alshabib79e52872015-12-07 16:01:01 -080068 }
69
alshabib1aa58142016-02-17 15:37:56 -080070 public void removeSink(ConnectPoint sink) {
Jonathan Hart07eb0412016-02-08 16:42:29 -080071 checkNotNull(sink);
alshabib1aa58142016-02-17 15:37:56 -080072 sinks.remove(sink);
alshabib79e52872015-12-07 16:01:01 -080073 }
74
75 public boolean isEmpty() {
76 return isEmpty.get();
77 }
78
79 public static MulticastData empty() {
80 return new MulticastData();
81 }
82
83}