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


Java InetUtils类代码示例

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


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


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