blob: a5de405f7c2b3e53ca09c43b89b3ca4a549a32bb [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.ui.model.topo;
18
Simon Hunt338a3b42016-04-14 09:43:52 -070019import org.onosproject.cluster.NodeId;
20
Simon Hunt23fb1352016-04-11 12:15:19 -070021import java.util.ArrayList;
Simon Hunt338a3b42016-04-14 09:43:52 -070022import java.util.HashMap;
Simon Hunt23fb1352016-04-11 12:15:19 -070023import java.util.List;
Simon Hunt338a3b42016-04-14 09:43:52 -070024import java.util.Map;
Simon Hunt23fb1352016-04-11 12:15:19 -070025
Simon Hunt5f6dbf82016-03-30 08:53:33 -070026/**
27 * Encapsulates the notion of the ONOS cluster.
28 */
Simon Hunt23fb1352016-04-11 12:15:19 -070029class UiCluster extends UiElement {
30
31 private final List<UiClusterMember> members = new ArrayList<>();
Simon Hunt338a3b42016-04-14 09:43:52 -070032 private final Map<NodeId, UiClusterMember> lookup = new HashMap<>();
33
34 @Override
35 public String toString() {
36 return String.valueOf(members.size()) + "-member cluster";
37 }
Simon Hunt23fb1352016-04-11 12:15:19 -070038
39 /**
40 * Removes all cluster members.
41 */
42 void clear() {
43 members.clear();
44 }
Simon Hunt338a3b42016-04-14 09:43:52 -070045
46 /**
47 * Returns the cluster member with the given identifier, or null if no
48 * such member exists.
49 *
50 * @param id identifier of member to find
51 * @return corresponding member
52 */
53 public UiClusterMember find(NodeId id) {
54 return lookup.get(id);
55 }
56
57 /**
58 * Adds the given member to the cluster.
59 *
60 * @param member member to add
61 */
62 public void add(UiClusterMember member) {
63 members.add(member);
64 lookup.put(member.id(), member);
65 }
66
67 /**
68 * Returns the number of members in the cluster.
69 *
70 * @return number of members
71 */
72 public int size() {
73 return members.size();
74 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -070075}