Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.group; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 23 | /** |
| 24 | * Default implementation of group description interface. |
| 25 | */ |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 26 | public class DefaultGroupDescription implements GroupDescription { |
| 27 | private final GroupDescription.Type type; |
| 28 | private final GroupBuckets buckets; |
| 29 | private final GroupKey appCookie; |
| 30 | private final ApplicationId appId; |
| 31 | private final DeviceId deviceId; |
| 32 | |
| 33 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 34 | * Constructor to be used by north bound applications. |
| 35 | * NOTE: The caller of this subsystem MUST ensure the appCookie |
| 36 | * provided in this API is immutable |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 37 | * |
| 38 | * @param deviceId device identifier |
| 39 | * @param type type of the group |
| 40 | * @param buckets immutable list of group bucket |
| 41 | * @param appCookie immutable application cookie to be associated with the group |
| 42 | * @param appId application id |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 43 | */ |
| 44 | public DefaultGroupDescription(DeviceId deviceId, |
| 45 | GroupDescription.Type type, |
| 46 | GroupBuckets buckets, |
| 47 | GroupKey appCookie, |
| 48 | ApplicationId appId) { |
| 49 | this.type = checkNotNull(type); |
| 50 | this.deviceId = checkNotNull(deviceId); |
| 51 | this.buckets = checkNotNull(buckets); |
| 52 | this.appCookie = checkNotNull(appCookie); |
| 53 | this.appId = checkNotNull(appId); |
| 54 | } |
| 55 | |
| 56 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 57 | * Constructor to be used by group subsystem internal components. |
| 58 | * Creates group description object from another object of same type. |
| 59 | * |
| 60 | * @param groupDesc group description object |
| 61 | * |
| 62 | */ |
| 63 | public DefaultGroupDescription(GroupDescription groupDesc) { |
| 64 | this.type = checkNotNull(groupDesc.type()); |
| 65 | this.deviceId = checkNotNull(groupDesc.deviceId()); |
| 66 | this.buckets = checkNotNull(groupDesc.buckets()); |
| 67 | this.appCookie = checkNotNull(groupDesc.appCookie()); |
| 68 | this.appId = checkNotNull(groupDesc.appId()); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns type of a group object. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 73 | * |
| 74 | * @return GroupType group type |
| 75 | */ |
| 76 | @Override |
| 77 | public GroupDescription.Type type() { |
| 78 | return this.type; |
| 79 | } |
| 80 | |
| 81 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 82 | * Returns device identifier on which this group object is created. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 83 | * |
| 84 | * @return DeviceId device identifier |
| 85 | */ |
| 86 | @Override |
| 87 | public DeviceId deviceId() { |
| 88 | return this.deviceId; |
| 89 | } |
| 90 | |
| 91 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 92 | * Returns application identifier that has created this group object. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 93 | * |
| 94 | * @return ApplicationId application identifier |
| 95 | */ |
| 96 | @Override |
| 97 | public ApplicationId appId() { |
| 98 | return this.appId; |
| 99 | } |
| 100 | |
| 101 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 102 | * Returns application cookie associated with a group object. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 103 | * |
| 104 | * @return GroupKey application cookie |
| 105 | */ |
| 106 | @Override |
| 107 | public GroupKey appCookie() { |
| 108 | return this.appCookie; |
| 109 | } |
| 110 | |
| 111 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 112 | * Returns group buckets of a group. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 113 | * |
| 114 | * @return GroupBuckets immutable list of group bucket |
| 115 | */ |
| 116 | @Override |
| 117 | public GroupBuckets buckets() { |
| 118 | return this.buckets; |
| 119 | } |
| 120 | |
| 121 | } |