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


Java TransportClient.addTransportAddress方法代码示例

本文整理汇总了Java中org.elasticsearch.client.transport.TransportClient.addTransportAddress方法的典型用法代码示例。如果您正苦于以下问题:Java TransportClient.addTransportAddress方法的具体用法?Java TransportClient.addTransportAddress怎么用?Java TransportClient.addTransportAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.client.transport.TransportClient的用法示例。


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

示例1: createClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的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

示例2: ElasticsearchClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的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

示例3: ElasticSearchConnection

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的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

示例4: createTransportClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的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

示例5: initESClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的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

示例6: openClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
/**
 * Open client to elaticsearch cluster
 * 
 * @param clusterName
 */
private void openClient(String clusterName) {
  logger.info("Using ElasticSearch hostnames: {} ",
      Arrays.toString(serverAddresses));
  Settings settings = Settings.builder().put("cluster.name", clusterName).build();;

  TransportClient transportClient = TransportClient.builder().settings(settings).build();
  for (InetSocketTransportAddress host : serverAddresses) {
    transportClient.addTransportAddress(host);
  }
  if (client != null) {
    client.close();
  }
  client = transportClient;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:ElasticSearchTransportClient.java

示例7: makeClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
/**
 * Generates a TransportClient or NodeClient
 *
 * @param props a populated {@link java.util.Properties} object
 * @return a constructed {@link org.elasticsearch.client.Client}
 * @throws IOException if there is an error building the
 *                     {@link org.elasticsearch.client.Client}
 */
protected Client makeClient(Properties props) throws IOException {
  String clusterName = props.getProperty(MudrodConstants.ES_CLUSTER);
  String hostsString = props.getProperty(MudrodConstants.ES_UNICAST_HOSTS);
  String[] hosts = hostsString.split(",");
  String portStr = props.getProperty(MudrodConstants.ES_TRANSPORT_TCP_PORT);
  int port = Integer.parseInt(portStr);

  Settings.Builder settingsBuilder = Settings.builder();

  // Set the cluster name and build the settings
  if (!clusterName.isEmpty())
    settingsBuilder.put("cluster.name", clusterName);

  settingsBuilder.put("http.type", "netty3");
  settingsBuilder.put("transport.type", "netty3");

  Settings settings = settingsBuilder.build();

  Client client = null;

  // Prefer TransportClient
  if (hosts != null && port > 1) {
    TransportClient transportClient = new ESTransportClient(settings);
    for (String host : hosts)
      transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
    client = transportClient;
  } else if (clusterName != null) {
    node = new Node(settings);
    client = node.client();
  }

  return client;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:42,代码来源:ESDriver.java

示例8: transportClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Bean
public TransportClient transportClient(Settings settings) {
    TransportClient client = TransportClient.builder().settings(settings).build();
    for (String ip : this.esProperties.getIps().split(Constants.COMMA)) {
        try {
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), this.esProperties.getPort()));
        } catch (UnknownHostException e) {
            LOGGER.error("es集群主机名错误, ip: {}", ip);
        }
    }
    return client;
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:13,代码来源:EsConfiguration.java

示例9: clientIsCalledWhenBatchItemIsAdded

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
    public void clientIsCalledWhenBatchItemIsAdded() {

        // given
        Builder builder = createTestObjectFactoryBuilder();
        ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

//        Settings settings = Settings.builder().put("node.local", "true").build();
        Settings settings = Settings.builder().build();
        TransportClient client = spy(new PreBuiltTransportClient(settings));
        client.addTransportAddress(new LocalTransportAddress("1"));
        when(config.createClient()).thenReturn(client);

        FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

        BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
        BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
                        1,
                        100,
                        config,
                        failoverPolicy);

        String payload1 = "test1";
        ActionRequest testRequest = createTestRequest(payload1);

        // when
        batchEmitter.add(testRequest);

        // then
        ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
        verify(client, times(1)).bulk(captor.capture(), Mockito.any());

        assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
    }
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:35,代码来源:BulkProcessorObjectFactoryTest.java

