本文整理汇总了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;
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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");
}
示例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);
}
示例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();
}
}
示例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());
}