Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame^] | 19 | import org.onosproject.cluster.NodeId; |
| 20 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 21 | import java.util.ArrayList; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame^] | 22 | import java.util.HashMap; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 23 | import java.util.List; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame^] | 24 | import java.util.Map; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 25 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Encapsulates the notion of the ONOS cluster. |
| 28 | */ |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 29 | class UiCluster extends UiElement { |
| 30 | |
| 31 | private final List<UiClusterMember> members = new ArrayList<>(); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame^] | 32 | 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 Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Removes all cluster members. |
| 41 | */ |
| 42 | void clear() { |
| 43 | members.clear(); |
| 44 | } |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame^] | 45 | |
| 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 Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 75 | } |