示例10: failoverIsExecutedAfterNonSuccessfulRequest

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
    public void failoverIsExecutedAfterNonSuccessfulRequest() {

        // given
        Builder builder = createTestObjectFactoryBuilder();
        ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

        FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
        Function handler = spy(config.createFailureHandler(failoverPolicy));
        when(config.createFailureHandler(any())).thenReturn(handler);

//        Settings settings = Settings.builder().put("node.local", "true").build();
        Settings settings = Settings.builder().build();
        TransportClient client = spy(new PreBuiltTransportClient(settings));
        client.addTransportAddress(new LocalTransportAddress("1"));
        when(config.createClient()).thenReturn(client);

        BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
        BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
                1,
                100,
                config,
                failoverPolicy);

        String payload1 = "test1";
        ActionRequest testRequest = createTestRequest(payload1);

        // when
        batchEmitter.add(testRequest);

        // then
        ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
        verify(handler, times(1)).apply(captor.capture());

        assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
    }
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:37,代码来源:BulkProcessorObjectFactoryTest.java

示例11: clientIsCalledWhenBatchItemIsAdded

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
public void clientIsCalledWhenBatchItemIsAdded() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    Settings settings = Settings.builder()
            .put("node.local", true)
            .build();

    TransportClient client = spy(TransportClient.builder().settings(settings).build());
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
                    1,
                    100,
                    config,
                    failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(client, times(1)).bulk(captor.capture(), Mockito.any());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:37,代码来源:BulkProcessorObjectFactoryTest.java

示例12: failoverIsExecutedAfterNonSuccessfulRequest

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
public void failoverIsExecutedAfterNonSuccessfulRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
    Function handler = spy(config.createFailureHandler(failoverPolicy));
    when(config.createFailureHandler(any())).thenReturn(handler);

    Settings settings = Settings.builder().put("node.local", "true").build();
    TransportClient client = spy(TransportClient.builder().settings(settings).build());
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
            1,
            100,
            config,
            failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(handler, times(1)).apply(captor.capture());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:36,代码来源:BulkProcessorObjectFactoryTest.java

示例13: main

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
public static void main(String[] args) {

        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY);

        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));

        IndexRequestBuilder irb = client.prepareIndex("uav_test_db", "uav_test_table");

        Map<String, Object> item = new HashMap<String, Object>();

        item.put("name", "zz");
        item.put("age", 1);

        irb.setSource(item);

        IndexResponse ir = irb.get();

        System.out.println(ir.status());

        client.close();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:DoTestESClient.java

示例14: init

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Override
public void init() {
    this.writerSliceConfig = this.getPluginJobConf();
    this.esIndex = writerSliceConfig.getString(Key.INDEX);
    this.esType = writerSliceConfig.getString(Key.TYPE);
    int batchSize = writerSliceConfig.getInt(Key.BATCH_SIZE);
    if (batchSize > 0) {
        BATCH_SIZE = batchSize;
    }

    clusterName = writerSliceConfig.getString(Key.CLUSTER_NAME);
    String hostArray = writerSliceConfig.getString(Key.HOST);

    this.columnMeta = JSON.parseArray(writerSliceConfig.getString(Key.COLUMN));

    int port = writerSliceConfig.getInt(Key.PORT);
    try {

        String[] hosts = hostArray.split(",");

        if (null == hosts || hosts.length <= 0) {
            throw new UnknownHostException("host config error");
        }

        Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();

        TransportClient client = TransportClient.builder().settings(settings).build();

        for (int i = 0; i < hosts.length; i++) {
            String host = hosts[i];
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
        }

        this.client = client;


    } catch (UnknownHostException e) {
        logger.error("es host error", e);
        System.exit(1);
    }

}
 
开发者ID:yaogdu,项目名称:datax,代码行数:43,代码来源:EsWriter.java


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