当前位置: 首页>>代码示例>>Java>>正文


Java InetSocketTransportAddress类代码示例

本文整理汇总了Java中org.elasticsearch.common.transport.InetSocketTransportAddress的典型用法代码示例。如果您正苦于以下问题:Java InetSocketTransportAddress类的具体用法?Java InetSocketTransportAddress怎么用?Java InetSocketTransportAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InetSocketTransportAddress类属于org.elasticsearch.common.transport包,在下文中一共展示了InetSocketTransportAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getElasticClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
private TransportClient getElasticClient() {
        try {
            // un-command this, if you have multiple node
//            TransportClient client1 = new PreBuiltTransportClient(Settings.EMPTY)
//                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
//                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300));

            Settings setting = Settings.builder()
                    .put("cluster.name", elasticPro.getProperty("cluster"))
                    .put("client.transport.sniff", Boolean.valueOf(elasticPro.getProperty("transport.sniff"))).build();

            client = new PreBuiltTransportClient(setting)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticPro.getProperty("host")), Integer.valueOf(elasticPro.getProperty("port"))));
        } catch (UnknownHostException ex) {
            log.error("Exception occurred while getting Client : " + ex, ex);
        }
        return client;
    }
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:19,代码来源:ElasticSearchClient.java

示例2: createClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
private TransportClient createClient() {
    Config cfg = getTypeCfg();
    Settings settings = Settings.builder().put("cluster.name", cfg.getString("elastic.cluster-name")).build();
    TransportClient client = new PreBuiltTransportClient(settings);

    List<String> servers = cfg.getStringList("elastic.servers");
    logger.debug(marker, "Elastic Servers: {}", servers);
    for (String addr : servers) {
        try {
            String[] a = addr.split(":");
            String host = a[0];
            int port = Integer.parseInt(a[1]);
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
        } catch (Exception e) {
            logger.error(marker, "Transport client creation failed for '{}'", addr, e);
        }
    }

    return client;
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:21,代码来源:ElasticClient.java

示例3: getClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
public static TransportClient getClient() {
    try {
        if (tclient == null) {
            String EsHosts = "192.168.1.41:9300,192.168.1.42:9300,192.168.1.43:9300";
            Settings settings = Settings.settingsBuilder()
                    .put("cluster.name", "dkes")//设置集群名称
                    .put("tclient.transport.sniff", true).build();//自动嗅探整个集群的状态,把集群中其它机器的ip地址加到客户端中

            tclient = TransportClient.builder().settings(settings).build();
            String[] nodes = EsHosts.split(",");
            for (String node : nodes) {
                if (node.length() > 0) {//跳过为空的node(当开头、结尾有逗号或多个连续逗号时会出现空node)
                    String[] hostPort = node.split(":");
                    tclient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1])));

                }
            }
        }//if
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tclient;
}
 
开发者ID:hs-web,项目名称:hsweb-learning,代码行数:24,代码来源:EsClient.java

示例4: wildcardQuery

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * wildcard查询/or条件/and条件
 */
