Changed the way ProviderId is made to include URI scheme portion.
diff --git a/core/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java b/core/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java
index f8cdb6b..6cf91a6 100644
--- a/core/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java
+++ b/core/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java
@@ -1,6 +1,7 @@
package org.onlab.onos.net.provider;
import com.google.common.collect.ImmutableSet;
+import org.onlab.onos.net.DeviceId;
import java.util.HashMap;
import java.util.Map;
@@ -20,6 +21,7 @@
private final Map<ProviderId, P> providers = new HashMap<>();
private final Map<ProviderId, S> services = new HashMap<>();
+ private final Map<String, P> providersByScheme = new HashMap<>();
/**
* Creates a new provider service bound to the specified provider.
@@ -65,4 +67,14 @@
return providers.get(providerId);
}
+ /**
+ * Returns the provider for the specified device ID based on URI scheme.
+ *
+ * @param deviceId device identifier
+ * @return provider bound to the URI scheme
+ */
+ protected synchronized P getProvider(DeviceId deviceId) {
+ return providersByScheme.get(deviceId.uri().getScheme());
+ }
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/provider/ProviderId.java b/core/api/src/main/java/org/onlab/onos/net/provider/ProviderId.java
index a945354..e9af0eb 100644
--- a/core/api/src/main/java/org/onlab/onos/net/provider/ProviderId.java
+++ b/core/api/src/main/java/org/onlab/onos/net/provider/ProviderId.java
@@ -9,6 +9,7 @@
*/
public class ProviderId {
+ private final String scheme;
private final String id;
/**
@@ -16,15 +17,26 @@
* The providers are expected to follow the reverse DNS convention, e.g.
* {@code org.onlab.onos.provider.of.device}
*
- * @param id string identifier
+ * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
+ * @param id string identifier
*/
- public ProviderId(String id) {
+ public ProviderId(String scheme, String id) {
+ this.scheme = scheme;
this.id = id;
}
+ /**
+ * Returns the device URI scheme to which this provider is bound.
+ *
+ * @return device URI scheme
+ */
+ public String scheme() {
+ return scheme;
+ }
+
@Override
public int hashCode() {
- return Objects.hash(id);
+ return Objects.hash(scheme, id);
}
@Override
@@ -36,12 +48,13 @@
return false;
}
final ProviderId other = (ProviderId) obj;
- return Objects.equals(this.id, other.id);
+ return Objects.equals(this.scheme, other.scheme) &&
+ Objects.equals(this.id, other.id);
}
@Override
public String toString() {
- return toStringHelper(this).add("id", id).toString();
+ return toStringHelper(this).add("scheme", scheme).add("id", id).toString();
}
}