blob: c1fdbf16245b8db7ba68cdd6c053b01113a59c6e [file] [log] [blame]
Andrea Campanella378e21a2017-06-07 12:09:59 +02001/*
2 * Copyright 2017-present 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
17package org.onosproject.grpc.api;
18
19import com.google.common.annotations.Beta;
20import org.onlab.util.Identifier;
21import org.onosproject.net.DeviceId;
22
23import static com.google.common.base.Preconditions.checkArgument;
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * gRPCChannel identifier suitable as an external key.
28 * <p>
29 * This class is immutable.</p>
30 */
31@Beta
32public final class GrpcChannelId extends Identifier<String> {
33
34 private final DeviceId deviceId;
35
36 private final String channelName;
37
38 /**
39 * Instantiates a new GrpcChannel id.
40 *
41 * @param deviceId the device id
42 * @param channelName the name of the channel
43 */
44 private GrpcChannelId(DeviceId deviceId, String channelName) {
45 super(deviceId.toString() + ":" + channelName);
46 checkNotNull(deviceId, "device id must not be null");
47 checkNotNull(channelName, "channel name must not be null");
48 checkArgument(!channelName.isEmpty(), "channel name must not be empty");
49 this.deviceId = deviceId;
50 this.channelName = channelName;
51 }
52
53 /**
54 * Returns the deviceId of the device that uses this channel.
55 *
56 * @return the device Id
57 */
58 public DeviceId deviceId() {
59 return deviceId;
60 }
61
62 /**
63 * Returns the channel name.
64 *
65 * @return the channel name
66 */
67 public String channelName() {
68 return channelName;
69 }
70
71 /**
72 * Creates a grpc channel identifier from the specified device id and name provided.
73 *
74 * @param id device id
75 * @param channelName name of the channel
76 * @return channel name
77 */
78 public static GrpcChannelId of(DeviceId id, String channelName) {
79 return new GrpcChannelId(id, channelName);
80 }
81}