public static void wildcardQuery() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.94"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("sqd.es_start");

        // {"query": {"bool": {"must": [{"or": [{"wildcard": {"content": "*oracle*"}},{"wildcard": {"content": "*mysql*"}}]}],"must_not": [],"should": []}},"from": 0, "size": 10, "sort": [],"aggs": {}}
        SearchResponse searchResponse = searchRequestBuilder.
                setQuery(QueryBuilders.boolQuery()
                .must(QueryBuilders.orQuery(QueryBuilders.wildcardQuery("content","*mysql*"),
                        QueryBuilders.wildcardQuery("content","*oracle*")))
                .must(QueryBuilders.termQuery("tbool","false")))
                .setFrom(0).setSize(100).setExplain(true).execute().actionGet();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
        for (int i = 0; i < searchHits.getHits().length; ++i) {
            System.out.println("content is "
                    + searchHits.getHits()[i].getSource().get("content"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:31,代码来源:SearchES.java

示例5: multisearch

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * 多字段查询
 */
public static void multisearch() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.93"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("service2","clients");
        SearchResponse searchResponse = searchRequestBuilder.
                setQuery(QueryBuilders.boolQuery()
                        .should(QueryBuilders.termQuery("id","5"))
                        .should(QueryBuilders.prefixQuery("content","oracle")))
                .setFrom(0).setSize(100).setExplain(true).execute().actionGet();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:24,代码来源:SearchES.java

示例6: getClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
public TransportClient getClient()   {
    if (esClient == null) {
        synchronized (this) {
            if (esClient == null) {
                try {
                    //判断配置
                    Preconditions.checkNotNull(clusterName, "es 服务clusterName未配置");
                    Preconditions.checkNotNull(addresses, "es 服务ip未配置");
                    //Preconditions.checkArgument(esPort > 0, "es 服务服务port未配置");
                    //设置集群的名字
                    Settings settings = Settings.settingsBuilder().put("client.node", true).put("cluster.name", clusterName).put("client.transport.sniff", sniff).build();
                    //Settings settings = Settings.settingsBuilder().put("client.transport.sniff", sniff).build();
                    //创建集群client并添加集群节点地址
                    esClient = TransportClient.builder().settings(settings).build();
                    for (String address : addresses) {
                        String[] inetAddress = address.split(":");
                        esClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(inetAddress[0]), new Integer(inetAddress[1])));
                    }
                  }catch (Exception e){
                     LOGGER.error("客户端连接初始化异常",e);
                }
            }
        }
    }
    return esClient;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:27,代码来源:EshClientFactory.java

示例7: ElasticsearchClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * create a elasticsearch transport client (remote elasticsearch)
 * @param addresses an array of host:port addresses
 * @param clusterName
 */
public ElasticsearchClient(final String[] addresses, final String clusterName) {
    // create default settings and add cluster name
    Settings.Builder settings = Settings.builder()
            .put("cluster.routing.allocation.enable", "all")
            .put("cluster.routing.allocation.allow_rebalance", "always");
    if (clusterName != null) settings.put("cluster.name", clusterName);
    
    // create a client
    TransportClient tc = new PreBuiltTransportClient(settings.build());

    for (String address: addresses) {
        String a = address.trim();
        int p = a.indexOf(':');
        if (p >= 0) try {
            InetAddress i = InetAddress.getByName(a.substring(0, p));
            int port = Integer.parseInt(a.substring(p + 1));
            tc.addTransportAddress(new InetSocketTransportAddress(i, port));
        } catch (UnknownHostException e) {
            Data.logger.warn("", e);
        }
    }
    this.elasticsearchClient = tc;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:29,代码来源:ElasticsearchClient.java

示例8: get

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * TransportClient provider.
 * @return TransportClient
 */
public TransportClient get() {
  final String hostCsv = configuration.getString(CONFIG_ES_CLUSTER_HOST);
  final List<String> hosts = Splitter.on(",").splitToList(hostCsv);
  Preconditions.checkState(!hosts.isEmpty());

  final TransportClient transportClient = new PreBuiltTransportClient(esSettings());
  final Integer esTransportPort = configuration.getInteger(CONFIG_ES_CLUSTER_PORT, 9300);
  log.info("connect to elastic search {} on port {} ", hostCsv, esTransportPort);

  hosts.forEach(
      host -> transportClient.addTransportAddress(
          new InetSocketTransportAddress(new InetSocketAddress(host, esTransportPort))
      )
  );

  return transportClient;
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:22,代码来源:TransportClientProvider.java

示例9: connect

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
@Override
public TransportClient connect() {
    Settings settings = Settings.builder()
        .put("cluster.name", "elasticsearch")
        .put("client.transport.sniff", true).build();       
    
    try {
        client = new PreBuiltTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst01.as.it.ubc.ca"), 9300))
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst02.as.it.ubc.ca"), 9300));        
    } catch (UnknownHostException uhe) {
        logger.error(uhe.toString());
    }
    
    return client;
}
 
开发者ID:armenak,项目名称:uDetective,代码行数:17,代码来源:ElasticSearchDataSource.java

示例10: jsonquery

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * json查询
 */
public static void jsonquery() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.93"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("service2");
        SearchResponse searchResponse = searchRequestBuilder.setSource("{\n" +
                "\"query\": {\n" +
                "\"bool\": {\n" +
                "\"must\": [\n" +
                "{\n" +
                "\"prefix\": {\n" +
                "\"content\": \"oracle\"\n" +
                "}\n" +
                "}\n" +
                "],\n" +
                "\"must_not\": [ ],\n" +
                "\"should\": [ ]\n" +
                "}\n" +
                "},\n" +
                "\"from\": 0,\n" +
                "\"size\": 10,\n" +
                "\"sort\": [ ],\n" +
                "\"aggs\": { }\n" +
                "}")
                .get();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
        for (int i = 0; i < searchHits.getHits().length; ++i) {
            System.out.println("content is "
                    + searchHits.getHits()[i].getSource().get("content"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:43,代码来源:SearchES.java

示例11: main

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    Log4jESLoggerFactory.getRootLogger().setLevel("ERROR");
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "ciphergateway").build();
    //Use one and only one Client in your JVM. It's threadsafe.
    Client client = new TransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

    Long start = System.currentTimeMillis();
//    exportES(client);
//    deleteES(client);
//    importES(client);
//    searchES(client);
    exportAndDeleteES(client);
    client.close();
    Long end = System.currentTimeMillis();
    System.out.println("用时: " + (end - start) + " ms");
  }
 
开发者ID:MoneZhao,项目名称:elasticsearch,代码行数:18,代码来源:App.java

示例12: ElasticSearchConnection

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
public ElasticSearchConnection(String jdbcUrl) {


        Settings settings = Settings.builder().put("client.transport.ignore_cluster_name", true).build();
        try {
            TransportClient transportClient = new PreBuiltTransportClient(settings);

            String hostAndPortArrayStr = jdbcUrl.split("/")[2];
            String[] hostAndPortArray = hostAndPortArrayStr.split(",");

            for (String hostAndPort : hostAndPortArray) {
                String host = hostAndPort.split(":")[0];
                String port = hostAndPort.split(":")[1];
                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), Integer.parseInt(port)));
            }
            client = transportClient;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:ElasticSearchConnection.java

示例13: build

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
/**
 * Builds the {@link MaprElasticSearchService} according to the specified properties.
 *
 * @return instence of {@link MaprElasticSearchService}, which can be started via {@link MaprElasticSearchService#start()}.
 * @throws IllegalStateException in case when some of the required properties are missed.
 */
public MaprElasticSearchService build() {

    ensureFieldNonNull("port", this.port);
    ensureFieldNonNull("hostname", this.inetAddress);
    ensureFieldNonNull("indexName", this.indexName);
    ensureFieldNonNull("typeName", this.typeName);
    ensureFieldNonNull("changelog", this.changelog);
    ensureFieldNonNull("fields", this.fields);

    return () -> {

        // Create ES Client
        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new InetSocketTransportAddress(inetAddress, port));

        // Create CDC Listener
        ChangelogListener listener = ChangelogListenerImpl.forChangelog(changelog);

        // Set 'onInsert' callback
        listener.onInsert(new SaveIndexCDCCallback(client));

        // Set 'onUpdate' callback
        listener.onUpdate(new SaveIndexCDCCallback(client));

        // Define and set 'onDelete' callback
        listener.onDelete((id) -> client.prepareDelete(indexName, typeName, id).get());

        listener.listen();

    };
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:38,代码来源:MaprElasticSearchServiceBuilder.java

示例14: createTransportClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
private static TransportClient createTransportClient(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        Settings.Builder settingsBuilder = Settings.builder();
        if (config.getClusterName() != null) {
            settingsBuilder.put("cluster.name", config.getClusterName());
        }
        for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
            settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
        }
        settings = settingsBuilder.build();
    }
    TransportClient transportClient = new PreBuiltTransportClient(settings);
    for (String esLocation : config.getEsLocations()) {
        String[] locationSocket = esLocation.split(":");
        String hostname;
        int port;
        if (locationSocket.length == 2) {
            hostname = locationSocket[0];
            port = Integer.parseInt(locationSocket[1]);
        } else if (locationSocket.length == 1) {
            hostname = locationSocket[0];
            port = config.getPort();
        } else {
            throw new MemgraphException("Invalid elastic search location: " + esLocation);
        }
        InetAddress host;
        try {
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException ex) {
            throw new MemgraphException("Could not resolve host: " + hostname, ex);
        }
        transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
    }
    return transportClient;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:37,代码来源:Elasticsearch5SearchIndex.java

示例15: initESClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //导入依赖的package包/类
@Bean
public TransportClient initESClient() throws NumberFormatException, UnknownHostException{
	String ip = env.getProperty("spring.es.ip");
	String port = env.getProperty("spring.es.port");
	String clusterName = env.getProperty("spring.es.cluster_name");
	
	Builder builder = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", true);
	Settings esSettings = builder.build();
	TransportClient client = new PreBuiltTransportClient(esSettings);
	client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.parseInt(port)));
	logger.info("ES Client 初始化成功, ip : {}, port : {}, cluster_name : {}", ip, port, clusterName);
	return client;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:14,代码来源:ElasticsearchConfiguration.java


注:本文中的org.elasticsearch.common.transport.InetSocketTransportAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。