tom | c1a38d3 | 2014-08-25 23:01:32 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.provider; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 2 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 5 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 6 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 7 | /** |
tom | db6c3f8 | 2014-10-01 21:30:17 -0700 | [diff] [blame^] | 8 | * External identity of a {@link org.onlab.onos.net.provider.Provider} family. |
| 9 | * It also carriers two designations of external characteristics, the URI |
| 10 | * scheme and primary/ancillary indicator. |
| 11 | * <p/> |
| 12 | * The device URI scheme is used to determine applicability of a provider to |
| 13 | * operations on a specific device. The ancillary indicator serves to designate |
| 14 | * a provider as a primary or ancillary. |
| 15 | * |
| 16 | * A {@link org.onlab.onos.net.provider.ProviderRegistry} uses this designation |
| 17 | * to permit only one primary provider per device URI scheme. Multiple |
| 18 | * ancillary providers can register with the same device URI scheme however. |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 19 | */ |
| 20 | public class ProviderId { |
| 21 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 22 | private final String scheme; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 23 | private final String id; |
tom | a536886 | 2014-10-01 12:35:48 -0700 | [diff] [blame] | 24 | private final boolean ancillary; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 25 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 26 | /** |
tom | db6c3f8 | 2014-10-01 21:30:17 -0700 | [diff] [blame^] | 27 | * Creates a new primary provider identifier from the specified string. |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 28 | * The providers are expected to follow the reverse DNS convention, e.g. |
| 29 | * {@code org.onlab.onos.provider.of.device} |
| 30 | * |
tom | db6c3f8 | 2014-10-01 21:30:17 -0700 | [diff] [blame^] | 31 | * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp" |
| 32 | * @param id string identifier |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 33 | */ |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 34 | public ProviderId(String scheme, String id) { |
tom | a536886 | 2014-10-01 12:35:48 -0700 | [diff] [blame] | 35 | this(scheme, id, false); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Creates a new provider identifier from the specified string. |
| 40 | * The providers are expected to follow the reverse DNS convention, e.g. |
| 41 | * {@code org.onlab.onos.provider.of.device} |
| 42 | * |
| 43 | * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp" |
| 44 | * @param id string identifier |
| 45 | * @param ancillary ancillary provider indicator |
| 46 | */ |
| 47 | public ProviderId(String scheme, String id, boolean ancillary) { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 48 | this.scheme = scheme; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 49 | this.id = id; |
tom | a536886 | 2014-10-01 12:35:48 -0700 | [diff] [blame] | 50 | this.ancillary = ancillary; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 51 | } |
| 52 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Returns the device URI scheme to which this provider is bound. |
| 55 | * |
| 56 | * @return device URI scheme |
| 57 | */ |
| 58 | public String scheme() { |
| 59 | return scheme; |
| 60 | } |
| 61 | |
Yuta HIGUCHI | c705201 | 2014-09-22 19:11:00 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Returns the device URI scheme specific id portion. |
| 64 | * |
| 65 | * @return id |
| 66 | */ |
| 67 | public String id() { |
| 68 | return id; |
| 69 | } |
| 70 | |
tom | db6c3f8 | 2014-10-01 21:30:17 -0700 | [diff] [blame^] | 71 | /** |
| 72 | * Indicates whether this identifier designates an ancillary providers. |
| 73 | * |
| 74 | * @return true if the provider is ancillary; false if primary |
| 75 | */ |
| 76 | public boolean isAncillary() { |
| 77 | return ancillary; |
| 78 | } |
| 79 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 80 | @Override |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 81 | public int hashCode() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 82 | return Objects.hash(scheme, id); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 86 | public boolean equals(Object obj) { |
| 87 | if (this == obj) { |
| 88 | return true; |
| 89 | } |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 90 | if (obj instanceof ProviderId) { |
| 91 | final ProviderId other = (ProviderId) obj; |
| 92 | return Objects.equals(this.scheme, other.scheme) && |
tom | a536886 | 2014-10-01 12:35:48 -0700 | [diff] [blame] | 93 | Objects.equals(this.id, other.id) && |
| 94 | this.ancillary == other.ancillary; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 95 | } |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 96 | return false; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
tom | a536886 | 2014-10-01 12:35:48 -0700 | [diff] [blame] | 101 | return toStringHelper(this).add("scheme", scheme).add("id", id) |
| 102 | .add("ancillary", ancillary).toString(); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 103 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 104 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 105 | } |