org.apache.hadoop.hbase.net.Address类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.apache.hadoop.hbase.net.Address类的一些代码示例,展示了Address类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address类的具体详情如下:
包路径:org.apache.hadoop.hbase.net.Address
类名称:Address

Address介绍

[英]An immutable type to hold a hostname and port combo, like an Endpoint or java.net.InetSocketAddress (but without danger of our calling resolve -- we do NOT want a resolve happening every time we want to hold a hostname and port combo). This class is also Comparable

In implementation this class is a facade over Guava's HostAndPort. We cannot have Guava classes in our API hence this Type.
[中]用于保存主机名和端口组合的不可变类型,如端点或java。网InetSocketAddress(但没有调用resolve的危险——我们不希望每次需要保存主机名和端口组合时都发生解析)。这一类也具有可比性
在实现中,这个类是Guava的HostAndPort上的一个门面。我们的API中不能有Guava类,因此是这种类型。

代码示例

代码示例来源:origin: apache/hbase

/**
 * If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
 * @return if host looks like it is resolved -- not an IP -- then strip the domain portion
 * otherwise returns same as {@link #toString()}}
 */
public String toStringWithoutDomain() {
 String hostname = getHostname();
 String [] parts = hostname.split("\\.");
 if (parts.length > 1) {
  for (String part: parts) {
   if (!StringUtils.isNumeric(part)) {
    return Address.fromParts(parts[0], getPort()).toString();
   }
  }
 }
 return toString();
}

代码示例来源:origin: apache/hbase

/**
 * @return List of Regions associated with this <code>server</code>.
 */
private List<RegionInfo> getRegions(final Address server) {
 LinkedList<RegionInfo> regions = new LinkedList<>();
 for (Map.Entry<RegionInfo, ServerName> el :
   master.getAssignmentManager().getRegionStates().getRegionAssignments().entrySet()) {
  if (el.getValue() == null) {
   continue;
  }
  if (el.getValue().getAddress().equals(server)) {
   addRegion(regions, el.getKey());
  }
 }
 for (RegionStateNode state : master.getAssignmentManager().getRegionsInTransition()) {
  if (state.getRegionLocation().getAddress().equals(server)) {
   addRegion(regions, state.getRegionInfo());
  }
 }
 return regions;
}

代码示例来源:origin: apache/hbase

private ServerName(final String hostAndPort, final long startCode) {
 this(Address.fromString(hostAndPort), startCode);
}

代码示例来源:origin: apache/hbase

@Override
 public int compareTo(Address that) {
  int compare = this.getHostname().compareTo(that.getHostname());
  if (compare != 0) return compare;
  return this.getPort() - that.getPort();
 }
}

代码示例来源:origin: apache/hbase

@Test
 public void testGetHostWithoutDomain() {
  assertEquals("a:123",
    Address.fromParts("a.b.c", 123).toStringWithoutDomain());
  assertEquals("1:123",
    Address.fromParts("1.b.c", 123).toStringWithoutDomain());
  assertEquals("123.456.789.1:123",
    Address.fromParts("123.456.789.1", 123).toStringWithoutDomain());
  assertEquals("[2001:db8::1]:80",
    Address.fromParts("[2001:db8::1]:", 80).toStringWithoutDomain());
  assertEquals("[2001:db8::1]:80",
    Address.fromParts("[2001:db8::1]:", 80).toStringWithoutDomain());
 }
}

代码示例来源:origin: apache/hbase

protected ServerName(final String hostname, final int port, final long startcode) {
 this(Address.fromParts(hostname, port), startcode);
}

代码示例来源:origin: apache/hbase

/**
 * @return Hostname and port formatted as described at
 * {@link Addressing#createHostAndPortStr(String, int)}
 * @deprecated Since 2.0. Use {@link #getAddress()} instead.
 */
@Deprecated
public String getHostAndPort() {
 return this.address.toString();
}

代码示例来源:origin: apache/hbase

/**
 * Call this restart method only after running MockMasterServices#start()
 * The RSs can be differentiated by the port number, see
 * ServerName in MockMasterServices#start() method above.
 * Restart of region server will have new startcode in server name
 *
 * @param serverName Server name to be restarted
 */
public void restartRegionServer(ServerName serverName) throws IOException {
 List<ServerName> onlineServers = serverManager.getOnlineServersList();
 long startCode = -1;
 for (ServerName s : onlineServers) {
  if (s.getAddress().equals(serverName.getAddress())) {
   startCode = s.getStartcode() + 1;
   break;
  }
 }
 if (startCode == -1) {
  return;
 }
 ServerName sn = ServerName.valueOf(serverName.getAddress().toString(), startCode);
 serverManager.regionServerReport(sn, ServerMetricsBuilder.of(sn));
}

代码示例来源:origin: apache/hbase

public String getHostname() {
 return this.address.getHostname();
}

代码示例来源:origin: apache/hbase

public int getPort() {
 return this.address.getPort();
}

代码示例来源:origin: apache/hbase

@Override
// Don't use HostAndPort equals... It is wonky including
// ipv6 brackets
public boolean equals(Object other) {
 if (this == other) {
  return true;
 }
 if (other instanceof Address) {
  Address that = (Address)other;
  return this.getHostname().equals(that.getHostname()) &&
    this.getPort() == that.getPort();
 }
 return false;
}

代码示例来源:origin: apache/hbase

private SortedSet<Address> getDefaultServers() throws IOException {
 SortedSet<Address> defaultServers = Sets.newTreeSet();
 for (ServerName serverName : getOnlineRS()) {
  Address server = Address.fromParts(serverName.getHostname(), serverName.getPort());
  boolean found = false;
  for (RSGroupInfo rsgi : listRSGroups()) {
   if (!RSGroupInfo.DEFAULT_GROUP.equals(rsgi.getName()) && rsgi.containsServer(server)) {
    found = true;
    break;
   }
  }
  if (!found) {
   defaultServers.add(server);
  }
 }
 return defaultServers;
}

代码示例来源:origin: apache/hbase

/**
 * Parses hostname:port from WAL file path
 * @param p path to WAL file
 * @return hostname:port
 */
public static String parseHostNameFromLogFile(Path p) {
 try {
  if (AbstractFSWALProvider.isArchivedLogFile(p)) {
   return BackupUtils.parseHostFromOldLog(p);
  } else {
   ServerName sname = AbstractFSWALProvider.getServerNameFromWALDirectoryName(p);
   if (sname != null) {
    return sname.getAddress().toString();
   } else {
    LOG.error("Skip log file (can't parse): " + p);
    return null;
   }
  }
 } catch (Exception e) {
  LOG.error("Skip log file (can't parse): " + p, e);
  return null;
 }
}

代码示例来源:origin: apache/hbase

Address.fromParts(initialIsa.getHostName(), initialIsa.getPort()).toStringWithoutDomain();

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * Call this restart method only after running MockMasterServices#start()
 * The RSs can be differentiated by the port number, see
 * ServerName in MockMasterServices#start() method above.
 * Restart of region server will have new startcode in server name
 *
 * @param serverName Server name to be restarted
 */
public void restartRegionServer(ServerName serverName) throws IOException {
 List<ServerName> onlineServers = serverManager.getOnlineServersList();
 long startCode = -1;
 for (ServerName s : onlineServers) {
  if (s.getAddress().equals(serverName.getAddress())) {
   startCode = s.getStartcode() + 1;
   break;
  }
 }
 if (startCode == -1) {
  return;
 }
 ServerName sn = ServerName.valueOf(serverName.getAddress().toString(), startCode);
 serverManager.regionServerReport(sn, new ServerLoad(ServerMetricsBuilder.of(sn)));
}

代码示例来源:origin: apache/hbase

public String getHostnameLowerCase() {
 return this.address.getHostname().toLowerCase(Locale.ROOT);
}

代码示例来源:origin: org.apache.hbase/hbase-common

public int getPort() {
 return this.address.getPort();
}

代码示例来源:origin: org.apache.hbase/hbase-common

/**
 * If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
 * @return if host looks like it is resolved -- not an IP -- then strip the domain portion
 * otherwise returns same as {@link #toString()}}
 */
public String toStringWithoutDomain() {
 String hostname = getHostname();
 String [] parts = hostname.split("\\.");
 if (parts.length > 1) {
  for (String part: parts) {
   if (!StringUtils.isNumeric(part)) {
    return Address.fromParts(parts[0], getPort()).toString();
   }
  }
 }
 return toString();
}

代码示例来源:origin: apache/hbase

@Override
public int hashCode() {
 return this.getHostname().hashCode() ^ getPort();
}

代码示例来源:origin: apache/hbase

public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
 RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
 for(HBaseProtos.ServerName el: proto.getServersList()) {
  RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
 }
 for(HBaseProtos.TableName pTableName: proto.getTablesList()) {
  RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
 }
 return RSGroupInfo;
}

相关文章