package io.mycat.route.handler;

import java.util.HashMap;
import java.util.Map;

public class HintHandlerFactory {
	private static volatile boolean isInit = false;
	 //sql注释的类型处理handler 集合，现在支持两种类型的处理：sql,schema
    private static Map<String,HintHandler> hintHandlerMap = new HashMap<String,HintHandler>();

    private HintHandlerFactory() {
    }
    
    private static void init() {
        hintHandlerMap.put("sql",new HintSQLHandler());
        hintHandlerMap.put("schema",new HintSchemaHandler());
        hintHandlerMap.put("datanode",new HintDataNodeHandler());
        hintHandlerMap.put("catlet",new HintCatletHandler());
        isInit = true;	// 修复多次初始化的bug
    }
    
    // 双重校验锁 fix 线程安全问题
    public static HintHandler getHintHandler(String hintType) {
    	if(!isInit) {
    		synchronized(HintHandlerFactory.class){
    			if(!isInit)
    				init();
    		}
    	}
    	return hintHandlerMap.get(hintType);
    }
    
}

@@ -26,16 +26,53 @@
 ndler;%0A%0A
+import io.mycat.route.RouteService;%0A%0A
 import j
@@ -116,89 +116,222 @@
 p;%0A%0A
-public class HintHandlerFactory %7B%0A%09private static volatile boolean isInit = false
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport com.alibaba.fastjson.JSON;%0A%0Apublic class HintHandlerFactory %7B%0A%09private static final Logger LOGGER = LoggerFactory.getLogger(HintHandlerFactory.class)
 ;%0A%09 
@@ -356,31 +356,8 @@
 r %E9%9B%86%E5%90%88
-%EF%BC%8C%E7%8E%B0%E5%9C%A8%E6%94%AF%E6%8C%81%E4%B8%A4%E7%A7%8D%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%A4%84%E7%90%86%EF%BC%9Asql,schema
 %0A   
@@ -372,16 +372,25 @@
  static 
+volatile 
 Map%3CStri
@@ -427,42 +427,172 @@
  = n
-ew HashMap%3CString,HintHandler%3E();%0A
+ull;%0A    %0A    static%7B%0A    %09hintHandlerMap = new HashMap%3CString,HintHandler%3E();%0A    %09init();%09// %E9%87%8D%E6%9E%84fix %E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E9%97%AE%E9%A2%98%E5%92%8C%E9%87%8D%E5%A4%8D%E5%88%9D%E5%A7%8B%E5%8C%96%E9%87%8D%E5%A4%8Dnew HintHandler%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9B by digdeep@126.com%0A    %7D%0A    
 %0A   
@@ -925,251 +925,251 @@
     
-isInit = true;%09// %E4%BF%AE%E5%A4%8D%E5%A4%9A%E6%AC%A1%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84bug
+%0A        // /*#mycat:db_type=master*/, /*#mycat:db_type=slave*/
 %0A    
-%7D%0A
     
-%0A    // %E5%8F%8C%E9%87%8D%E6%A0%A1%E9%AA%8C%E9%94%81 fix %E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E9%97%AE%E9%A2%98%0A    public static HintHandler getHintHandler(String hintType) %7B%0A    %09if(!isInit) %7B%0A    %09%09synchronized(HintHandlerFactory.class)%7B%0A    %09%09%09if(!isInit)%0A    %09%09%09%09init();%0A    %09%09%7D%0A    %09%7D
+// %E5%BC%BA%E5%88%B6%E8%B5%B0 master %E5%92%8C %E5%BC%BA%E5%88%B6%E8%B5%B0 slave%0A        hintHandlerMap.put(%22db_type%22, new HintMasterDBHandler());%0A    %7D%0A    %0A    %0A    public static HintHandler getHintHandler(String hintType) %7B
 %0A   

重构HintHanlerFactory, fix 线程安全问题和重复初始化和重复new HintHandler的问题