private synchronized void initialize ( ) { if ( this . runtimes != null ) { return ; } this . runtimes = new HashMap <> ( ) ; for ( final AvroRuntimeDefinition rd : runtimeDefinition . getRuntimes ( ) ) { try { // We need to create different injector for each runtime as they define conflicting bindings. Also we cannot // fork the original injector because of the same reason. // We create new injectors and copy form the original injector what we need. // rootInjector is an emptyInjector that we copy bindings from the original injector into. Then we fork // it to instantiate the actual runtime. final Injector rootInjector = Tang . Factory . getTang ( ) . newInjector ( ) ; initializeInjector ( rootInjector ) ; final Configuration runtimeConfig = Tang . Factory . getTang ( ) . newConfigurationBuilder ( ) . bindNamedParameter ( RuntimeName . class , rd . getRuntimeName ( ) . toString ( ) ) . bindImplementation ( Runtime . class , RuntimeImpl . class ) . build ( ) ; final Configuration config = new AvroConfigurationSerializer ( ) . fromString ( rd . getSerializedConfiguration ( ) . toString ( ) ) ; final Injector runtimeInjector = rootInjector . forkInjector ( config , runtimeConfig ) ; this . runtimes . put ( rd . getRuntimeName ( ) . toString ( ) , runtimeInjector . getInstance ( Runtime . class ) ) ; } catch ( final IOException | InjectionException e ) { throw new RuntimeException ( "Unable to initialize runtimes." , e ) ; } } }
Initializes the configured runtimes .