本文整理汇总了Java中com.netflix.appinfo.InstanceInfo.getHostName方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceInfo.getHostName方法的具体用法?Java InstanceInfo.getHostName怎么用?Java InstanceInfo.getHostName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.appinfo.InstanceInfo
的用法示例。
在下文中一共展示了InstanceInfo.getHostName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateIfNeeded
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
static InstanceInfo updateIfNeeded(final InstanceInfo info) {
if (info.getInstanceId() == null && info.getMetadata() != null) {
String instanceId = info.getMetadata().get("instanceId");
if (StringUtils.hasText(instanceId)) {
// backwards compatibility for Angel
if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) {
instanceId = info.getHostName()+":"+instanceId;
}
return new InstanceInfo.Builder(info).setInstanceId(instanceId).build();
}
}
return info;
}
示例2: getRegistration
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
protected Registration getRegistration(InstanceInfo instanceInfo) {
Application application = new Application(instanceInfo.getAppName(), instanceInfo.getInstanceId(), instanceInfo.getHostName(), instanceInfo.getPort());
Registration registration = new Registration();
registration.setApplication(application);
registration.update(instanceInfo);
return registration;
}
示例3: extractId
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
private String extractId(Server server) {
if (server instanceof DiscoveryEnabledServer) {
DiscoveryEnabledServer enabled = (DiscoveryEnabledServer) server;
InstanceInfo instance = enabled.getInstanceInfo();
if (instance.getMetadata().containsKey("instanceId")) {
return instance.getHostName()+":"+instance.getMetadata().get("instanceId");
}
}
return super.getId();
}
示例4: marshall
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
/**
* Private helper that marshals the information from each instance into something that
* Turbine can understand. Override this method for your own implementation for
* parsing Eureka info.
* @param instanceInfo
* @return Instance
*/
Instance marshall(InstanceInfo instanceInfo) {
String hostname = instanceInfo.getHostName();
final String managementPort = instanceInfo.getMetadata().get("management.port");
String port = managementPort == null ? String.valueOf(instanceInfo.getPort()) : managementPort;
String cluster = getClusterName(instanceInfo);
Boolean status = parseInstanceStatus(instanceInfo.getStatus());
if (hostname != null && cluster != null && status != null) {
Instance instance = getInstance(hostname, port, cluster, status);
Map<String, String> metadata = instanceInfo.getMetadata();
boolean securePortEnabled = instanceInfo.isPortEnabled(InstanceInfo.PortType.SECURE);
String securePort = String.valueOf(instanceInfo.getSecurePort());
addMetadata(instance, hostname, port, securePortEnabled, securePort, metadata);
// add amazon metadata
String asgName = instanceInfo.getASGName();
if (asgName != null) {
instance.getAttributes().put(ASG_KEY, asgName);
}
DataCenterInfo dcInfo = instanceInfo.getDataCenterInfo();
if (dcInfo != null && dcInfo.getName().equals(DataCenterInfo.Name.Amazon)) {
AmazonInfo amznInfo = (AmazonInfo) dcInfo;
instance.getAttributes().putAll(amznInfo.getMetadata());
}
return instance;
}
else {
return null;
}
}