/** * Creates a new factory and returns the instance * * @param actorSystem the actor system to use for mapping config + dynamicAccess * @param factoryClass the factory class scanned for factory functions * @param log the log adapter used for debug and warning logs * @return the new instance */ public static DefaultMessageMapperFactory of(final ActorSystem actorSystem, final Class<?> factoryClass, final DiagnosticLoggingAdapter log) { final Config mappingConfig = actorSystem.settings().config().getConfig("ditto.connectivity.mapping"); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); return new DefaultMessageMapperFactory(mappingConfig, dynamicAccess, factoryClass, log); }
/** * Creates a new factory and returns the instance * * @param actorSystem the actor system to use for mapping config + dynamicAccess * @param factoryClass the factory class scanned for factory functions * @param log the log adapter used for debug and warning logs * @return the new instance */ public static DefaultMessageMapperFactory of(final ActorSystem actorSystem, final Class<?> factoryClass, final DiagnosticLoggingAdapter log) { final Config mappingConfig = actorSystem.settings().config().getConfig("ditto.connectivity.mapping"); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); return new DefaultMessageMapperFactory(mappingConfig, dynamicAccess, factoryClass, log); }
/** * Load the configured protocol adapter provider by reflection. * Call the 1-argument constructor every subclass of {@link ProtocolAdapterProvider} should implement. * * @param actorSystem Akka actor system to perform reflection with. * @return the loaded protocol adapter provider. */ public ProtocolAdapterProvider loadProtocolAdapterProvider(final ActorSystem actorSystem) { final String className = provider(); final ClassTag<ProtocolAdapterProvider> tag = ClassTag$.MODULE$.apply(ProtocolAdapterProvider.class); final List<Tuple2<Class<?>, Object>> constructorArgs = Collections.singletonList(new Tuple2<>(getClass(), this)); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); final Try<ProtocolAdapterProvider> providerBox = dynamicAccess.createInstanceFor(className, JavaConverters.asScalaBuffer(constructorArgs).toList(), tag); return providerBox.get(); }
/** * Loads the {@link MappingStrategy} in the passed ActorSystem this is running in by looking up the config key * {@value CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION}. * * @param actorSystem the ActorSystem we are running in. * @return the resolved MappingStrategy. */ static MappingStrategy loadMappingStrategy(final ActorSystem actorSystem) { // load via config the class implementing MappingStrategy: final String mappingStrategyClass = actorSystem.settings().config().getString(CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION); final ClassTag<MappingStrategy> tag = scala.reflect.ClassTag$.MODULE$.apply(MappingStrategy.class); final List<Tuple2<Class<?>, Object>> constructorArgs = new ArrayList<>(); final Try<MappingStrategy> mappingStrategy = ((ExtendedActorSystem) actorSystem).dynamicAccess().createInstanceFor(mappingStrategyClass, JavaConversions.asScalaBuffer(constructorArgs).toList(), tag); return mappingStrategy.get(); }
/** * Loads the {@link MappingStrategy} in the passed ActorSystem this is running in by looking up the config key * {@value CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION}. * * @param actorSystem the ActorSystem we are running in. * @return the resolved MappingStrategy. */ static MappingStrategy loadMappingStrategy(final ActorSystem actorSystem) { // load via config the class implementing MappingStrategy: final String mappingStrategyClass = actorSystem.settings().config().getString(CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION); final ClassTag<MappingStrategy> tag = scala.reflect.ClassTag$.MODULE$.apply(MappingStrategy.class); final List<Tuple2<Class<?>, Object>> constructorArgs = new ArrayList<>(); final Try<MappingStrategy> mappingStrategy = ((ExtendedActorSystem) actorSystem).dynamicAccess().createInstanceFor(mappingStrategyClass, JavaConversions.asScalaBuffer(constructorArgs).toList(), tag); return mappingStrategy.get(); }