@@ -274,31 +274,46 @@ private GrpcTransportBuilder applyChannelInitializer(GrpcTransportBuilder builde
274274 builder = builder .addChannelInitializer (prov );
275275 } else if (initializer instanceof String ) {
276276 String className = (String ) initializer ;
277- if (!FQCN .matcher (className ).matches ()) {
278- throw new SQLException ("channelInitializer must be full class name or instance of "
279- + "Consumer<ManagedChannelBuilder>" );
280- }
281277
282- try {
283- Class <?> clazz = Class .forName (className );
284- if (!Consumer .class .isAssignableFrom (clazz )) {
285- throw new SQLException ("channelInitializer " + className + " is not implement "
278+ if (FQCN .matcher (className .trim ()).matches ()) {
279+ builder .addChannelInitializer (newInitializerInstance (className .trim ()));
280+ } else {
281+ String [] classNames = className .split ("," );
282+ if (classNames .length < 2 ) {
283+ throw new SQLException ("channelInitializer must be full class name or instance of "
286284 + "Consumer<ManagedChannelBuilder>" );
287285 }
288- @ SuppressWarnings ("unchecked" )
289- Consumer <Object > prov = clazz .asSubclass (Consumer .class )
290- .getConstructor (new Class <?>[0 ])
291- .newInstance (new Object [0 ]);
292- builder = builder .addChannelInitializer (prov );
293- } catch (ClassNotFoundException ex ) {
294- throw new SQLException ("channelInitializer " + className + " not found" , ex );
295- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
296- | IllegalArgumentException | InvocationTargetException ex ) {
297- throw new SQLException ("Cannot construct channelInitializer " + className , ex );
286+
287+ for (String name : classNames ) {
288+ if (!FQCN .matcher (name .trim ()).matches ()) {
289+ throw new SQLException ("channelInitializer must be full class name or instance of "
290+ + "Consumer<ManagedChannelBuilder>" );
291+ }
292+ builder .addChannelInitializer (newInitializerInstance (name .trim ()));
293+ }
298294 }
299295 } else if (initializer != null ) {
300296 throw new SQLException ("Cannot parse channelInitializer " + initializer .getClass ().getName ());
301297 }
302298 return builder ;
303299 }
300+
301+ @ SuppressWarnings ("unchecked" )
302+ private Consumer <Object > newInitializerInstance (String className ) throws SQLException {
303+ try {
304+ Class <?> clazz = Class .forName (className );
305+ if (!Consumer .class .isAssignableFrom (clazz )) {
306+ throw new SQLException ("channelInitializer " + className + " is not implement "
307+ + "Consumer<ManagedChannelBuilder>" );
308+ }
309+ return clazz .asSubclass (Consumer .class )
310+ .getConstructor (new Class <?>[0 ])
311+ .newInstance (new Object [0 ]);
312+ } catch (ClassNotFoundException ex ) {
313+ throw new SQLException ("channelInitializer " + className + " not found" , ex );
314+ } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
315+ | IllegalArgumentException | InvocationTargetException ex ) {
316+ throw new SQLException ("Cannot construct channelInitializer " + className , ex );
317+ }
318+ }
304319}
0 commit comments