dasahcc commented on a change in pull request #729: Implement Helix API for updating customized state URL: https://github.com/apache/helix/pull/729#discussion_r379066208
########## File path: helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProviderFactory.java ########## @@ -0,0 +1,81 @@ +package org.apache.helix.customizedstate; + +/* + * 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. + */ + +import java.util.HashMap; +import org.apache.helix.HelixException; +import org.apache.helix.HelixManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Singleton factory that build customized state provider. + */ +public class CustomizedStateProviderFactory { + private static Logger LOG = LoggerFactory.getLogger(CustomizedStateProvider.class); + private final HashMap<String, CustomizedStateProvider> _customizedStateProviderMap = + new HashMap<>(); + private HelixManager _helixManager; + + protected CustomizedStateProviderFactory() { + } + + private static class SingletonHelper { + private static final CustomizedStateProviderFactory INSTANCE = + new CustomizedStateProviderFactory(); + } + + public static CustomizedStateProviderFactory getInstance() { + return SingletonHelper.INSTANCE; + } + + public CustomizedStateProvider buildCustomizedStateProvider(String instanceName) { + if (_helixManager == null) { + throw new HelixException("Helix Manager has not been set yet."); + } else { + return buildCustomizedStateProvider(_helixManager, instanceName); + } + } + + /** + * Build a customized state provider based on the specified input. If the instance already has a + * provider, return it. Otherwise, build a new one and put it in the map. + * @param helixManager The helix manager that belongs to the instance + * @param instanceName The name of the instance + * @return CustomizedStateProvider + */ + public CustomizedStateProvider buildCustomizedStateProvider(HelixManager helixManager, + String instanceName) { + synchronized (_customizedStateProviderMap) { + if (_customizedStateProviderMap.get(instanceName) != null) { + return _customizedStateProviderMap.get(instanceName); + } else { Review comment: Same here. Remove else clause. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org