You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/10/22 05:43:59 UTC

[james-project] branch master updated (a72e809 -> 53b864c)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from a72e809  JAMES-2813 Globally fix typo: information has no plural
     new 7752687  JAMES-2866 Log additional modules
     new a5a1f11  JAMES-2866 Fix warnings in GuiceGenericLoader
     new fe58c21  JAMES-2866 singleton are not shared between extensions
     new 53b864c  JAMES-2866 Create a single child injector for extensions

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/james/utils/GuiceGenericLoader.java |  27 +++++++++------------
 .../apache/james/utils/GuiceMailetLoaderTest.java  |  20 +++++++++++++++
 ...ustom-mailets-implementation-3.5.0-SNAPSHOT.jar | Bin 11147 -> 11069 bytes
 ...ailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar | Bin 30473134 -> 30057150 bytes
 .../james/transport/mailets/MyExtensionModule.java |   5 ++--
 .../james/transport/mailets/MyGenericMailet.java   |  17 +++++++++++++
 6 files changed, 52 insertions(+), 17 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 02/04: JAMES-2866 Fix warnings in GuiceGenericLoader

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a5a1f11c12d62b63c17db2da11e73ddb52eb071b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Oct 18 11:27:22 2019 +0700

    JAMES-2866 Fix warnings in GuiceGenericLoader
---
 .../src/main/java/org/apache/james/utils/GuiceGenericLoader.java      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
index d8ca52e..1163907 100644
--- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
+++ b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
@@ -113,10 +113,10 @@ public class GuiceGenericLoader {
     }
 
     public <T> InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme) {
-        return new InvocationPerformer<T>(injector, extendedClassLoader, namingSheme, additionalExtensionBindings);
+        return new InvocationPerformer<>(injector, extendedClassLoader, namingSheme, additionalExtensionBindings);
     }
 
     public <T> InvocationPerformer<T> withChildModule(Module childModule) {
-        return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY, Modules.combine(additionalExtensionBindings, childModule));
+        return new InvocationPerformer<>(injector, extendedClassLoader, NamingScheme.IDENTITY, Modules.combine(additionalExtensionBindings, childModule));
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 04/04: JAMES-2866 Create a single child injector for extensions

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 53b864cd85bd7581b7e4ace5439a924b5e2ec1d8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Oct 22 01:11:03 2019 +0200

    JAMES-2866 Create a single child injector for extensions
    
     - Extensions SINGLETON bindings are preserved
     - Performance enhancement
