| 
					
				 | 
			
			
				@ -19,6 +19,7 @@ import java.util.Arrays; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 中山医院版本 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by chenweida on 2017/6/5. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -34,6 +35,8 @@ public class ElasticFactory { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String clusterName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${es.securityUser}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String securityUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${es.pwflag}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String pwflag; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//-----------------------------------jestClient---------------------------------------- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -75,7 +78,12 @@ public class ElasticFactory { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Client getTransportClient() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            initTranClient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //1需要加密初始化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if("1".equals(pwflag)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                initTranClientPw(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                initTranClient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return transportClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -85,37 +93,36 @@ public class ElasticFactory { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 9300 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 互联网医院版本需要密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws UnknownHostException 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private synchronized void initTranClient() throws UnknownHostException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        if (transportClient == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            String[] hosts = tHost.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            Settings settings = Settings.settingsBuilder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    // .put("client.transport.sniff", true)//开启嗅探功能 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            transportClient = TransportClient.builder().settings(settings).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            for (String oneHost : hosts) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                String[] hostAndport = oneHost.split(":"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1]))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private synchronized void initTranClientPw() throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (transportClient == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] hosts = tHost.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Settings settings = getSettings(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            transportClient = TransportClient.builder().addPlugin(ShieldPlugin.class).settings(settings).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String oneHost : hosts) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] hostAndport = oneHost.split(":"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1]))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 9300 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 厦门I健康版本不需要密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws UnknownHostException 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private synchronized void initTranClient() throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private synchronized void initTranClient() throws UnknownHostException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (transportClient == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] hosts = tHost.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Settings settings = getSettings(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            transportClient = TransportClient.builder().addPlugin(ShieldPlugin.class).settings(settings).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Settings settings = Settings.settingsBuilder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    // .put("client.transport.sniff", true)//开启嗅探功能 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            transportClient = TransportClient.builder().settings(settings).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String oneHost : hosts) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] hostAndport = oneHost.split(":"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1]))); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -123,6 +130,7 @@ public class ElasticFactory { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 配置连接 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -136,5 +144,6 @@ public class ElasticFactory { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        settingBuilder.put("transport.address.list", tHost); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return settingBuilder.build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 |