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


Java NetworkUtils类代码示例

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


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

示例1: NettyRedisServerTransport

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
@Inject
public NettyRedisServerTransport(Settings settings, RestController restController, NetworkService networkService) {
    super(settings);
    this.restController = restController;
    this.networkService = networkService;

    this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors() * 2);
    this.blockingServer = componentSettings.getAsBoolean("redis.blocking_server", settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false)));
    this.port = componentSettings.get("port", settings.get("redis.port", "6379-6479"));
    this.bindHost = componentSettings.get("bind_host");
    this.publishHost = componentSettings.get("publish_host");
    this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true));
    this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true));
    this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
    this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
    this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
}
 
开发者ID:kzwang,项目名称:elasticsearch-transport-redis,代码行数:18,代码来源:NettyRedisServerTransport.java

示例2: buildNodeSettings

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
protected Settings buildNodeSettings() {
    // Build settings
    ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
            .put("node.name", "node-test-" + System.currentTimeMillis())
            .put("node.data", true)
            .put("cluster.name", "cluster-test-" + NetworkUtils.getLocalAddress().getHostName())
            .put("path.data", "./target/elasticsearch-test/data")
            .put("path.work", "./target/elasticsearch-test/work")
            .put("path.logs", "./target/elasticsearch-test/logs")
            .put("index.number_of_shards", "1")
            .put("index.number_of_replicas", "0")
            .put("cluster.routing.schedule", "50ms")
            .put("node.local", true);

    if (settings != null) {
        builder.put(settings);
    }

    return builder.build();
}
 
开发者ID:crate,项目名称:elasticsearch-inout-plugin,代码行数:21,代码来源:StoreLocalClientProvider.java

示例3: testHttpPublishPort

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
public void testHttpPublishPort() throws Exception {
    int boundPort = randomIntBetween(9000, 9100);
    int otherBoundPort = randomIntBetween(9200, 9300);

    int publishPort = resolvePublishPort(Settings.builder().put(HttpTransportSettings.SETTING_HTTP_PUBLISH_PORT.getKey(), 9080).build(),
        randomAddresses(), getByName("127.0.0.2"));
    assertThat("Publish port should be explicitly set to 9080", publishPort, equalTo(9080));

    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)),
        getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matched address", publishPort, equalTo(boundPort));

    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("127.0.0.1", boundPort), address("127.0.0.2", boundPort)),
        getByName("127.0.0.3"));
    assertThat("Publish port should be derived from unique port of bound addresses", publishPort, equalTo(boundPort));

    final BindHttpException e =
        expectThrows(BindHttpException.class,
            () -> resolvePublishPort(
                Settings.EMPTY,
                asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)),
                getByName("127.0.0.3")));
    assertThat(e.getMessage(), containsString("Failed to auto-resolve http publish port"));

    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)),
        getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));

    if (NetworkUtils.SUPPORTS_V6) {
        publishPort = resolvePublishPort(Settings.EMPTY, asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)),
            getByName("::1"));
        assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:Netty4HttpPublishPortTests.java

