测试

六眼飞鱼酱① 提交于 2019-11-27 12:04:32
public class TransportClientFactory implements FactoryBean<TransportClient>,InitializingBean,DisposableBean {


    private String clusterName;

    private String host;

    private String xpacksecurityuser;

    private int port;

    private TransportClient client;


    @Override
    public void afterPropertiesSet() throws Exception {
        Settings settings = Settings.builder()
                .put("cluster.name", clusterName)
                .put("xpack.security.user", xpacksecurityuser)
                .put("client.transport.sniff", false)
                .build();
        client=new PreBuiltXPackTransportClient(settings).addTransportAddress(new InetSocketTransportAddress( InetAddress.getByName(host),port));
    }

    @Override
    public TransportClient getObject() throws Exception {
        return client;
    }

    public void setClusterName(String clusterName) {
        this.clusterName = clusterName;
    }

    public void setHost(String host) {
        this.host = host;
    }
    public void setXpacksecurityuser(String xpacksecurityuser) {
        this.xpacksecurityuser = xpacksecurityuser;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public void destroy() throws Exception {
        if(client!=null)
            client.close();

    }
    @Override
    public Class<?> getObjectType() {
        return TransportClient.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!