ctubbsii commented on a change in pull request #1715: URL: https://github.com/apache/accumulo/pull/1715#discussion_r518511817
########## File path: core/src/main/java/org/apache/accumulo/core/spi/common/ContextClassLoaderFactory.java ########## @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.accumulo.core.spi.common; + +import java.util.Map; +import java.util.function.Supplier; + +/** + * The ClassLoaderFactory is defined by the property general.context.factory. The factory + * implementation is configured externally to Accumulo and will return a ClassLoader for a given + * contextName. + * + * @since 2.1.0 + * + */ +public interface ContextClassLoaderFactory { + + /** + * Initialize the ClassLoaderFactory. Implementations may need a reference to the configuration so + * that it can clean up contexts that are no longer being used. + * + * @param contextProperties + * Accumulo configuration properties + * @throws Exception + * if error initializing ClassLoaderFactory + */ + void initialize(Supplier<Map<String,String>> contextProperties) throws Exception; Review comment: > Would still recommend the parameters interface as it gives more options for mutating the SPI in the future w/o causing pain to anyone who has taken the time to implement the interface. I think I would disagree with the need to create an evolve-able parameter type here. I don't think it's a good idea to support a dedicated parameter type because that implies we're constructing a framework that can evolve, on which complex subclass implementations can support being initialized based on internal Accumulo objects. That's antithetical to what we're trying to do here. This ClassloaderFactory is not your typical SPI (like sampling or iterators or balancers), where behavior is coupled to Accumulo functionality. Rather, classloading is something that should be done largely independently of Accumulo... as it is something on which other parts of Accumulo depend. Its initialization API should not itself depend on Accumulo objects that would be passed in using these parameter types, because that could create cyclical dependencies (Accumulo depends on classloader, which depends on Accumulo internal objects passed as parameters, which depends on classloader...). The only thing this interface needs from Accumulo is initial configuration, which just happens to be carried in Accumulo's own configuration files. We should merely pass that information along to this. We should never pass along any other internal state objects as parameters. Besides, the classloader factory should be instantiated *early*, before any meaningful state is generated in Accumulo. So, it should never have the opportunity to initialize based on internal Accumulo state anyway... just initial configuration files. So, I think it's a conscious decision to make the initialization parameter only a configuration mapping. It will ensure we keep the classloading stuff as decoupled as possible from Accumulo's internal workings, and merely responsible for providing classloaders that the rest of Accumulo can reliably depend on, based on the implementer's own independent criteria. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
