@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); }
@Override public Mailet getMailet(MailetConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMailetName()); Mailet result = genericLoader.<Mailet>withNamingSheme(MAILET_NAMING_SCHEME) .instantiate(className); result.init(resolveConfiguration(result, config)); return result; } catch (Exception e) { throw new MessagingException("Can not load mailet " + config.getMailetName(), e); } }
GuiceMailetLoader implements MailetLoader { @Override public Mailet getMailet(MailetConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMailetName()); Mailet result = genericLoader.<Mailet>withNamingSheme(MAILET_NAMING_SCHEME) .instantiate(className); result.init(resolveConfiguration(result, config)); return result; } catch (Exception e) { throw new MessagingException("Can not load mailet " + config.getMailetName(), e); } } }
GuiceMailetLoader implements MailetLoader { @Override public Mailet getMailet(MailetConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMailetName()); Mailet result = genericLoader.<Mailet>withNamingSheme(MAILET_NAMING_SCHEME) .instantiate(className); result.init(resolveConfiguration(result, config)); return result; } catch (Exception e) { throw new MessagingException("Can not load mailet " + config.getMailetName(), e); } } @Inject  GuiceMailetLoader(GuiceGenericLoader genericLoader, Set<MailetConfigurationOverride> mailetConfigurationOverrides); }
GuiceMailetLoader implements MailetLoader { @Override public Mailet getMailet(MailetConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMailetName()); Mailet result = genericLoader.<Mailet>withNamingSheme(MAILET_NAMING_SCHEME) .instantiate(className); result.init(resolveConfiguration(result, config)); return result; } catch (Exception e) { throw new MessagingException("Can not load mailet " + config.getMailetName(), e); } } @Inject  GuiceMailetLoader(GuiceGenericLoader genericLoader, Set<MailetConfigurationOverride> mailetConfigurationOverrides); @Override Mailet getMailet(MailetConfig config); }
GuiceMailetLoader implements MailetLoader { @Override public Mailet getMailet(MailetConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMailetName()); Mailet result = genericLoader.<Mailet>withNamingSheme(MAILET_NAMING_SCHEME) .instantiate(className); result.init(resolveConfiguration(result, config)); return result; } catch (Exception e) { throw new MessagingException("Can not load mailet " + config.getMailetName(), e); } } @Inject  GuiceMailetLoader(GuiceGenericLoader genericLoader, Set<MailetConfigurationOverride> mailetConfigurationOverrides); @Override Mailet getMailet(MailetConfig config);  }