@@ -58,14 +58,15 @@ private DataLoaderRegistry(Builder builder) {
5858 }
5959
6060 protected DataLoaderRegistry (Map <String , DataLoader <?, ?>> dataLoaders , @ Nullable DataLoaderInstrumentation instrumentation , DispatchStrategy dispatchStrategy ) {
61- this .dataLoaders = instrumentDLs (dataLoaders , instrumentation );
61+ this .dataLoaders = instrumentDLs (dataLoaders , instrumentation , dispatchStrategy );
6262 this .instrumentation = instrumentation ;
6363 this .dispatchStrategy = dispatchStrategy ;
64+ dispatchStrategy .onRegistryCreation (this );
6465 }
6566
66- private Map <String , DataLoader <?, ?>> instrumentDLs (Map <String , DataLoader <?, ?>> incomingDataLoaders , @ Nullable DataLoaderInstrumentation registryInstrumentation ) {
67+ private Map <String , DataLoader <?, ?>> instrumentDLs (Map <String , DataLoader <?, ?>> incomingDataLoaders , @ Nullable DataLoaderInstrumentation registryInstrumentation , DispatchStrategy dispatchStrategy ) {
6768 Map <String , DataLoader <?, ?>> dataLoaders = new ConcurrentHashMap <>(incomingDataLoaders );
68- if (registryInstrumentation != null ) {
69+ if (registryInstrumentation != null || dispatchStrategy != DispatchStrategy . NO_OP ) {
6970 dataLoaders .replaceAll ((k , existingDL ) -> nameAndInstrumentDL (k , registryInstrumentation , existingDL , dispatchStrategy ));
7071 }
7172 return dataLoaders ;
@@ -83,7 +84,7 @@ protected DataLoaderRegistry(Map<String, DataLoader<?, ?>> dataLoaders, @Nullabl
8384 private static DataLoader <?, ?> nameAndInstrumentDL (String key , @ Nullable DataLoaderInstrumentation registryInstrumentation , DataLoader <?, ?> existingDL , DispatchStrategy dispatchStrategy ) {
8485 existingDL = checkAndSetName (key , existingDL );
8586
86- if (registryInstrumentation == null ) {
87+ if (registryInstrumentation == null && dispatchStrategy == DispatchStrategy . NO_OP ) {
8788 return existingDL ;
8889 }
8990 DataLoaderOptions options = existingDL .getOptions ();
@@ -120,12 +121,17 @@ protected DataLoaderRegistry(Map<String, DataLoader<?, ?>> dataLoaders, @Nullabl
120121 return dataLoader ;
121122 }
122123
123- private static DataLoader <?, ?> mkInstrumentedDataLoader (DataLoader <?, ?> existingDL , DataLoaderOptions options , DataLoaderInstrumentation newInstrumentation , DispatchStrategy dispatchStrategy ) {
124+ private static DataLoader <?, ?> mkInstrumentedDataLoader (DataLoader <?, ?> existingDL , DataLoaderOptions options , @ Nullable DataLoaderInstrumentation newInstrumentation , DispatchStrategy dispatchStrategy ) {
124125 return existingDL .transform (builder -> builder .options (setInInstrumentation (options , newInstrumentation , dispatchStrategy )));
125126 }
126127
127- private static DataLoaderOptions setInInstrumentation (DataLoaderOptions options , DataLoaderInstrumentation newInstrumentation , DispatchStrategy dispatchStrategy ) {
128- return options .transform (optionsBuilder -> optionsBuilder .setInstrumentation (newInstrumentation ).setDispatchStrategy (dispatchStrategy ));
128+ private static DataLoaderOptions setInInstrumentation (DataLoaderOptions options , @ Nullable DataLoaderInstrumentation newInstrumentation , DispatchStrategy dispatchStrategy ) {
129+ return options .transform (optionsBuilder -> {
130+ optionsBuilder .setDispatchStrategy (dispatchStrategy );
131+ if (newInstrumentation != null ) {
132+ optionsBuilder .setInstrumentation (newInstrumentation );
133+ }
134+ });
129135 }
130136
131137 /**
0 commit comments