本文整理了Java中com.yahoo.net.HostName.getLocalhost()
方法的一些代码示例,展示了HostName.getLocalhost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HostName.getLocalhost()
方法的具体详情如下:
包路径:com.yahoo.net.HostName
类名称:HostName
方法名:getLocalhost
[英]Return a public and fully qualified hostname for localhost that resolves to an IP address on a network interface.
[中]返回解析为网络接口上IP地址的localhost的公共和完全限定的主机名。
代码示例来源:origin: com.yahoo.vespa/jdisc_core
static String getHostname() {
return HostName.getLocalhost();
}
}
代码示例来源:origin: com.yahoo.vespa/messagebus
/**
* The default constructor requires a configuration identifier that it will use to subscribe to this message bus'
* identity. This identity is necessary so that the network layer is able to identify self for registration with
* Slobrok.
*
* @param configId The config identifier for the application.
*/
public Identity(String configId) {
hostname = HostName.getLocalhost(); // ... but fallback to hostname if we get an IPv6 address
servicePrefix = configId;
}
代码示例来源:origin: com.yahoo.vespa/standalone-container
public String fileSourceHost() {
return HostName.getLocalhost();
}
代码示例来源:origin: com.yahoo.vespa/zkfacade
private boolean isLocalHost(String remoteHost) {
if (remoteHost.equals("localhost")) return true;
if (remoteHost.equals("localhost.localdomain")) return true;
if (remoteHost.equals(HostName.getLocalhost())) return true;
return false;
}
代码示例来源:origin: com.yahoo.vespa/container-search
/**
* Returns false if this host is local.
*/
boolean isRemote(String host) throws UnknownHostException {
return (InetAddress.getByName(host).isLoopbackAddress())
? false
: !host.equals(HostName.getLocalhost());
}
代码示例来源:origin: com.yahoo.vespa/vespaclient-container-plugin
ClientFeederV3(
ReferencedResource<SharedSourceSession> sourceSession,
FeedReaderFactory feedReaderFactory,
DocumentTypeManager docTypeManager,
String clientId,
Metric metric,
ReplyHandler feedReplyHandler,
AtomicInteger threadsAvailableForFeeding) {
this.sourceSession = sourceSession;
this.clientId = clientId;
this.feedReplyHandler = feedReplyHandler;
this.metric = metric;
this.threadsAvailableForFeeding = threadsAvailableForFeeding;
this.streamReaderV3 = new StreamReaderV3(feedReaderFactory, docTypeManager);
this.hostName = HostName.getLocalhost();
}
代码示例来源:origin: com.yahoo.vespa/node-repository
@Inject
public AuthorizationFilter(Zone zone, NodeRepository nodeRepository, NodeRepositoryConfig nodeRepositoryConfig) {
this(
new Authorizer(
zone.system(),
nodeRepository,
Stream.concat(
Stream.of(HostName.getLocalhost()),
Stream.of(nodeRepositoryConfig.hostnameWhitelist().split(","))
).filter(hostname -> !hostname.isEmpty()).collect(Collectors.toSet())),
AuthorizationFilter::logAndReject
);
}
代码示例来源:origin: com.yahoo.vespa/config-model
private ConfigServer[] getConfigServers() {
return Optional.of(options.allConfigServers())
.filter(configServers -> configServers.length > 0)
.orElseGet(() -> new ConfigServer[]{new ConfigServer(HostName.getLocalhost(), Optional.empty())});
}
代码示例来源:origin: com.yahoo.vespa/zkfacade
static String createConnectionSpecForLocalhost(ConfigserverConfig config) {
String thisServer = HostName.getLocalhost();
for (int i = 0; i < config.zookeeperserver().size(); i++) {
ConfigserverConfig.Zookeeperserver server = config.zookeeperserver(i);
if (thisServer.equals(server.hostname())) {
return String.format("%s:%d", server.hostname(), server.port());
}
}
throw new IllegalArgumentException("Unable to create connect string to localhost: " +
"There is no localhost server specified in config: " + config);
}
代码示例来源:origin: com.yahoo.vespa/config-model
/**
* Builds host system from a hosts.xml file
*
* @param hostsFile a reader for host from application package
* @return the HostSystem for this application package
*/
public static Hosts readFrom(Reader hostsFile) {
List<Host> hosts = new ArrayList<>();
Document doc;
try {
doc = XmlHelper.getDocumentBuilder().parse(new InputSource(hostsFile));
} catch (SAXException | IOException e) {
throw new IllegalArgumentException(e);
}
for (Element hostE : XML.getChildren(doc.getDocumentElement(), "host")) {
String name = hostE.getAttribute("name");
if (name.equals("")) {
throw new RuntimeException("Missing 'name' attribute for host.");
}
if ("localhost".equals(name)) {
name = HostName.getLocalhost();
}
List<String> hostAliases = VespaDomBuilder.getHostAliases(hostE.getChildNodes());
if (hostAliases.isEmpty()) {
throw new IllegalArgumentException("No host aliases defined for host '" + name + "'");
}
hosts.add(new Host(name, hostAliases));
}
return new Hosts(hosts);
}
代码示例来源:origin: com.yahoo.vespa/container-search
this.nodesByHost = nodesByHostBuilder.build();
this.directDispatchTarget = findDirectDispatchTarget(HostName.getLocalhost(), size, containerClusterSize,
nodesByHost, groups);
代码示例来源:origin: com.yahoo.vespa/container-search
private static ImmutableList<Node> toNodes(DispatchConfig dispatchConfig) {
ImmutableList.Builder<Node> nodesBuilder = new ImmutableList.Builder<>();
Predicate<DispatchConfig.Node> filter;
if (dispatchConfig.useLocalNode()) {
final String hostName = HostName.getLocalhost();
filter = node -> node.host().equals(hostName);
} else {
filter = node -> true;
}
for (DispatchConfig.Node node : dispatchConfig.node()) {
if (filter.test(node)) {
nodesBuilder.add(new Node(node.key(), node.host(), node.fs4port(), node.group()));
}
}
return nodesBuilder.build();
}
代码示例来源:origin: com.yahoo.vespa/node-repository
public Maintainer(NodeRepository nodeRepository, Duration interval, JobControl jobControl) {
this.nodeRepository = nodeRepository;
this.interval = interval;
this.jobControl = jobControl;
HostName hostname = HostName.from(com.yahoo.net.HostName.getLocalhost());
long delay = staggeredDelay(nodeRepository.database().cluster(), hostname, nodeRepository.clock().instant(), interval);
service = new ScheduledThreadPoolExecutor(1);
service.scheduleAtFixedRate(this, delay, interval.toMillis(), TimeUnit.MILLISECONDS);
jobControl.started(name());
}
代码示例来源:origin: com.yahoo.vespa/config-model
@Override
public void getConfig(ZookeeperServerConfig.Builder builder) {
ConfigServer[] configServers = getConfigServers();
int[] zookeeperIds = getConfigServerZookeeperIds();
if (configServers.length != zookeeperIds.length) {
throw new IllegalArgumentException(String.format("Number of provided config server hosts (%d) must be the " +
"same as number of provided config server zookeeper ids (%d)",
configServers.length, zookeeperIds.length));
}
String myhostname = HostName.getLocalhost();
for (int i = 0; i < configServers.length; i++) {
if (zookeeperIds[i] < 0) {
throw new IllegalArgumentException(String.format("Zookeeper ids cannot be negative, was %d for %s",
zookeeperIds[i], configServers[i].hostName));
}
if (configServers[i].hostName.equals(myhostname)) {
builder.myid(zookeeperIds[i]);
}
builder.server(getZkServer(configServers[i], zookeeperIds[i]));
}
if (options.zookeeperClientPort().isPresent()) {
builder.clientPort(options.zookeeperClientPort().get());
}
}
代码示例来源:origin: com.yahoo.vespa/config-model
public SingleNodeProvisioner() {
host = new Host(HostName.getLocalhost());
this.hostSpec = new HostSpec(host.hostname(), host.aliases());
}
代码示例来源:origin: com.yahoo.vespa/config-model
builder.serverId(HostName.getLocalhost());
if (!containerCluster.getHttp().getHttpServer().getConnectorFactories().isEmpty()) {
builder.httpport(containerCluster.getHttp().getHttpServer().getConnectorFactories().get(0).getListenPort());
代码示例来源:origin: com.yahoo.vespa/container-disc
/**
* The container has no rpc methods, but we still need an RPC sever
* to register in Slobrok to enable orchestration
*/
private Register registerInSlobrok(SlobroksConfig slobrokConfig, QrConfig qrConfig) {
if ( ! qrConfig.rpc().enabled()) return null;
// 1. Set up RPC server
supervisor = new Supervisor(new Transport());
Spec listenSpec = new Spec(qrConfig.rpc().port());
try {
acceptor = supervisor.listen(listenSpec);
}
catch (ListenFailedException e) {
throw new RuntimeException("Could not create rpc server listening on " + listenSpec, e);
}
// 2. Register it in slobrok
SlobrokList slobrokList = new SlobrokList();
slobrokList.setup(slobrokConfig.slobrok().stream().map(SlobroksConfig.Slobrok::connectionspec).toArray(String[]::new));
Spec mySpec = new Spec(HostName.getLocalhost(), acceptor.port());
slobrokRegistrator = new Register(supervisor, slobrokList, mySpec);
slobrokRegistrator.registerName(qrConfig.rpc().slobrokId());
log.log(LogLevel.INFO, "Registered name '" + qrConfig.rpc().slobrokId() +
"' at " + mySpec + " with: " + slobrokList);
return slobrokRegistrator;
}
内容来源于网络,如有侵权,请联系作者删除!