• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InetUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: tenantConfigurationHazelcast

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean(TENANT_CONFIGURATION_HAZELCAST)
public HazelcastInstance tenantConfigurationHazelcast() throws IOException {
    log.info("{}", appProps.getHazelcast());

    Properties props = new Properties();
    props.putAll(appProps.getHazelcast());
    props.put(HAZELCAST_LOCAL_LOCAL_ADDRESS, InetUtils.getFirstNonLoopbackHostInfo().getIpAddress());

    String hazelcastConfigUrl = appProps.getHazelcast().get(HAZELCAST_CONFIG_URL_PROPERTY);
    InputStream in = context.getResource(hazelcastConfigUrl).getInputStream();

    Config config = new XmlConfigBuilder(in).setProperties(props).build();
    config.getNetworkConfig().setInterfaces(buildInterfaces(appProps.getHazelcast().get(INTERFACES)));
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    return hazelcastInstance;
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:17,代码来源:XmConfigHazelcastConfiguration.java


示例2: determineMyLocalAddress

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Override
@SneakyThrows
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
	
	Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
	 
	Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
	if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) {
		logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it...");
		Address publicAddress = localDiscoveryNode.getPublicAddress();
		if (publicAddress != null) {
			myLocalAddress = publicAddress;
		}
	}

	return new Address(InetUtils.getFirstNonLoopbackHostInfo().getIpAddress(), myLocalAddress.getPort());
}
 
开发者ID:xm-online,项目名称:xm-ms-config,代码行数:18,代码来源:CustomDiscoveryNodeRegistrator.java


示例3: eurekaClientNotShutdownInDeregister

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Test
public void eurekaClientNotShutdownInDeregister() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
	ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);

	when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));

	EurekaRegistration registration = EurekaRegistration.builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties())))
			.with(eurekaClient)
			.with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	registry.deregister(registration);

	verifyZeroInteractions(eurekaClient);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:20,代码来源:EurekaServiceRegistryTests.java


示例4: Eureka

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
public Eureka(InetUtils inetUtils, CloudEurekaClient eurekaClient) {
	this.inetUtils = inetUtils;
	this.eurekaClient = eurekaClient;
	this.clientConfig = new EurekaClientConfigBean();
	this.clientConfig.setRegisterWithEureka(false); // turn off registering with eureka, let apps send heartbeats.
	this.transport = createTransport();
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:8,代码来源:Eureka.java


示例5: etcdAutoRegistration

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public EtcdRegistration etcdAutoRegistration(InetUtils inetUtils, EtcdDiscoveryProperties properties) {
  if (StringUtils.isEmpty(properties.getAddress())) {
    String ipAddress = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
    properties.setAddress(ipAddress);
  }
  return new EtcdRegistration(properties.getName(), properties.getAddress(), properties.getPort());
}
 
开发者ID:ScienJus,项目名称:spring-cloud-etcd,代码行数:10,代码来源:EtcdAutoSerivceRegistrationAutoConfiguration.java


示例6: tenantConfigurationHazelcast

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean(TENANT_CONFIGURATION_HAZELCAST)
public HazelcastInstance tenantConfigurationHazelcast() throws IOException {
    log.info("{}", appProps.getHazelcast());

    Properties props = new Properties();
    props.putAll(appProps.getHazelcast());
    props.put(HAZELCAST_LOCAL_LOCAL_ADDRESS, InetUtils.getFirstNonLoopbackHostInfo().getIpAddress());

    String hazelcastConfigUrl = appProps.getHazelcast().get(HAZELCAST_CONFIG_URL_PROPERTY);
    InputStream in = context.getResource(hazelcastConfigUrl).getInputStream();
    Config config = new XmlConfigBuilder(in).setProperties(props).build();
    config.getNetworkConfig().setInterfaces(buildInterfaces(appProps.getHazelcast().get(INTERFACES)));

    return Hazelcast.newHazelcastInstance(config);
}
 
开发者ID:xm-online,项目名称:xm-ms-config,代码行数:16,代码来源:HazelcastConfiguration.java


示例7: eurekaInstanceConfig

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean
/**
 * Dynamically assign the hosts IP address to this instances of the Eureka Client
 *
 * @param  inetUtils  Java Networks Utilities
 * @return	An instance of a EurekaInstanceConfigBean with dynamically configured IP address
 */
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils){
    EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);

    String ip = null;
    String urlPattern = "http://{0}:{1}{2}";

    try {
        // Get the IP address of the current host using Java Network Utils
        ip = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    config.setIpAddress(ip);
    config.setPreferIpAddress(true);

    // Build the Status Page URL specific to this instances IP Address
    String statusPageUrl = MessageFormat.format(urlPattern,
            config.getIpAddress(),
            port,
            config.getStatusPageUrlPath());
    config.setStatusPageUrl(statusPageUrl);

    // Build the Health Page URL specific to this instances IP Address
    String healthPageUrl = MessageFormat.format(urlPattern,
            config.getIpAddress(),
            port,
            config.getHealthCheckUrlPath());
    config.setHealthCheckUrl(healthPageUrl);

    return config;
}
 
开发者ID:wb3-spring,项目名称:Trace-Server,代码行数:40,代码来源:WB3TraceServer.java


