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/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index badad7f..f08e513 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -15,7 +15,19 @@
*/
package org.onosproject.sdnip;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Semaphore;
+
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
@@ -43,19 +55,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Semaphore;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import static com.google.common.base.Preconditions.checkArgument;
@@ -340,11 +340,15 @@
int priority =
prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Key key = Key.of(prefix.toString(), appId);
- return new MultiPointToSinglePointIntent(appId, key, selector.build(),
- treatment.build(),
- ingressPorts, egressPort,
- Collections.emptyList(),
- priority);
+ return MultiPointToSinglePointIntent.builder()
+ .appId(appId)
+ .key(key)
+ .selector(selector.build())
+ .treatment(treatment.build())
+ .ingressPoints(ingressPorts)
+ .egressPoint(egressPort)
+ .priority(priority)
+ .build();
}
@Override