---
 .../org/apache/james/utils/GuiceGenericLoader.java | 26 +++++++++-------------
 .../apache/james/utils/GuiceMailetLoaderTest.java  |  2 --
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
index 1163907..97bdb1d 100644
--- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
+++ b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
@@ -36,7 +36,6 @@ import com.google.inject.util.Modules;
 
 public class GuiceGenericLoader {
     private static final Logger LOGGER = LoggerFactory.getLogger(GuiceGenericLoader.class);
-    private static final Module NO_CHILD_MODULE = binder -> { };
 
     @VisibleForTesting
     public static GuiceGenericLoader forTesting(ExtendedClassLoader extendedClassLoader) {
@@ -47,19 +46,16 @@ public class GuiceGenericLoader {
         private final Injector injector;
         private final ExtendedClassLoader extendedClassLoader;
         private final NamingScheme namingSheme;
-        private final Module childModule;
 
-        private InvocationPerformer(Injector injector, ExtendedClassLoader extendedClassLoader, NamingScheme namingSheme, Module childModule) {
+        private InvocationPerformer(Injector injector, ExtendedClassLoader extendedClassLoader, NamingScheme namingSheme) {
             this.injector = injector;
             this.extendedClassLoader = extendedClassLoader;
             this.namingSheme = namingSheme;
-            this.childModule = childModule;
         }
 
         public T instantiate(ClassName className) throws ClassNotFoundException {
             Class<T> clazz = locateClass(className, namingSheme);
-            return injector.createChildInjector(childModule)
-                .getInstance(clazz);
+            return injector.getInstance(clazz);
         }
 
         private Class<T> locateClass(ClassName className, NamingScheme namingScheme) throws ClassNotFoundException {
@@ -88,35 +84,35 @@ public class GuiceGenericLoader {
 
     private final Injector injector;
     private final ExtendedClassLoader extendedClassLoader;
-    private final Module additionalExtensionBindings;
 
     @Inject
     public GuiceGenericLoader(Injector injector, ExtendedClassLoader extendedClassLoader, ExtensionConfiguration extensionConfiguration) {
-        this.injector = injector;
+
         this.extendedClassLoader = extendedClassLoader;
 
-        this.additionalExtensionBindings = Modules.combine(extensionConfiguration.getAdditionalGuiceModulesForExtensions()
+        Module additionalExtensionBindings = Modules.combine(extensionConfiguration.getAdditionalGuiceModulesForExtensions()
             .stream()
-            .map(Throwing.function(this::<Module>instantiateNoChildModule))
+            .map(Throwing.<ClassName, Module>function(className -> instantiateNoChildModule(injector, className)))
             .peek(module -> LOGGER.info("Enabling injects contained in " + module.getClass().getCanonicalName()))
             .collect(Guavate.toImmutableList()));
+        this.injector = injector.createChildInjector(additionalExtensionBindings);
     }
 
-    private  <T> T instantiateNoChildModule(ClassName className) throws ClassNotFoundException {
-        return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY, NO_CHILD_MODULE)
+    private <T> T instantiateNoChildModule(Injector injector, ClassName className) throws ClassNotFoundException {
+        return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY)
             .instantiate(className);
     }
 
     public <T> T instantiate(ClassName className) throws ClassNotFoundException {
-        return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY, additionalExtensionBindings)
+        return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY)
             .instantiate(className);
     }
 
     public <T> InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme) {
-        return new InvocationPerformer<>(injector, extendedClassLoader, namingSheme, additionalExtensionBindings);
+        return new InvocationPerformer<>(injector, extendedClassLoader, namingSheme);
     }
 
     public <T> InvocationPerformer<T> withChildModule(Module childModule) {
-        return new InvocationPerformer<>(injector, extendedClassLoader, NamingScheme.IDENTITY, Modules.combine(additionalExtensionBindings, childModule));
+        return new InvocationPerformer<>(injector.createChildInjector(childModule), extendedClassLoader, NamingScheme.IDENTITY);
     }
 }
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
index e261c1a..43c2434 100644
--- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
@@ -33,7 +33,6 @@ import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -185,7 +184,6 @@ public class GuiceMailetLoaderTest {
         assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException();
     }
 
-    @Ignore("JAMES-2866 singleton are not shared between extensions")
     @Test
     public void allMailetsShouldShareTheSameSingleton() throws Exception {
         GuiceGenericLoader genericLoader = new GuiceGenericLoader(


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 01/04: JAMES-2866 Log additional modules

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 7752687fecd0071ee873620384b055659f9f240c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Oct 18 11:26:34 2019 +0700

    JAMES-2866 Log additional modules
---
 .../src/main/java/org/apache/james/utils/GuiceGenericLoader.java         | 1 +
 1 file changed, 1 insertion(+)

diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
index e87ebc2..d8ca52e 100644
--- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
+++ b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
@@ -98,6 +98,7 @@ public class GuiceGenericLoader {
         this.additionalExtensionBindings = Modules.combine(extensionConfiguration.getAdditionalGuiceModulesForExtensions()
             .stream()
             .map(Throwing.function(this::<Module>instantiateNoChildModule))
+            .peek(module -> LOGGER.info("Enabling injects contained in " + module.getClass().getCanonicalName()))
             .collect(Guavate.toImmutableList()));
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 03/04: JAMES-2866 singleton are not shared between extensions

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit fe58c21aa67aa32f9dc6fdb5e44a8a44ef46de1d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Oct 22 01:01:24 2019 +0200

    JAMES-2866 singleton are not shared between extensions
---
 .../apache/james/utils/GuiceMailetLoaderTest.java  |  22 +++++++++++++++++++++
 ...ustom-mailets-implementation-3.5.0-SNAPSHOT.jar | Bin 11147 -> 11069 bytes
 ...ailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar | Bin 30473134 -> 30057150 bytes
 .../james/transport/mailets/MyExtensionModule.java |   5 +++--
 .../james/transport/mailets/MyGenericMailet.java   |  17 ++++++++++++++++
 5 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
index b5333d6..e261c1a 100644
--- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
@@ -33,6 +33,7 @@ import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -183,4 +184,25 @@ public class GuiceMailetLoaderTest {
 
         assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException();
     }
+
+    @Ignore("JAMES-2866 singleton are not shared between extensions")
+    @Test
+    public void allMailetsShouldShareTheSameSingleton() throws Exception {
+        GuiceGenericLoader genericLoader = new GuiceGenericLoader(
+            Guice.createInjector(),
+            new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM),
+            new ExtensionConfiguration(ImmutableList.of(new ClassName("org.apache.james.transport.mailets.MyExtensionModule"))));
+        GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES);
+
+        Mailet mailet1 = guiceMailetLoader.getMailet(FakeMailetConfig.builder()
+            .mailetName("MyGenericMailet")
+            .mailetContext(FakeMailContext.defaultContext())
+            .build());
+        Mailet mailet2 = guiceMailetLoader.getMailet(FakeMailetConfig.builder()
+            .mailetName("MyGenericMailet")
+            .mailetContext(FakeMailContext.defaultContext())
+            .build());
+
+        assertThat(mailet1).isEqualTo(mailet2);
+    }
 }
diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar
index bd866d9..8dda0fc 100644
Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar differ
diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar
index 2f73d5b..1158dc5 100644
Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar differ
diff --git a/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
index cd6b70f..924a01d 100644
--- a/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
+++ b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
@@ -20,11 +20,12 @@
 package org.apache.james.transport.mailets;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
 
 public class MyExtensionModule extends AbstractModule {
     @Override
     protected void configure() {
-        bind(MyInterface.class)
-            .to(MyInterfaceImplementation.class);
+        bind(MyInterfaceImplementation.class).in(Scopes.SINGLETON);
+        bind(MyInterface.class).to(MyInterfaceImplementation.class);
     }
 }
diff --git a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
index a0e28d4..17c7039 100644
--- a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
+++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.transport.mailets;
 
+import java.util.Objects;
+
 import javax.inject.Inject;
 import javax.mail.MessagingException;
 
@@ -37,4 +39,19 @@ public class MyGenericMailet extends GenericMailet {
     public void service(Mail mail) throws MessagingException {
         myInterface.doSomething();
     }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof MyGenericMailet) {
+            MyGenericMailet that = (MyGenericMailet) o;
+
+            return Objects.equals(this.myInterface, that.myInterface);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(myInterface);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org