kumaab commented on code in PR #447: URL: https://github.com/apache/ranger/pull/447#discussion_r1880999714
########## tagsync/src/main/java/org/apache/ranger/tagsync/ha/TagSyncHAInitializerImpl.java: ########## @@ -32,79 +27,84 @@ import org.apache.ranger.ha.service.HARangerService; import org.apache.ranger.ha.service.ServiceManager; import org.apache.ranger.tagsync.process.TagSyncConfig; -import org.apache.log4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class TagSyncHAInitializerImpl extends RangerHAInitializer { - private static final Logger LOG = Logger.getLogger(TagSyncHAInitializerImpl.class); - ActiveInstanceElectorService activeInstanceElectorService = null; - ActiveStateChangeHandler activeStateChangeHandler = null; - List<HARangerService> haRangerService = null; - ServiceManager serviceManager = null; - private static TagSyncHAInitializerImpl theInstance = null; - - private TagSyncHAInitializerImpl(Configuration configuration) { - if(LOG.isDebugEnabled()){ - LOG.info("==> TagSyncHAInitializerImpl.TagSyncHAInitializerImpl()"); - } - try { - LOG.info("Ranger TagSync server is HA enabled : "+configuration.getBoolean(TagSyncConfig.TAGSYNC_SERVER_HA_ENABLED_PARAM, false) ); - init(configuration); - } catch (Exception e) { - LOG.error("TagSyncHAInitializerImpl initialization failed", e); - } - if(LOG.isDebugEnabled()){ - LOG.info("<== TagSyncHAInitializerImpl.TagSyncHAInitializerImpl()"); - } - } - - public void init(Configuration configuration) throws Exception { - super.init(configuration); - LOG.info("==> TagSyncHAInitializerImpl.init() initialization started"); - Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders = new HashSet<ActiveStateChangeHandler>(); - activeInstanceElectorService = new ActiveInstanceElectorService(activeStateChangeHandlerProviders, - curatorFactory, activeInstanceState, serviceState, configuration); - - haRangerService = new ArrayList<HARangerService>(); - haRangerService.add(activeInstanceElectorService); - serviceManager = new ServiceManager(haRangerService); - LOG.info("<== TagSyncHAInitializerImpl.init() initialization completed"); - } - - - @Override - public void stop() { - if(LOG.isDebugEnabled()){ - LOG.debug("==> TagSyncHAInitializerImpl.stop() "); - } - if (serviceManager != null) { - serviceManager.stop(); - } - if(curatorFactory != null){ - curatorFactory.close(); - } - if(LOG.isDebugEnabled()){ - LOG.debug("<== TagSyncHAInitializerImpl.stop() "); - } - } - - public static TagSyncHAInitializerImpl getInstance(Configuration configuration) { - if(theInstance == null){ - synchronized(TagSyncHAInitializerImpl.class){ - if(theInstance == null){ - theInstance = new TagSyncHAInitializerImpl(configuration); - } - } - } - return theInstance; - } - public boolean isActive() { - try { - // To let the curator thread a chance to run and set the active state if needed - Thread.sleep(0L); - } catch (InterruptedException exception) { - // Ignore - } - return serviceState.getState().equals(ServiceState.ServiceStateValue.ACTIVE); - } + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TagSyncHAInitializerImpl.class); + private static volatile TagSyncHAInitializerImpl theInstance; + ActiveInstanceElectorService activeInstanceElectorService; + List<HARangerService> haRangerService; + ServiceManager serviceManager; + + private TagSyncHAInitializerImpl(Configuration configuration) { + LOG.debug("==> TagSyncHAInitializerImpl.TagSyncHAInitializerImpl()"); + + try { + LOG.info("Ranger TagSync server is HA enabled : {}", configuration.getBoolean(TagSyncConfig.TAGSYNC_SERVER_HA_ENABLED_PARAM, false)); + init(configuration); + } catch (Exception e) { + LOG.error("TagSyncHAInitializerImpl initialization failed", e); + } + + LOG.debug("<== TagSyncHAInitializerImpl.TagSyncHAInitializerImpl()"); + } + + public static TagSyncHAInitializerImpl getInstance(Configuration configuration) { + TagSyncHAInitializerImpl me = theInstance; + + if (me == null) { + synchronized (TagSyncHAInitializerImpl.class) { + me = theInstance; + + if (me == null) { + me = new TagSyncHAInitializerImpl(configuration); + theInstance = me; + } + } + } + + return me; + } + + public void init(Configuration configuration) throws Exception { + super.init(configuration); + LOG.info("==> TagSyncHAInitializerImpl.init() initialization started"); + Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders = new HashSet<>(); + activeInstanceElectorService = new ActiveInstanceElectorService(activeStateChangeHandlerProviders, Review Comment: please use single line here. -- 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: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org