List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:org.opendaylight.controller.switchmanager.Subnet.java
public boolean isSubnetOf(InetAddress ip) { if (ip == null) return false; InetAddress thisPrefix = getPrefixForAddress(this.networkAddress); InetAddress otherPrefix = getPrefixForAddress(ip); if ((thisPrefix == null) || (otherPrefix == null)) return false; if (thisPrefix.equals(otherPrefix)) return true; else/*from w w w. ja va2s . c o m*/ return false; }
From source file:org.opennms.netmgt.config.snmp.AddressSnmpConfigVisitor.java
@Override public void visitSpecifics(final List<String> specifics) { for (final String saddr : specifics) { try {/*from w ww .j a v a 2 s .com*/ final InetAddress addr = InetAddressUtils.addr(saddr); if (addr != null && addr.equals(m_address)) { //LOG.debug("{} == {}", addr, m_address); m_matchedDefinition = m_currentDefinition; return; } } catch (final IllegalArgumentException e) { LOG.info("Error while reading SNMP config <specific> tag: {}", saddr, e); } } }
From source file:com.mirth.connect.connectors.tcp.TcpMessageReceiver.java
protected ServerSocket createSocket(URI uri) throws IOException { String host = uri.getHost();// w w w .ja v a 2 s. c o m int backlog = connector.getBacklog(); if (host == null || host.length() == 0) { host = "localhost"; } InetAddress inetAddress = InetAddress.getByName(host); if (inetAddress.equals(InetAddress.getLocalHost()) || inetAddress.isLoopbackAddress() || host.trim().equals("localhost")) { return new ServerSocket(uri.getPort(), backlog); } else { return new ServerSocket(uri.getPort(), backlog, inetAddress); } }
From source file:org.apache.cassandra.service.MigrationManager.java
public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value) { if (state != ApplicationState.SCHEMA || endpoint.equals(FBUtilities.getBroadcastAddress())) return;/*from www . java 2 s . c o m*/ rectifySchema(UUID.fromString(value.value), endpoint); }
From source file:org.apache.cassandra.service.StorageProxy.java
/*** * /*from www . ja v a 2s. co m*/ * @param rm * @param hintedEndpoints * @param responseHandler * @param localDataCenter * @param insertLocalMessages * @param consistency_level * @throws IOException */ //write1.0insertLocalhintedEndpointsby Hycz private static void sendToHintedEndpoints(final RowMutation rm, Multimap<InetAddress, InetAddress> hintedEndpoints, IWriteResponseHandler responseHandler, String localDataCenter, boolean insertLocalMessages, ConsistencyLevel consistency_level) throws IOException { // Multimap that holds onto all the messages and addresses meant for a specific datacenter Map<String, Multimap<Message, InetAddress>> dcMessages = new HashMap<String, Multimap<Message, InetAddress>>( hintedEndpoints.size()); MessageProducer producer = new CachingMessageProducer(rm); for (Map.Entry<InetAddress, Collection<InetAddress>> entry : hintedEndpoints.asMap().entrySet()) { InetAddress destination = entry.getKey(); Collection<InetAddress> targets = entry.getValue(); String dc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(destination); if (targets.size() == 1 && targets.iterator().next().equals(destination)) { // // unhinted writes if (destination.equals(FBUtilities.getLocalAddress())) { if (insertLocalMessages) insertLocal(rm, responseHandler); } // else { // belongs on a different server if (logger.isDebugEnabled()) logger.debug( "insert writing key " + ByteBufferUtil.bytesToHex(rm.key()) + " to " + destination); Multimap<Message, InetAddress> messages = dcMessages.get(dc); if (messages == null) { messages = HashMultimap.create(); dcMessages.put(dc, messages); } messages.put(producer.getMessage(Gossiper.instance.getVersion(destination)), destination); } } // hint else { // hinted messages are unique, so there is no point to adding a hop by forwarding via another node. // thus, we use sendRR/sendOneWay directly here. Message hintedMessage = rm.getMessage(Gossiper.instance.getVersion(destination)); for (InetAddress target : targets) { if (!target.equals(destination)) { addHintHeader(hintedMessage, target); if (logger.isDebugEnabled()) logger.debug("insert writing key " + ByteBufferUtil.bytesToHex(rm.key()) + " to " + destination + " for " + target); } } // non-destination hints are part of the callback and count towards consistency only under CL.ANY if (targets.contains(destination) || consistency_level == ConsistencyLevel.ANY) MessagingService.instance().sendRR(hintedMessage, destination, responseHandler); else MessagingService.instance().sendOneWay(hintedMessage, destination); } } // sendMessages(localDataCenter, dcMessages, responseHandler); }
From source file:com.cloudera.sqoop.util.TestDirectImportUtils.java
public void testLocalhost() throws UnknownHostException { InetAddress localHostAddr = InetAddress.getLocalHost(); LOG.info("Advertised localhost address: " + localHostAddr); InetAddress requestAddr = InetAddress.getByName("localhost"); LOG.info("Requested localhost address: " + requestAddr); assertTrue(/*from w w w. j a v a 2 s .c o m*/ "Requested addr does not identify as localhost. " + "Check /etc/hosts (see TestDirectImportUtils comments)", localHostAddr.equals(requestAddr)); assertTrue( "Couldn't match 'localhost' to localhost; " + "check /etc/hosts (see TestDirectImportUtils comments)", DirectImportUtils.isLocalhost("localhost")); }
From source file:org.apache.axis.utils.Admin.java
/** * host validation logic goes here// w w w . j a va 2s . c om * @param msgContext * @throws AxisFault */ private void verifyHostAllowed(MessageContext msgContext) throws AxisFault { /** For now, though - make sure we can only admin from our own * IP, unless the remoteAdmin option is set. */ Handler serviceHandler = msgContext.getService(); if (serviceHandler != null && !JavaUtils.isTrueExplicitly(serviceHandler.getOption("enableRemoteAdmin"))) { String remoteIP = msgContext.getStrProp(Constants.MC_REMOTE_ADDR); if (remoteIP != null && !(remoteIP.equals(NetworkUtils.LOCALHOST) || remoteIP.equals(NetworkUtils.LOCALHOST_IPV6))) { try { InetAddress myAddr = InetAddress.getLocalHost(); InetAddress remoteAddr = InetAddress.getByName(remoteIP); if (log.isDebugEnabled()) { log.debug("Comparing remote caller " + remoteAddr + " to " + myAddr); } if (!myAddr.equals(remoteAddr)) { log.error(Messages.getMessage("noAdminAccess01", remoteAddr.toString())); throw new AxisFault("Server.Unauthorized", Messages.getMessage("noAdminAccess00"), null, null); } } catch (UnknownHostException e) { throw new AxisFault("Server.UnknownHost", Messages.getMessage("unknownHost00"), null, null); } } } }
From source file:nl.mindef.c2sc.nbs.olsr.pud.uplink.server.cluster.impl.RelayClusterReceiverImpl.java
@Override public void run() { byte[] receiveBuffer = new byte[UplinkReceiver.BUFFERSIZE]; DatagramPacket packet = new DatagramPacket(receiveBuffer, receiveBuffer.length); while (this.run.get()) { try {//www. jav a 2s .co m this.sock.receive(packet); InetAddress ip = packet.getAddress(); int port = packet.getPort(); if (this.logger.isDebugEnabled()) { this.logger.debug("received packet from RelayServer " + ip.getHostAddress() + ":" + port); } RelayServer me = this.relayServers.getMe(); if (!(ip.equals(me.getIp()) && (port != this.relayClusterUdpPort))) { DatagramPacket msg = RelayClusterMessage.fromWireFormat(packet, this.reportOnce); if (msg != null) { RelayServer rs = this.relayServers.getOrAdd(ip, port); boolean packetCausedUpdate = this.packetHandler.processPacket(rs, msg); if (this.relayClusterForwarding && packetCausedUpdate) { if (this.logger.isDebugEnabled()) { this.logger.debug( "forwarding packet from RelayServer " + ip.getHostAddress() + ":" + port); } this.relayClusterSender.addPacket(rs, msg); } } else { this.logger.error("Could not convert RelayClusterMessage from wire format"); } } else { if (this.logger.isDebugEnabled()) { this.logger.debug("skipping packet from RelayServer " + ip.getHostAddress() + ":" + port + " since the packet came from me"); } } } catch (Exception e) { if (!SocketException.class.equals(e.getClass())) { e.printStackTrace(); } } } if (this.sock != null) { this.sock.close(); this.sock = null; } }
From source file:com.bigdata.dastor.locator.TokenMetadata.java
public void addBootstrapToken(Token token, InetAddress endpoint) { assert token != null; assert endpoint != null; lock.writeLock().lock();//from www. j a v a 2 s . c o m try { InetAddress oldEndPoint = null; oldEndPoint = bootstrapTokens.get(token); if (oldEndPoint != null && !oldEndPoint.equals(endpoint)) throw new RuntimeException("Bootstrap Token collision between " + oldEndPoint + " and " + endpoint + " (token " + token); oldEndPoint = tokenToEndPointMap.get(token); if (oldEndPoint != null && !oldEndPoint.equals(endpoint)) throw new RuntimeException("Bootstrap Token collision between " + oldEndPoint + " and " + endpoint + " (token " + token); bootstrapTokens.inverse().remove(endpoint); bootstrapTokens.put(token, endpoint); } finally { lock.writeLock().unlock(); } }
From source file:org.apache.cassandra.dht.BootStrapperTest.java
@Test public void testGuessToken() throws IOException { StorageService ss = StorageService.instance; generateFakeEndpoints(5);/* ww w . ja va2s. c o m*/ InetAddress two = InetAddress.getByName("127.0.0.2"); InetAddress three = InetAddress.getByName("127.0.0.3"); InetAddress four = InetAddress.getByName("127.0.0.4"); InetAddress five = InetAddress.getByName("127.0.0.5"); Map<InetAddress, Double> load = new HashMap<InetAddress, Double>(); load.put(two, 2.0); load.put(three, 3.0); load.put(four, 4.0); load.put(five, 5.0); TokenMetadata tmd = ss.getTokenMetadata(); InetAddress source = BootStrapper.getBootstrapSource(tmd, load); assert five.equals(source) : five + " != " + source; InetAddress myEndpoint = InetAddress.getByName("127.0.0.1"); Range range5 = ss.getPrimaryRangeForEndpoint(five); Token fakeToken = StorageService.getPartitioner().midpoint(range5.left, range5.right); assert range5.contains(fakeToken); ss.onChange(myEndpoint, ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(fakeToken)); tmd = ss.getTokenMetadata(); InetAddress source4 = BootStrapper.getBootstrapSource(tmd, load); assert four.equals(source4) : four + " != " + source4; }