示例4: setup

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
@Before
public void setup() {
    if (NetworkUtils.SUPPORTS_V6 && randomBoolean()) {
        host = "::1";
    } else {
        host = "127.0.0.1";
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:NettyTransportMultiPortTests.java

示例5: testDifferentPorts

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
public void testDifferentPorts() throws Exception {
    if (!NetworkUtils.SUPPORTS_V6) {
        return;
    }
    logger.info("--> starting a node on ipv4 only");
    Settings ipv4Settings = Settings.builder().put("network.host", "127.0.0.1").build();
    String ipv4OnlyNode = internalCluster().startNode(ipv4Settings); // should bind 127.0.0.1:XYZ

    logger.info("--> starting a node on ipv4 and ipv6");
    Settings bothSettings = Settings.builder().put("network.host", "_local_").build();
    internalCluster().startNode(bothSettings); // should bind [::1]:XYZ and 127.0.0.1:XYZ+1

    logger.info("--> waiting for the cluster to declare itself stable");
    ensureStableCluster(2); // fails if port of publish address does not match corresponding bound address

    logger.info("--> checking if boundAddress matching publishAddress has same port");
    NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        BoundTransportAddress boundTransportAddress = nodeInfo.getTransport().getAddress();
        if (nodeInfo.getNode().getName().equals(ipv4OnlyNode)) {
            assertThat(boundTransportAddress.boundAddresses().length, equalTo(1));
            assertThat(boundTransportAddress.boundAddresses()[0].getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
        } else {
            assertThat(boundTransportAddress.boundAddresses().length, greaterThan(1));
            for (TransportAddress boundAddress : boundTransportAddress.boundAddresses()) {
                assertThat(boundAddress, instanceOf(TransportAddress.class));
                TransportAddress inetBoundAddress = (TransportAddress) boundAddress;
                if (inetBoundAddress.address().getAddress() instanceof Inet4Address) {
                    // IPv4 address is preferred publish address for _local_
                    assertThat(inetBoundAddress.getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
                }
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:Netty4TransportPublishAddressIT.java

示例6: getLocalAddresses

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
@Override
public List<String> getLocalAddresses() {
    List<String> local = new ArrayList<>();
    local.add("127.0.0.1");
    // check if v6 is supported, if so, v4 will also work via mapped addresses.
    if (NetworkUtils.SUPPORTS_V6) {
        local.add("[::1]"); // may get ports appended!
    }
    return local;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:TcpTransport.java

示例7: createFallbackSettings

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
private Settings createFallbackSettings() {
    Settings.Builder fallbackSettingsBuilder = settingsBuilder();

    String fallbackBindHost = settings.get("transport.netty.bind_host", settings.get("transport.bind_host", settings.get("transport.host")));
    if (fallbackBindHost != null) {
        fallbackSettingsBuilder.put("bind_host", fallbackBindHost);
    }

    String fallbackPublishHost = settings.get("transport.netty.publish_host", settings.get("transport.publish_host", settings.get("transport.host")));
    if (fallbackPublishHost != null) {
        fallbackSettingsBuilder.put("publish_host", fallbackPublishHost);
    }

    String fallbackTcpNoDelay = settings.get("transport.netty.tcp_no_delay", settings.get(TCP_NO_DELAY, "true"));
    if (fallbackTcpNoDelay != null) {
        fallbackSettingsBuilder.put("tcp_no_delay", fallbackTcpNoDelay);
    }

    String fallbackTcpKeepAlive = settings.get("transport.netty.tcp_keep_alive", settings.get(TCP_KEEP_ALIVE, "true"));
    if (fallbackTcpKeepAlive != null) {
        fallbackSettingsBuilder.put("tcp_keep_alive", fallbackTcpKeepAlive);
    }

    boolean fallbackReuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
    fallbackSettingsBuilder.put("reuse_address", fallbackReuseAddress);

    ByteSizeValue fallbackTcpSendBufferSize = settings.getAsBytesSize("transport.netty.tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
    if (fallbackTcpSendBufferSize != null) {
        fallbackSettingsBuilder.put("tcp_send_buffer_size", fallbackTcpSendBufferSize);
    }

    ByteSizeValue fallbackTcpBufferSize = settings.getAsBytesSize("transport.netty.tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
    if (fallbackTcpBufferSize != null) {
        fallbackSettingsBuilder.put("tcp_receive_buffer_size", fallbackTcpBufferSize);
    }

    return fallbackSettingsBuilder.build();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:39,代码来源:NettyTransport.java

示例8: setupServer

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
@BeforeClass
protected void setupServer() {
    node = nodeBuilder().local(true).settings(settingsBuilder()
            .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
            .put("gateway.type", "none")
            .put("index.numberOfReplicas", 0)
            .put("index.numberOfShards", 1)
    ).node();
}
 
开发者ID:yakaz,项目名称:elasticsearch-analysis-worddelimiter2,代码行数:10,代码来源:BaseESTest.java

示例9: setupThreadPoolServer

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
public void setupThreadPoolServer() throws IOException, TTransportException {
    node = nodeBuilder().settings(settingsBuilder()
            .put("path.data", "target/data")
            .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
            .put("gateway.type", "none")
            .put("thrift.server_type", "threadpool")).node();
    transport = new TSocket("localhost", 9500);
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new Rest.Client(protocol);
    transport.open();
}
 
开发者ID:russ168,项目名称:thrift-transport,代码行数:12,代码来源:SimpleThriftTests.java

示例10: setupNonblockingServer

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
public void setupNonblockingServer() throws IOException, TTransportException {
    node = nodeBuilder().settings(settingsBuilder()
            .put("path.data", "target/data")
            .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
            .put("gateway.type", "none")
            .put("thrift.server_type", "nonblocking")).node();
    transport = new TFramedTransport(new TSocket("localhost", 9500));
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new Rest.Client(protocol);
    transport.open();
}
 
开发者ID:russ168,项目名称:thrift-transport,代码行数:12,代码来源:SimpleThriftTests.java

示例11: testPublishPort

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
public void testPublishPort() throws Exception {
    int boundPort = randomIntBetween(9000, 9100);
    int otherBoundPort = randomIntBetween(9200, 9300);

    boolean useProfile = randomBoolean();
    final String profile;
    final Settings settings;
    final Settings profileSettings;
    if (useProfile) {
        profile = "some_profile";
        settings = randomBoolean() ? Settings.EMPTY : Settings.builder().put(TransportSettings.PUBLISH_PORT.getKey(), 9081).build();
        profileSettings = Settings.builder().put("publish_port", 9080).build();
    } else {
        profile = TransportSettings.DEFAULT_PROFILE;
        settings = Settings.builder().put(TransportSettings.PUBLISH_PORT.getKey(), 9081).build();
        profileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder().put("publish_port", 9080).build();;
    }

    int publishPort = resolvePublishPort(profile, settings, profileSettings,
        randomAddresses(), getByName("127.0.0.2"));
    assertThat("Publish port should be explicitly set", publishPort, equalTo(useProfile ? 9080 : 9081));

    publishPort = resolvePublishPort(profile, Settings.EMPTY, Settings.EMPTY,
        asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)),
        getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matched address", publishPort, equalTo(boundPort));

    publishPort = resolvePublishPort(profile, Settings.EMPTY, Settings.EMPTY,
        asList(address("127.0.0.1", boundPort), address("127.0.0.2", boundPort)),
        getByName("127.0.0.3"));
    assertThat("Publish port should be derived from unique port of bound addresses", publishPort, equalTo(boundPort));

    try {
        resolvePublishPort(profile, Settings.EMPTY, Settings.EMPTY,
            asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)),
            getByName("127.0.0.3"));
        fail("Expected BindTransportException as publish_port not specified and non-unique port of bound addresses");
    } catch (BindTransportException e) {
        assertThat(e.getMessage(), containsString("Failed to auto-resolve publish port"));
    }

    publishPort = resolvePublishPort(profile, Settings.EMPTY, Settings.EMPTY,
        asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)),
        getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));

    if (NetworkUtils.SUPPORTS_V6) {
        publishPort = resolvePublishPort(profile, Settings.EMPTY, Settings.EMPTY,
            asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)),
            getByName("::1"));
        assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:PublishPortTests.java

示例12: setClusterName

import org.elasticsearch.common.network.NetworkUtils; //导入依赖的package包/类
protected void setClusterName() {
    this.cluster = "test-jdbc-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "-" + clusterCount.incrementAndGet();
}
 
开发者ID:szwork2013,项目名称:elasticsearch-sentiment,代码行数:4,代码来源:AbstractNodeTestHelper.java


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