smiklosovic commented on code in PR #4513:
URL: https://github.com/apache/cassandra/pull/4513#discussion_r2621025562
##########
src/java/org/apache/cassandra/schema/CompressionParams.java:
##########
@@ -348,6 +365,48 @@ public static ICompressor
createCompressor(ParameterizedClass compression) throw
return createCompressor(parseCompressorClass(compression.class_name),
copyOptions(compression.parameters));
}
+ /**
+ * Creates a decorated compressor, if compression service providers
available in the classpath or
+ * returns the base compressor
+ * @param baseCompressor compressor being decorated
+ * @param options compression options of baseCompressor
+ * @return returns a decorated compressor, if service available, otherwise
baseCompressor
+ */
+ private static ICompressor decorateCompressor(ICompressor baseCompressor,
Map<String, String> options)
Review Comment:
I think this might be way simplified
````
private static ICompressor decorateCompressor(ICompressor
baseCompressor, Map<String, String> options)
{
return Optional.ofNullable(baseCompressor)
.flatMap(c ->
ServiceLoader.load(ICompressorFactory.class)
.stream()
.map(ServiceLoader.Provider::get)
.filter(factory->
c.getClass().getSimpleName()
.equals(factory.getSupportedCompressorName()))
.findFirst())
.flatMap(factory -> factory.createCompressor(options))
.map(pluginCompressor -> new
CompressorDecorator(baseCompressor, pluginCompressor))
.orElse(null);
}
````
We can get rid of getServiceProviderFactory completely. Just return
`Optional<ICompressor>` from factory's `createCompressor`. You are just
catching that exception here and logging, you can do same in the implementation
and return empty optional instead if not possible to instantiate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]