List of usage examples for java.net InetSocketAddress equals
@Override public final boolean equals(Object obj)
From source file:org.apache.hadoop.hdfs.conf.FallbackNameSpaceAddressManager.java
private static void verifyAddress(String address, InstanceId fromZk, InetSocketAddress zeroAddr, InetSocketAddress oneAddr) { InstanceId afterMatchingWithConfig = null; if (address == null) { afterMatchingWithConfig = null;//from w w w .j a v a 2s . c o m } else { InetSocketAddress addressInIp = NetUtils.createSocketAddr(address); if (zeroAddr.equals(addressInIp)) { afterMatchingWithConfig = InstanceId.NODEZERO; } else if (oneAddr.equals(addressInIp)) { afterMatchingWithConfig = InstanceId.NODEONE; } else { DFSUtil.throwAndLogIllegalState( "Address doesn't match any of the possible candidates from the config file", LOG); } } if (afterMatchingWithConfig != fromZk) { DFSUtil.throwAndLogIllegalState("One of the addresses of Zookeeper isn't in sync with other addresses.", LOG); } }
From source file:org.apache.hadoop.mapred.tools.MRZKFailoverController.java
@Override protected HAServiceTarget dataToTarget(byte[] data) { ActiveNodeInfo proto;// ww w .j a v a 2s .c o m try { proto = ActiveNodeInfo.parseFrom(data); } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Invalid data in ZK: " + StringUtils.byteToHexString(data)); } JobTrackerHAServiceTarget ret = new JobTrackerHAServiceTarget(conf, proto.getNamenodeId()); InetSocketAddress addressFromProtobuf = new InetSocketAddress(proto.getHostname(), proto.getPort()); if (!addressFromProtobuf.equals(ret.getAddress())) { throw new RuntimeException("Mismatched address stored in ZK for " + ret + ": Stored protobuf was " + addressFromProtobuf + ", address from our own " + "configuration for this JobTracker was " + ret.getAddress()); } ret.setZkfcPort(proto.getZkfcPort()); return ret; }
From source file:org.apache.hadoop.hdfs.server.datanode.AvatarDataNode.java
private static void logChangeOf(InetSocketAddress prev, InetSocketAddress next) { if (prev.equals(next)) { return;/* w w w . j a v a2 s . c om*/ } LOG.info("From: <" + prev + "> To: <" + next + ">"); }
From source file:com.velix.jmongo.MongoImpl.java
@SuppressWarnings("unchecked") private InetSocketAddress checkPrimary(InetSocketAddress inetAddress, SimpleConnectionPool delegate) { if (!inetAddress.equals(this.address)) { delegate.setAddress(inetAddress); }/* ww w. j ava 2s .c o m*/ MongoAdmin mongoAdmin = this.getAdmin(); BSONDocument command = new MongoDocument("ismaster", 1); try { CommandResult result = mongoAdmin.runCommand(command, true); List<String> hosts = (List<String>) result.get("hosts"); this.allHosts.addAll(getUniqueHosts(hosts)); boolean isMaster = (Boolean) result.get("ismaster"); if (isMaster) { return inetAddress; } else { String master = (String) result.get("primary"); return checkPrimary(parseInetSocketAddress(master), delegate); } } catch (Exception e) { return null; } }
From source file:org.apache.hadoop.hdfs.conf.FallbackNameSpaceAddressManager.java
@Override public void refreshZookeeperInfo() throws IOException, KeeperException, InterruptedException { NameNodeAddress zero = getNodeZero(); NameNodeAddress one = getNodeOne();/* w ww . j a v a2 s.c om*/ // Using RPC Address to determine which node is primary and using the rest // of them as a sanity check String zNodeClientProtocol = clientProtocolZnodeAddress.getAddress(); String primaryClientProtocol = zkClient.getPrimaryAvatarAddress(zNodeClientProtocol, new Stat(), false, false); InstanceId instanceIdfromZookeeper = null; if (primaryClientProtocol == null) { // Fail-over in progress. instanceIdfromZookeeper = null; } else { InetSocketAddress clientProtAddress = NetUtils.createSocketAddr(primaryClientProtocol); if (clientProtAddress.equals(zero.clientProtocol.getAddress())) { instanceIdfromZookeeper = InstanceId.NODEZERO; } else if (clientProtAddress.equals(one.clientProtocol.getAddress())) { instanceIdfromZookeeper = InstanceId.NODEONE; } else { throw new IllegalArgumentException( "Zookeeper client protocol address isn't valid: " + primaryClientProtocol); } } String zNodeHttpKey = httpZnodeAddress.getAddress(); verifyAddress(zkClient.getPrimaryAvatarAddress(zNodeHttpKey, new Stat(), false), instanceIdfromZookeeper, zero.httpProtocol.getAddress(), one.httpProtocol.getAddress()); String zNodeKeyForDnAddress = datanodeProtocolZnodeAddress.getAddress(); verifyAddress(zkClient.getPrimaryAvatarAddress(zNodeKeyForDnAddress, new Stat(), false), instanceIdfromZookeeper, zero.datanodeProtocol.getAddress(), one.datanodeProtocol.getAddress()); super.setPrimary(instanceIdfromZookeeper); }
From source file:org.apache.hadoop.hdfs.tools.DFSZKFailoverController.java
@Override protected HAServiceTarget dataToTarget(byte[] data) { ActiveNodeInfo proto;/* w w w .j av a 2 s . c o m*/ try { proto = ActiveNodeInfo.parseFrom(data); } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Invalid data in ZK: " + StringUtils.byteToHexString(data)); } NNHAServiceTarget ret = new NNHAServiceTarget(conf, proto.getNameserviceId(), proto.getNamenodeId()); InetSocketAddress addressFromProtobuf = new InetSocketAddress(proto.getHostname(), proto.getPort()); if (!addressFromProtobuf.equals(ret.getAddress())) { throw new RuntimeException("Mismatched address stored in ZK for " + ret + ": Stored protobuf was " + proto + ", address from our own " + "configuration for this NameNode was " + ret.getAddress()); } ret.setZkfcPort(proto.getZkfcPort()); return ret; }
From source file:com.velix.jmongo.MongoImpl.java
private synchronized void findPrimary(Set<InetSocketAddress> hostSet) { connectionPool.getPoolLock().lock(); connectionPool.closeDelegate();/*from w ww . j av a2s . c o m*/ SimpleConnectionPool delegate = new SimpleConnectionPool(new MongoProtocol()); connectionPool.setDelegate(delegate); try { this.allHosts = new HashSet<InetSocketAddress>(hostSet.size()); InetSocketAddress lastPrimary = null; for (InetSocketAddress inetAddress : hostSet) { allHosts.add(inetAddress); InetSocketAddress primary = checkPrimary(inetAddress, delegate); if (null == primary || primary.equals(lastPrimary)) { // throw new MongoException("can not find master db"); continue; } if (null != lastPrimary && !lastPrimary.equals(primary)) { throw new MongoException("multi master db " + lastPrimary + " and " + primary); } else { lastPrimary = primary; } } if (null == lastPrimary) { throw new MongoException("can not find master db"); } this.address = lastPrimary; factory = new PoolableConnectionFactory(this.address, new MongoProtocol()); connectionPool .setDelegate(new CommonsConnectionPool(new GenericObjectPool(factory, this.configuration))); } finally { connectionPool.getPoolLock().unlock(); } }
From source file:org.apache.hadoop.hdfs.DFSUtil.java
/** * For given set of {@code keys} adds nameservice Id and or namenode Id * and returns {nameserviceId, namenodeId} when address match is found. * @see #getSuffixIDs(Configuration, String, AddressMatcher) */// w ww . j av a2 s.co m static String[] getSuffixIDs(final Configuration conf, final InetSocketAddress address, final String... keys) { AddressMatcher matcher = new AddressMatcher() { @Override public boolean match(InetSocketAddress s) { return address.equals(s); } }; for (String key : keys) { String[] ids = getSuffixIDs(conf, key, null, null, matcher); if (ids != null && (ids[0] != null || ids[1] != null)) { return ids; } } return null; }
From source file:org.wso2.andes.server.cluster.HazelcastCoordinationStrategy.java
/** * {@inheritDoc}/*from w w w . j a v a2 s . co m*/ */ @Override public List<NodeDetail> getAllNodeDetails() throws AndesException { List<NodeDetail> nodeDetails = new ArrayList<>(); CoordinatorInformation coordinatorDetails = getCoordinatorDetails(); InetSocketAddress coordinatorSocketAddress = new InetSocketAddress(coordinatorDetails.getHostname(), Integer.parseInt(coordinatorDetails.getPort())); for (Member member : hazelcastInstance.getCluster().getMembers()) { InetSocketAddress nodeSocketAddress = member.getSocketAddress(); String nodeId = configurableClusterAgent.getIdOfNode(member); boolean isCoordinator = nodeSocketAddress.equals(coordinatorSocketAddress); nodeDetails.add(new NodeDetail(nodeId, nodeSocketAddress, isCoordinator)); } return nodeDetails; }
From source file:org.openhab.binding.lifx.internal.LifxLightDiscovery.java
private void handlePacket(Packet packet, InetSocketAddress address) { logger.trace("Discovery : Packet type '{}' received from '{}' for '{}' with sequence '{}' and source '{}'", new Object[] { packet.getClass().getSimpleName(), address.toString(), packet.getTarget().getHex(), packet.getSequence(), Long.toString(packet.getSource(), 16) }); if (packet.getSource() == sourceId || packet.getSource() == 0) { MACAddress macAddress = packet.getTarget(); DiscoveredLight light = discoveredLights.get(macAddress); if (packet instanceof StateServiceResponse) { int port = (int) ((StateServiceResponse) packet).getPort(); if (port != 0) { try { InetSocketAddress socketAddress = new InetSocketAddress(address.getAddress(), port); if (light == null || (!socketAddress.equals(light.socketAddress))) { if (light != null) { light.cancelUnicastKey(); }//from ww w . j ava 2 s. com Selector lightSelector = selector; if (lightSelector != null) { String logId = getLogId(macAddress, socketAddress); light = new DiscoveredLight(lightSelector, macAddress, socketAddress, logId, openUnicastChannel(lightSelector, logId, socketAddress)); discoveredLights.put(macAddress, light); } } } catch (Exception e) { logger.warn("{} while connecting to IP address: {}", e.getClass().getSimpleName(), e.getMessage()); return; } } } else if (light != null) { if (packet instanceof StateLabelResponse) { light.label = ((StateLabelResponse) packet).getLabel().trim(); } else if (packet instanceof StateVersionResponse) { try { light.product = Product .getProductFromProductID(((StateVersionResponse) packet).getProduct()); light.productVersion = ((StateVersionResponse) packet).getVersion(); } catch (IllegalArgumentException e) { logger.debug("Discovered an unsupported light ({}): {}", light.macAddress.getAsLabel(), e.getMessage()); light.supportedProduct = false; } } } if (light != null && light.isDataComplete()) { try { thingDiscovered(createDiscoveryResult(light)); } catch (IllegalArgumentException e) { logger.trace("{} while creating discovery result of light ({})", e.getClass().getSimpleName(), light.logId, e); } } } }