Refactor connectivity intent creation to use builders
- Each connectivity intent now has only one constructor
- Intent constructors are now private for leaf classes and
protected for classes that can be derived from
- Each intent class has a Builder class that accumulates
parameters for intent creation
- Each intent class has a public static builder() method
to create a builder
- Each Builder class has a build() method to create the
intent from the accumulated parameters
- Added keys to a few intent types that were missing them
- Tightened up usage of checkNotNull(), taking advantage of
the return value to save some lines of code
- Modified callers to use the builders instead of directly
calling the constructors
Change-Id: I713185d5ecbadbf51f87ef7f68fec41102106c78
diff --git a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
index 721ff17..c92898e 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
@@ -16,6 +16,7 @@
package org.onosproject.net.intent;
import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
@@ -42,29 +43,6 @@
* traffic selector and treatment.
*
* @param appId application identifier
- * @param selector traffic selector
- * @param treatment treatment
- * @param ingressPoints set of ports from which ingress traffic originates
- * @param egressPoint port to which traffic will egress
- * @throws NullPointerException if {@code ingressPoints} or
- * {@code egressPoint} is null.
- * @throws IllegalArgumentException if the size of {@code ingressPoints} is
- * not more than 1
- */
- public MultiPointToSinglePointIntent(ApplicationId appId,
- TrafficSelector selector,
- TrafficTreatment treatment,
- Set<ConnectPoint> ingressPoints,
- ConnectPoint egressPoint) {
- this(appId, selector, treatment, ingressPoints, egressPoint,
- Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
- }
-
- /**
- * Creates a new multi-to-single point connectivity intent for the specified
- * traffic selector and treatment.
- *
- * @param appId application identifier
* @param key intent key
* @param selector traffic selector
* @param treatment treatment
@@ -77,7 +55,7 @@
* @throws IllegalArgumentException if the size of {@code ingressPoints} is
* not more than 1
*/
- public MultiPointToSinglePointIntent(ApplicationId appId,
+ private MultiPointToSinglePointIntent(ApplicationId appId,
Key key,
TrafficSelector selector,
TrafficTreatment treatment,
@@ -99,33 +77,6 @@
}
/**
- * Creates a new multi-to-single point connectivity intent for the specified
- * traffic selector and treatment.
- *
- * @param appId application identifier
- * @param selector traffic selector
- * @param treatment treatment
- * @param ingressPoints set of ports from which ingress traffic originates
- * @param egressPoint port to which traffic will egress
- * @param constraints constraints to apply to the intent
- * @param priority priority to use for flows generated by this intent
- * @throws NullPointerException if {@code ingressPoints} or
- * {@code egressPoint} is null.
- * @throws IllegalArgumentException if the size of {@code ingressPoints} is
- * not more than 1
- */
- public MultiPointToSinglePointIntent(ApplicationId appId,
- TrafficSelector selector,
- TrafficTreatment treatment,
- Set<ConnectPoint> ingressPoints,
- ConnectPoint egressPoint,
- List<Constraint> constraints,
- int priority) {
- this(appId, null, selector, treatment, ingressPoints, egressPoint,
- constraints, priority);
- }
-
- /**
* Constructor for serializer.
*/
protected MultiPointToSinglePointIntent() {
@@ -135,6 +86,105 @@
}
/**
+ * Returns a new multi point to single point intent builder. The application id,
+ * ingress points and egress point are required fields. If they are
+ * not set by calls to the appropriate methods, an exception will
+ * be thrown.
+ *
+ * @return single point to multi point builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder of a multi point to single point intent.
+ */
+ public static final class Builder extends ConnectivityIntent.Builder {
+ Set<ConnectPoint> ingressPoints;
+ ConnectPoint egressPoint;
+
+ private Builder() {
+ // Hide constructor
+ }
+
+ @Override
+ public Builder appId(ApplicationId appId) {
+ return (Builder) super.appId(appId);
+ }
+
+ @Override
+ public Builder key(Key key) {
+ return (Builder) super.key(key);
+ }
+
+ @Override
+ public Builder selector(TrafficSelector selector) {
+ return (Builder) super.selector(selector);
+ }
+
+ @Override
+ public Builder treatment(TrafficTreatment treatment) {
+ return (Builder) super.treatment(treatment);
+ }
+
+ @Override
+ public Builder constraints(List<Constraint> constraints) {
+ return (Builder) super.constraints(constraints);
+ }
+
+ @Override
+ public Builder priority(int priority) {
+ return (Builder) super.priority(priority);
+ }
+
+ /**
+ * Sets the ingress point of the single point to multi point intent
+ * that will be built.
+ *
+ * @param ingressPoints ingress connect points
+ * @return this builder
+ */
+ public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
+ this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
+ return this;
+ }
+
+ /**
+ * Sets the egress point of the multi point to single point intent
+ * that will be built.
+ *
+ * @param egressPoint egress connect point
+ * @return this builder
+ */
+ public Builder egressPoint(ConnectPoint egressPoint) {
+ this.egressPoint = egressPoint;
+ return this;
+ }
+
+ /**
+ * Builds a multi point to single point intent from the
+ * accumulated parameters.
+ *
+ * @return point to point intent
+ */
+ public MultiPointToSinglePointIntent build() {
+
+ return new MultiPointToSinglePointIntent(
+ appId,
+ key,
+ selector,
+ treatment,
+ ingressPoints,
+ egressPoint,
+ constraints,
+ priority
+ );
+ }
+ }
+
+
+ /**
* Returns the set of ports on which ingress traffic should be connected to
* the egress port.
*