Re: Contribute multiple collections in the same service?
Thank you, In my case, MapConfig contributions can be reduced to HazelcastConfigurer contributions (and now I see I should have used the latter from the start) so (to avoid many refactorings) I created another service that converts MapConfig contributions to a HazelcastConfigurer. public class MapConfigServiceImpl implements MapConfigService { private final CollectionMapConfig mapConfigs; private final Logger logger; public MapConfigServiceImpl(CollectionMapConfig mapConfigs, Logger logger) { this.mapConfigs = mapConfigs; this.logger = logger; } @Override public HazelcastConfigurer getHazelcastConfigurer() { return new HazelcastConfigurer() { @Override public void configure(Config config) { for (MapConfig mapConfig : mapConfigs) { logger.info(Configuring map: + mapConfig.getName()); config.addMapConfig(mapConfig); } } }; } } And in the module: @Contribute(HazelcastConfigService.class) public static void contributeConfigurerForMapConfigs( MapConfigService mapConfigService, ConfigurationHazelcastConfigurer hzConfigurers) { hzConfigurers.add( mapConfigService.getHazelcastConfigurer() ); } On Tue, Jun 4, 2013 at 12:50 PM, Ferran Maylinch ferranmayli...@gmail.comwrote: Hello, I would like to contribute 2 collections to a service, but I am afraid Tapestry only supports one collection to be contributed. Am I right? My service constructor is like this: public HazelcastConfigServiceImpl( final CollectionMapConfig mapConfigs, final CollectionHazelcastConfigurer hzConfigurers) { ... } And I try to contribute the hzConfigurers this way: @Contribute(HazelcastConfigService.class) public static void contributeExecutorConfig(ConfigurationHazelcastConfigurer hzConfigurers) { hzConfigurers.add(new HazelcastConfigurer() { @Override public void configure(Config config) { config.addExecutorConfig( new ExecutorConfig(RankingsConstants.RANKINGS_EXECUTOR_SERVICE_NAME) .setCorePoolSize(5) .setMaxPoolSize(5) ); } }); } But I get this exception: Caused by: org.apache.tapestry5.ioc.util.UnknownValueException: Could not find a coercion from type com.mobivery.malcom.categories.rankings.workers.services.MalcomRankingsWorkersModule$1 to type com.hazelcast.config.MapConfig. It seems it is trying to insert my HazelcastConfigurer into the mapConfigs when it should go to the hzConfigurers. Thank you -- Ferran
Re: Contribute multiple collections in the same service?
You don't need the MapConfigService, you can use a serviceId (or a marker annotation) to disambiguate your HazelcastConfigurer instances. // serviceId = mapConfigHazelcastConfigurer public HazelcastConfigurer buildMapConfigHazelcastConfigurer(final CollectionMapConfig mapConfigs) { return new HazelcastConfigurer { public void configure(Config config) { for (MapConfig mapConfig : mapConfigs) { config.addMapConfig(mapConfig); } } }; } public void contributeMapConfigHazelcastConfigurer(ConfigurationHazelcastConfigurer config) { config.add(new MapConfig(...)); config.add(new MapConfig(...)); } public static void contributeHazelcastConfigService( ConfigurationHazelcastConfigurer config, @ServiceId(mapConfigHazelcastConfigurer) HazelcastConfigurer mapConfigHazelcastConfigurer { config.add(mapConfigHazelcastConfigurer); }
Contribute multiple collections in the same service?
Hello, I would like to contribute 2 collections to a service, but I am afraid Tapestry only supports one collection to be contributed. Am I right? My service constructor is like this: public HazelcastConfigServiceImpl( final CollectionMapConfig mapConfigs, final CollectionHazelcastConfigurer hzConfigurers) { ... } And I try to contribute the hzConfigurers this way: @Contribute(HazelcastConfigService.class) public static void contributeExecutorConfig(ConfigurationHazelcastConfigurer hzConfigurers) { hzConfigurers.add(new HazelcastConfigurer() { @Override public void configure(Config config) { config.addExecutorConfig( new ExecutorConfig(RankingsConstants.RANKINGS_EXECUTOR_SERVICE_NAME) .setCorePoolSize(5) .setMaxPoolSize(5) ); } }); } But I get this exception: Caused by: org.apache.tapestry5.ioc.util.UnknownValueException: Could not find a coercion from type com.mobivery.malcom.categories.rankings.workers.services.MalcomRankingsWorkersModule$1 to type com.hazelcast.config.MapConfig. It seems it is trying to insert my HazelcastConfigurer into the mapConfigs when it should go to the hzConfigurers. Thank you -- Ferran
Re: Contribute multiple collections in the same service?
Yes, this is a limitation of tapestry contributions. This can be worked around. Create a MapConfigProvider service which has a getter for the MapConfig collection. Contribute MapConfig objects to the MapConfigProvider. Then pass the MapConfigProvider and the second collection to your HazelcastConfigServiceImpl.
Re: Contribute multiple collections in the same service?
There's a huge complexity cost for allowing a single service to expose multiple configurations, and its rare to need. Often, a solution that breaks the single service into two (or more) services, even if just to support the constraint of a single configuration, leads to better, more testable code anyway. On Tue, Jun 4, 2013 at 6:53 AM, Lance Java lance.j...@googlemail.comwrote: Yes, this is a limitation of tapestry contributions. This can be worked around. Create a MapConfigProvider service which has a getter for the MapConfig collection. Contribute MapConfig objects to the MapConfigProvider. Then pass the MapConfigProvider and the second collection to your HazelcastConfigServiceImpl. -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com