openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans-meecrowave] branch master updated: MEECROWAVE-202 Ensure configuration, context and tomcat customizers are sortable using @Priority
Date Mon, 15 Jul 2019 07:22:49 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git


The following commit(s) were added to refs/heads/master by this push:
     new 79da490  MEECROWAVE-202 Ensure configuration, context and tomcat customizers are
sortable using @Priority
79da490 is described below

commit 79da4900a6ae56829b912d7e2a850d760f8a7130
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
AuthorDate: Mon Jul 15 09:22:24 2019 +0200

    MEECROWAVE-202 Ensure configuration, context and tomcat customizers are sortable using
@Priority
---
 .../main/java/org/apache/meecrowave/Meecrowave.java  | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
index 98fccbb..200a651 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
@@ -68,6 +68,7 @@ import java.util.function.Function;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
+import javax.annotation.Priority;
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 import javax.enterprise.context.spi.CreationalContext;
@@ -719,6 +720,7 @@ public class Meecrowave implements AutoCloseable {
                         MeecrowaveAwareInstanceCustomizer.class.cast(i).setMeecrowave(this);
                     }
                 })
+                .sorted(Meecrowave::sortByPriority)
                 .forEach(c -> c.accept(tomcat));
         configuration.instanceCustomizers.forEach(c -> c.accept(tomcat));
 
@@ -728,6 +730,7 @@ public class Meecrowave implements AutoCloseable {
                         MeecrowaveAwareContextCustomizer.class.cast(i).setMeecrowave(this);
                     }
                 })
+                .sorted(Meecrowave::sortByPriority)
                 .forEach(configuration::addGlobalContextCustomizer);
 
         beforeStart();
@@ -1154,6 +1157,16 @@ public class Meecrowave implements AutoCloseable {
         return recipe;
     }
 
+    private static int priorityOf(final Object i) {
+        return ofNullable(i.getClass().getAnnotation(Priority.class))
+                .map(Priority::value)
+                .orElse(0);
+    }
+
+    private static <T> int sortByPriority(final T a, final T b) {
+        return priorityOf(a) - priorityOf(b);
+    }
+
     // this class holds all the built-in config,
     // extension can use extensions feature (see cli.html) which is basically the same kind
of bean
     // accessible through builder.getExtension(type) builder being accessible through the
meecrowave.configuration
@@ -1401,6 +1414,7 @@ public class Meecrowave implements AutoCloseable {
         public Builder() { // load defaults
             extensions.put(ValueTransformers.class, new ValueTransformers());
             StreamSupport.stream(ServiceLoader.load(Meecrowave.ConfigurationCustomizer.class).spliterator(),
false)
+                    .sorted(Meecrowave::sortByPriority)
                     .forEach(c -> c.accept(this));
             loadFrom(meecrowaveProperties);
         }
@@ -2692,9 +2706,15 @@ public class Meecrowave implements AutoCloseable {
     public interface ConfigurationCustomizer extends Consumer<Meecrowave.Builder> {
     }
 
+    /**
+     * SPI to customize Tomcat instance. They are sorted by Priority, default being 0.
+     */
     public interface InstanceCustomizer extends Consumer<Tomcat> {
     }
 
+    /**
+     * SPI to customize context instances. They are sorted by Priority, default being 0.
+     */
     public interface ContextCustomizer extends Consumer<Context> {
     }
 


Mime
View raw message