示例8: getIpAddress

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
private int getIpAddress(ServiceInstance instance) {
	try {
		return InetUtils.getIpAddressAsInt(instance.getHost());
	}
	catch (Exception e) {
		return 0;
	}
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:9,代码来源:DiscoveryClientEndpointLocator.java


示例9: getAddress

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
private int getAddress() {
	if (this.serverProperties!=null && this.serverProperties.getAddress() != null) {
		return InetUtils.getIpAddressAsInt(this.serverProperties.getAddress().getHostAddress());
	}
	else {
		return 127 << 24 | 1;
	}
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:9,代码来源:ServerPropertiesEndpointLocator.java


示例10: DefaultEndpointLocator

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
public DefaultEndpointLocator(Registration registration, ServerProperties serverProperties,
		Environment environment, ZipkinProperties zipkinProperties, InetUtils inetUtils) {
	this.registration = registration;
	this.serverProperties = serverProperties;
	this.environment = environment;
	this.zipkinProperties = zipkinProperties;
	if (inetUtils == null) {
		this.inetUtils = new InetUtils(new InetUtilsProperties());
	} else {
		this.inetUtils = inetUtils;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:13,代码来源:DefaultEndpointLocator.java


示例11: ServerPropertiesHostLocator

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
public ServerPropertiesHostLocator(ServerProperties serverProperties,
		Environment environment, ZipkinProperties zipkinProperties, InetUtils inetUtils) {
	this.serverProperties = serverProperties;
	this.environment = environment;
	this.zipkinProperties = zipkinProperties;
	if (inetUtils == null) {
		this.inetUtils = new InetUtils(new InetUtilsProperties());
	} else {
		this.inetUtils = inetUtils;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:12,代码来源:ServerPropertiesHostLocator.java


示例12: should_escape_root

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Test
public void should_escape_root() {
    // given:
    ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = new ZookeeperDiscoveryProperties(new InetUtils(new InetUtilsProperties()));
    // when:
    zookeeperDiscoveryProperties.setRoot(root);
    // then:
    then(zookeeperDiscoveryProperties.getRoot()).isEqualTo("/es");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:10,代码来源:ZookeeperDiscoveryPropertiesTest.java


示例13: postProcessEnvironment

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
	LinkedHashMap<String, Object> map = new LinkedHashMap<>();
	map.put("spring.cloud.client.hostname", hostInfo.getHostname());
	map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
	MapPropertySource propertySource = new MapPropertySource(
			"springCloudClientHostInfo", map);
	environment.getPropertySources().addLast(propertySource);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:12,代码来源:HostInfoEnvironmentPostProcessor.java


示例14: getFirstNonLoopbackHostInfo

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
	InetUtilsProperties target = new InetUtilsProperties();
	ConfigurationPropertySources.attach(environment);
	Binder.get(environment).bind(InetUtilsProperties.PREFIX,
			Bindable.ofInstance(target));
	try (InetUtils utils = new InetUtils(target)) {
		return utils.findFirstNonLoopbackHostInfo();
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:10,代码来源:HostInfoEnvironmentPostProcessor.java


示例15: eurekaClientGetStatus

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Test
public void eurekaClientGetStatus() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);

	InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
			.setAppName("myapp")
			.setInstanceId("1234")
			.setStatus(DOWN)
			.setOverriddenStatus(UNKNOWN)
			.build();
	when(eurekaClient.getInstanceInfo("myapp", "1234"))
			.thenReturn(instanceInfo);

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient)
			.with(mock(ApplicationInfoManager.class))
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(2)
			.containsEntry("status", DOWN.toString())
			.containsEntry("overriddenStatus", UNKNOWN.toString());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:36,代码来源:EurekaServiceRegistryTests.java


示例16: eurekaClientGetStatusNoInstance

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Test
public void eurekaClientGetStatusNoInstance() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);

	when(eurekaClient.getInstanceInfo("myapp", "1234"))
			.thenReturn(null);

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient)
			.with(mock(ApplicationInfoManager.class))
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(1)
			.containsEntry("status", UNKNOWN.toString());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:29,代码来源:EurekaServiceRegistryTests.java


示例17: instanceIdIsHostNameByDefault

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Test
public void instanceIdIsHostNameByDefault() throws IOException {
	InstanceInfo instanceInfo = setupInstance();
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		assertEquals(utils.findFirstNonLoopbackHostInfo().getHostname(),
				instanceInfo.getId());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:9,代码来源:InstanceInfoFactoryTests.java


示例18: init

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Before
public void init() throws Exception {
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
		this.hostName = hostInfo.getHostname();
		this.ipAddress = hostInfo.getIpAddress();
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:9,代码来源:EurekaInstanceConfigBeanTests.java


示例19: eurekaInstanceConfigBean

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
	EurekaInstanceConfigBean configBean = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
	String springAppName = this.env.getProperty("spring.application.name", "");
	if(StringUtils.hasText(springAppName)) {
		configBean.setSecureVirtualHostName(springAppName);
		configBean.setVirtualHostName(springAppName);
		configBean.setAppname(springAppName);
	}
	return configBean;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:12,代码来源:EurekaInstanceConfigBeanTests.java


示例20: consulDiscoveryProperties

import org.springframework.cloud.commons.util.InetUtils; //导入依赖的package包/类
@Bean
public ConsulDiscoveryProperties consulDiscoveryProperties(InetUtils inetUtils) {
	ConsulDiscoveryProperties properties = new ConsulDiscoveryProperties(inetUtils);
	// for bootstrap, lifecycle (and hence registration) is not needed, just discovery client
	properties.getLifecycle().setEnabled(false);
	return properties;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:8,代码来源:ConsulDiscoveryClientConfigServiceBootstrapConfiguration.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KafkaEmbedded类代码示例发布时间:2022-05-22
下一篇:
Java PersistentCollection类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap