本文整理汇总了Java中java.net.InetAddress.isMulticastAddress方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddress.isMulticastAddress方法的具体用法?Java InetAddress.isMulticastAddress怎么用?Java InetAddress.isMulticastAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.InetAddress
的用法示例。
在下文中一共展示了InetAddress.isMulticastAddress方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortKey
import java.net.InetAddress; //导入方法依赖的package包/类
/** Sorts an address by preference. This way code like publishing can just pick the first one */
static int sortKey(InetAddress address, boolean prefer_v6) {
int key = address.getAddress().length;
if (prefer_v6) {
key = -key;
}
if (address.isAnyLocalAddress()) {
key += 5;
}
if (address.isMulticastAddress()) {
key += 4;
}
if (address.isLoopbackAddress()) {
key += 3;
}
if (address.isLinkLocalAddress()) {
key += 2;
}
if (address.isSiteLocalAddress()) {
key += 1;
}
return key;
}
示例2: read
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* Reads from ChannelBuffer and parses NextHop.
*
* @param cb ChannelBuffer
* @return object of NextHop
* @throws BgpParseException while parsing nexthop attribute
*/
public static NextHop read(ChannelBuffer cb) throws BgpParseException {
Ip4Address nextHop;
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
if (cb.readableBytes() < parseFlags.getLength()) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
if (ipAddress.isMulticastAddress()) {
throw new BgpParseException("Multicast address is not supported");
}
nextHop = Ip4Address.valueOf(ipAddress);
return new NextHop(nextHop);
}
示例3: doGetIpv4AddressFromNetworkInterface
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* docker环境中,有时无法通过InetAddress.getLocalHost()获取 ,会报unknown host Exception, system error
* 此时,通过遍历网卡接口的方式规避,出来的数据不一定对
*/
private static void doGetIpv4AddressFromNetworkInterface() throws SocketException {
Enumeration<NetworkInterface> iterNetwork = NetworkInterface.getNetworkInterfaces();
while (iterNetwork.hasMoreElements()) {
NetworkInterface network = iterNetwork.nextElement();
if (!network.isUp() || network.isLoopback() || network.isVirtual()) {
continue;
}
Enumeration<InetAddress> iterAddress = network.getInetAddresses();
while (iterAddress.hasMoreElements()) {
InetAddress address = iterAddress.nextElement();
if (address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isMulticastAddress()
|| Inet6Address.class.isInstance(address)) {
continue;
}
if (Inet4Address.class.isInstance(address)) {
LOGGER.info(
"add network interface name:" + network.getName() + ",host address:" + address.getHostAddress());
allInterfaceAddresses.put(network.getName(), address);
}
}
}
}
示例4: createDatagramSocket
import java.net.InetAddress; //导入方法依赖的package包/类
public DatagramSocket createDatagramSocket(int port, InetAddress laddr)
throws SocketException {
if ( laddr.isMulticastAddress() ) {
try {
MulticastSocket ds = new MulticastSocket( port );
ds.joinGroup( laddr );
return ds;
} catch (IOException e) {
throw new SocketException( e.getLocalizedMessage() );
}
} else return new DatagramSocket(port, laddr);
}
示例5: getInetAddresses
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* @return a bunch of InetAddresses that are "real", ie, not virtual,
* loopback, multicast and are up.
*/
public static List<Pair<NetworkInterface, InetAddress>> getInetAddresses()
{
List<Pair<NetworkInterface, InetAddress>> addrs = Lists.newArrayList();
try
{
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
while( nis.hasMoreElements() )
{
NetworkInterface ni = nis.nextElement();
if( !ni.isLoopback() && !ni.isVirtual() && ni.isUp() )
{
for( Enumeration<InetAddress> ias = ni.getInetAddresses(); ias.hasMoreElements(); )
{
InetAddress ia = ias.nextElement();
if( !ia.isMulticastAddress() && !ia.isLoopbackAddress() )
{
addrs.add(new Pair<NetworkInterface, InetAddress>(ni, ia));
}
}
}
}
}
catch( SocketException e )
{
// Carry on
}
return addrs;
}
示例6: getAttribute
import java.net.InetAddress; //导入方法依赖的package包/类
public String getAttribute(String attName) {
Object result = getAttributeObject(attName);
if (result instanceof String) {
return (String) result;
}
if (attName.equalsIgnoreCase(MEMBERSHIP_PORT_RANGE)) {
int[] value = (int[]) result;
return "" + value[0] + "-" + value[1];
}
if (result.getClass().isArray() && attName.startsWith("ssl-")) {
return SystemAdmin.join((Object[]) result, ",");
}
if (result.getClass().isArray()) {
return SystemAdmin.join((Object[]) result);
}
if (result instanceof InetAddress) {
InetAddress addr = (InetAddress) result;
String addrName = null;
if (addr.isMulticastAddress() || !SocketCreator.resolve_dns) {
addrName = addr.getHostAddress(); // on Windows getHostName on mcast addrs takes ~5 seconds
} else {
addrName = SocketCreator.getHostName(addr);
}
return addrName;
}
return result.toString();
}
示例7: checkMcastAddress
import java.net.InetAddress; //导入方法依赖的package包/类
@ConfigAttributeChecker(name = MCAST_ADDRESS)
protected InetAddress checkMcastAddress(InetAddress value) {
if (!value.isMulticastAddress()) {
throw new IllegalArgumentException(
LocalizedStrings.AbstractDistributionConfig_COULD_NOT_SET_0_TO_1_BECAUSE_IT_WAS_NOT_A_MULTICAST_ADDRESS
.toLocalizedString(new Object[] {MCAST_ADDRESS, value}));
}
return value;
}
示例8: bgpIdValidation
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* Validates BGP ID.
*
* @param openMsg open message
* @return true or false
*/
private boolean bgpIdValidation(BgpOpenMsg openMsg) {
String openMsgBgpId = Ip4Address.valueOf(openMsg.getBgpId()).toString();
InetAddress ipAddress;
try {
ipAddress = InetAddress.getByName(openMsgBgpId);
if (ipAddress.isMulticastAddress()) {
return false;
}
} catch (UnknownHostException e) {
log.debug("InetAddress convertion failed");
}
return true;
}
示例9: read
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* Reads the channel buffer and returns object of IPv6AddressTlv.
*
* @param cb channelBuffer
* @param type address type
* @return object of IPv6AddressTlv
* @throws BgpParseException while parsing IPv6AddressTlv
*/
public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
if (ipAddress.isMulticastAddress()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
Ip6Address address = Ip6Address.valueOf(ipAddress);
return IPv6AddressTlv.of(address, type);
}
示例10: read
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* Reads the channel buffer and returns object of IPv4AddressTlv.
*
* @param cb channelBuffer
* @param type address type
* @return object of IPv4AddressTlv
* @throws BgpParseException while parsing IPv4AddressTlv
*/
public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
if (ipAddress.isMulticastAddress()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
Ip4Address address = Ip4Address.valueOf(ipAddress);
return IPv4AddressTlv.of(address, type);
}
示例11: isGoodV4Address
import java.net.InetAddress; //导入方法依赖的package包/类
private static boolean isGoodV4Address(InetAddress address)
{
return address instanceof Inet4Address &&
!address.isAnyLocalAddress() &&
!address.isLoopbackAddress() &&
!address.isMulticastAddress();
}
示例12: isGoodV6Address
import java.net.InetAddress; //导入方法依赖的package包/类
private static boolean isGoodV6Address(InetAddress address)
{
return address instanceof Inet6Address &&
!address.isAnyLocalAddress() &&
!address.isLoopbackAddress() &&
!address.isMulticastAddress();
}
示例13: testRegionServerHostname
import java.net.InetAddress; //导入方法依赖的package包/类
@Test(timeout=120000)
public void testRegionServerHostname() throws Exception {
final int NUM_MASTERS = 1;
final int NUM_RS = 1;
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
while (netInterfaceList.hasMoreElements()) {
NetworkInterface ni = netInterfaceList.nextElement();
Enumeration<InetAddress> addrList = ni.getInetAddresses();
// iterate through host addresses and use each as hostname
while (addrList.hasMoreElements()) {
InetAddress addr = addrList.nextElement();
if (addr.isLoopbackAddress() || addr.isLinkLocalAddress() || addr.isMulticastAddress()) {
continue;
}
String hostName = addr.getHostName();
LOG.info("Found " + hostName + " on " + ni);
TEST_UTIL.getConfiguration().set(HRegionServer.RS_HOSTNAME_KEY, hostName);
TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
try {
ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.rsZNode);
while (servers == null) {
Threads.sleep(10);
}
assertTrue(servers.size() == NUM_RS);
for (String server : servers) {
assertTrue("From zookeeper: " + server + " hostname: " + hostName,
server.startsWith(hostName.toLowerCase()+","));
}
zkw.close();
} finally {
TEST_UTIL.shutdownMiniCluster();
}
}
}
}