blob: 11741b50b5a85ff9c70ebbc8ef89af725a518868 [file] [log] [blame]
alshabib79e52872015-12-07 16:01:01 -08001/*
2 * Copyright 2015 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.incubator.store.mcast.impl;
17
18import com.google.common.collect.ImmutableSet;
alshabib79e52872015-12-07 16:01:01 -080019import org.onosproject.net.ConnectPoint;
20
Jonathan Hart6ccfc5a2016-02-12 19:26:02 -080021import java.util.HashSet;
alshabib79e52872015-12-07 16:01:01 -080022import java.util.Set;
23import java.util.concurrent.atomic.AtomicBoolean;
24import java.util.concurrent.atomic.AtomicReference;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Simple entity maintaining a mapping between a source and a collection of sink
30 * connect points.
31 */
32public final class MulticastData {
33
34 private final AtomicReference<ConnectPoint> source =
35 new AtomicReference<>();
36 private final Set<ConnectPoint> sinks;
37 private final AtomicBoolean isEmpty = new AtomicBoolean();
38
39 private MulticastData() {
Jonathan Hart6ccfc5a2016-02-12 19:26:02 -080040 // FIXME we have major problems trying to serialize these sets
41 //this.sinks = Sets.newConcurrentHashSet();
42 this.sinks = new HashSet<>();
alshabib79e52872015-12-07 16:01:01 -080043 isEmpty.set(true);
44 }
45
46 public MulticastData(ConnectPoint source) {
47 this.source.set(checkNotNull(source, "Multicast source cannot be null."));
Jonathan Hart6ccfc5a2016-02-12 19:26:02 -080048 //this.sinks = Sets.newConcurrentHashSet();
49 this.sinks = new HashSet<>();
alshabib79e52872015-12-07 16:01:01 -080050 isEmpty.set(false);
51 }
52
53 public ConnectPoint source() {
54 return source.get();
55 }
56
57 public Set<ConnectPoint> sinks() {
58 return ImmutableSet.copyOf(sinks);
59 }
60
61 public void setSource(ConnectPoint source) {
62 isEmpty.set(false);
63 this.source.set(source);
64 }
65
66 public void appendSink(ConnectPoint sink) {
Jonathan Hart07eb0412016-02-08 16:42:29 -080067 checkNotNull(sink);
alshabib79e52872015-12-07 16:01:01 -080068 sinks.add(sink);
69 }
70
71 public boolean removeSink(ConnectPoint sink) {
Jonathan Hart07eb0412016-02-08 16:42:29 -080072 checkNotNull(sink);
alshabib79e52872015-12-07 16:01:01 -080073 return sinks.remove(sink);
74 }
75
76 public boolean isEmpty() {
77 return isEmpty.get();
78 }
79
80 public static MulticastData empty() {
81 return new MulticastData();
82 }
83
84}