summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider/src/main
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2020-03-01 15:44:26 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-01 15:44:26 +0000
commit76a2d0ed90c281768793a279debbd6ee6e445fce (patch)
tree00fcabf94706b533983aec22cae60eb36f3e40b8 /models-interactions/model-actors/actorServiceProvider/src/main
parentfe0673988d5707bbb6553802946f3ca5b31dca44 (diff)
parentf583aa9031e4f73ae0004bf972ac7a6c3afa4b71 (diff)
Merge "Add sequence number to Actors"
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/main')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java43
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java8
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java10
3 files changed, 49 insertions, 12 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
index b0d70fda0..49379b28c 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
@@ -25,6 +25,8 @@ import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
@@ -55,17 +57,7 @@ public class ActorService extends StartConfigPartial<Map<String, Object>> {
Map<String, Actor> map = new HashMap<>();
- Iterator<Actor> iter = loadActors().iterator();
- while (iter.hasNext()) {
-
- Actor newActor;
- try {
- newActor = iter.next();
- } catch (ServiceConfigurationError e) {
- logger.warn("unable to load actor", e);
- continue;
- }
-
+ for (Actor newActor : buildList()) {
map.compute(newActor.getName(), (name, existingActor) -> {
if (existingActor == null) {
return newActor;
@@ -81,6 +73,35 @@ public class ActorService extends StartConfigPartial<Map<String, Object>> {
}
/**
+ * Builds the list of actors, discarding those that cannot be constructed.
+ *
+ * @return the list of actors, sorted by ascending sequence number
+ */
+ private List<Actor> buildList() {
+ List<Actor> actors = new LinkedList<>();
+
+ Iterator<Actor> iter = loadActors().iterator();
+ while (iter.hasNext()) {
+ try {
+ actors.add(iter.next());
+ } catch (ServiceConfigurationError e) {
+ logger.warn("unable to load actor", e);
+ }
+ }
+
+ actors.sort((actor1, actor2) -> {
+ int cmp = Integer.compare(actor1.getSequenceNumber(), actor2.getSequenceNumber());
+ if (cmp != 0) {
+ return cmp;
+ }
+
+ return actor1.getClass().getName().compareTo(actor2.getClass().getName());
+ });
+
+ return actors;
+ }
+
+ /**
* Gets a particular actor.
*
* @param name name of the actor of interest
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java
index 0c88ebee2..12af030d5 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java
@@ -56,6 +56,14 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
}
/**
+ * This method simply returns {@code 0}.
+ */
+ @Override
+ public int getSequenceNumber() {
+ return 0;
+ }
+
+ /**
* Adds an operator supported by this actor.
*
* @param operator operation to be added
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java
index 53bee5f00..52d1a5a9a 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java
@@ -36,7 +36,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator;
* @author pameladragosh
*
*/
-public interface Actor extends Startable, Configurable<Map<String,Object>> {
+public interface Actor extends Startable, Configurable<Map<String, Object>> {
/**
* Gets the name of the actor.
@@ -68,6 +68,14 @@ public interface Actor extends Startable, Configurable<Map<String,Object>> {
*/
public Set<String> getOperationNames();
+ /**
+ * Gets the actor sequence number. Lower numbered actors take precedence over higher
+ * numbered actors.
+ *
+ * @return the actor sequence number
+ */
+ public int getSequenceNumber();
+
// TODO old code: remove lines down to **HERE**