Java Code Examples for java.net.InetSocketAddress#equals()
The following examples show how to use
java.net.InetSocketAddress#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMDelegationTokenIdentifier.java From hadoop with Apache License 2.0 | 6 votes |
private static ApplicationClientProtocol getRmClient(Token<?> token, Configuration conf) throws IOException { String[] services = token.getService().toString().split(","); for (String service : services) { InetSocketAddress addr = NetUtils.createSocketAddr(service); if (localSecretManager != null) { // return null if it's our token if (localServiceAddress.getAddress().isAnyLocalAddress()) { if (NetUtils.isLocalAddress(addr.getAddress()) && addr.getPort() == localServiceAddress.getPort()) { return null; } } else if (addr.equals(localServiceAddress)) { return null; } } } return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); }
Example 2
Source File: DriverConductor.java From aeron with Apache License 2.0 | 6 votes |
void onReResolveControl( final String control, final UdpChannel udpChannel, final ReceiveChannelEndpoint channelEndpoint, final InetSocketAddress address) { final InetSocketAddress newAddress; try { newAddress = UdpChannel.resolve(control, CommonContext.MDC_CONTROL_PARAM_NAME, true, nameResolver); if (!address.equals(newAddress)) { receiverProxy.onResolutionChange(channelEndpoint, udpChannel, newAddress); } } catch (final UnknownHostException ex) { LangUtil.rethrowUnchecked(ex); } }
Example 3
Source File: DFSUtil.java From RDFS with Apache License 2.0 | 6 votes |
/** * Given the InetSocketAddress for any configured communication with a * namenode, this method returns the corresponding nameservice ID, * by doing a reverse lookup on the list of nameservices until it * finds a match. * If null is returned, client should try {@link #isDefaultNamenodeAddress} * to check pre-Federated configurations. * Since the process of resolving URIs to Addresses is slightly expensive, * this utility method should not be used in performance-critical routines. * * @param conf - configuration * @param address - InetSocketAddress for configured communication with NN. * Configured addresses are typically given as URIs, but we may have to * compare against a URI typed in by a human, or the server name may be * aliased, so we compare unambiguous InetSocketAddresses instead of just * comparing URI substrings. * @param keys - list of configured communication parameters that should * be checked for matches. For example, to compare against RPC addresses, * provide the list DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, * DFS_NAMENODE_RPC_ADDRESS_KEY. Use the generic parameter keys, * not the NameServiceId-suffixed keys. * @return nameserviceId, or null if no match found */ public static String getNameServiceIdFromAddress(Configuration conf, InetSocketAddress address, String... keys) { Collection<String> nameserviceIds = getNameServiceIds(conf); // Configuration with a single namenode and no nameserviceId if (nameserviceIds == null || nameserviceIds.isEmpty()) { // client should try {@link isDefaultNamenodeAddress} instead return null; } // Get the candidateAddresses for all the configured nameServiceIds for (String nameserviceId : nameserviceIds) { for (String key : keys) { String candidateAddress = conf.get( getNameServiceIdKey(key, nameserviceId)); if (candidateAddress != null && address.equals(NetUtils.createSocketAddr(candidateAddress))) return nameserviceId; } } // didn't find a match // client should try {@link isDefaultNamenodeAddress} instead return null; }
Example 4
Source File: NamingTest.java From reef with Apache License 2.0 | 6 votes |
private boolean isEqual(final Map<Identifier, InetSocketAddress> map1, final Map<Identifier, InetSocketAddress> map2) { if (map1.size() != map2.size()) { return false; } for (final Identifier id : map1.keySet()) { final InetSocketAddress addr1 = map1.get(id); final InetSocketAddress addr2 = map2.get(id); if (!addr1.equals(addr2)) { return false; } } return true; }
Example 5
Source File: RPC.java From RDFS with Apache License 2.0 | 6 votes |
private synchronized InetSocketAddress getAddress() { if (needCheckDnsUpdate && address != null && address.getHostName() != null && System.currentTimeMillis() - this.timeLastDnsCheck > MIN_DNS_CHECK_INTERVAL_MSEC) { try { String hostName = address.getHostName() + ":" + address.getPort(); InetSocketAddress newAddr = NetUtils.createSocketAddr(hostName); if (!newAddr.equals(address)) { LOG.info("DNS change: " + newAddr); address = newAddr; } } finally { this.timeLastDnsCheck = System.currentTimeMillis(); } } needCheckDnsUpdate = false; return address; }
Example 6
Source File: RakNetClient.java From JRakNet with MIT License | 6 votes |
/** * Called by the {@link com.whirvis.jraknet.client.RakNetClientHandler * RakNetClientHander} when it catches a <code>Throwable</code> while * handling a packet. * * @param address * the address that caused the exception. * @param cause * the <code>Throwable</code> caught by the handler. * @throws NullPointerException * if the cause <code>address</code> or <code>cause</code> are * <code>null</code>. */ protected final void handleHandlerException(InetSocketAddress address, Throwable cause) throws NullPointerException { if (address == null) { throw new NullPointerException("Address cannot be null"); } else if (cause == null) { throw new NullPointerException("Cause cannot be null"); } else if (peerFactory != null) { if (address.equals(peerFactory.getAddress())) { peerFactory.exceptionCaught(new NettyHandlerException(this, handler, address, cause)); } } else if (peer != null) { if (address.equals(peer.getAddress())) { this.disconnect(cause); } } logger.warn("Handled exception " + cause.getClass().getName() + " caused by address " + address); this.callEvent(listener -> listener.onHandlerException(this, address, cause)); }
Example 7
Source File: RMDelegationTokenIdentifier.java From big-c with Apache License 2.0 | 6 votes |
private static ApplicationClientProtocol getRmClient(Token<?> token, Configuration conf) throws IOException { String[] services = token.getService().toString().split(","); for (String service : services) { InetSocketAddress addr = NetUtils.createSocketAddr(service); if (localSecretManager != null) { // return null if it's our token if (localServiceAddress.getAddress().isAnyLocalAddress()) { if (NetUtils.isLocalAddress(addr.getAddress()) && addr.getPort() == localServiceAddress.getPort()) { return null; } } else if (addr.equals(localServiceAddress)) { return null; } } } return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); }
Example 8
Source File: DFSUtil.java From big-c with Apache License 2.0 | 6 votes |
/** * 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, String, String, AddressMatcher) */ 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; }
Example 9
Source File: RakNetClient.java From JRakNet with MIT License | 6 votes |
/** * Handles a packet received by the {@link RakNetClientHandler}. * * @param sender * the address of the sender. * @param packet * the packet to handle. * @throws NullPointerException * if the <code>sender</code> or <code>packet</code> are * <code>null</code>. */ protected final void handleMessage(InetSocketAddress sender, RakNetPacket packet) throws NullPointerException { if (sender == null) { throw new NullPointerException("Sender cannot be null"); } else if (packet == null) { throw new NullPointerException("Packet cannot be null"); } else if (peerFactory != null) { if (sender.equals(peerFactory.getAddress())) { RakNetServerPeer peer = peerFactory.assemble(packet); if (peer != null) { this.peer = peer; this.peerFactory = null; } } } else if (peer != null) { peer.handleInternal(packet); } logger.trace("Handled " + RakNetPacket.getName(packet) + " packet from " + sender); }
Example 10
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 5 votes |
public boolean slaveUp(ClientConnectionsEntry entry, FreezeReason freezeReason) { if (!slaveBalancer.unfreeze(entry, freezeReason)) { return false; } InetSocketAddress addr = masterEntry.getClient().getAddr(); // exclude master from slaves if (!config.checkSkipSlavesInit() && !addr.equals(entry.getClient().getAddr())) { if (slaveDown(addr, FreezeReason.SYSTEM)) { log.info("master {} excluded from slaves", addr); } } return true; }
Example 11
Source File: SubCreator.java From SubServers-2 with Apache License 2.0 | 5 votes |
/** * Check if an address has been reserved * * @param address Address to check * @return Reserved Status */ public static boolean isReserved(InetSocketAddress address) { boolean reserved = false; for (InetSocketAddress list : getAllReservedAddresses()) { if (list.equals(address)) reserved = true; } return reserved; }
Example 12
Source File: PRUDPPacketHandlerSocks.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
private void checkAddress( InetSocketAddress destination ) throws PRUDPPacketHandlerException { if ( !destination.equals( target )){ throw( new PRUDPPacketHandlerException( "Destination mismatch" )); } }
Example 13
Source File: AZInstanceManagerImpl.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
protected Map modifyAddress( Map map, InetSocketAddress key, InetSocketAddress value, boolean add ) { // System.out.println( "ModAddress: " + key + " -> " + value + " - " + (add?"add":"remove")); InetSocketAddress old_value = (InetSocketAddress)map.get(key); boolean same = old_value != null && old_value.equals( value ); Map new_map = map; if ( add ){ if ( !same ){ new_map = new HashMap( map ); new_map.put( key, value ); } }else{ if ( same ){ new_map = new HashMap( map ); new_map.remove( key ); } } return( new_map ); }
Example 14
Source File: DnsSocketAddressProvider.java From pinpoint with Apache License 2.0 | 5 votes |
private void checkDnsUpdate(InetSocketAddress updateAddress) { synchronized(this) { final InetSocketAddress oldAddress = this.oldAddress; if (oldAddress != null) { if (!oldAddress.equals(updateAddress)) { logger.info("host address updated, host:{} old:{}, update:{}", host, oldAddress, updateAddress); } } this.oldAddress = updateAddress; } }
Example 15
Source File: DataNode.java From big-c with Apache License 2.0 | 5 votes |
/** * @param addr rpc address of the namenode * @return true if the datanode is connected to a NameNode at the * given address */ public boolean isConnectedToNN(InetSocketAddress addr) { for (BPOfferService bpos : getAllBpOs()) { for (BPServiceActor bpsa : bpos.getBPServiceActors()) { if (addr.equals(bpsa.getNNSocketAddress())) { return bpsa.isAlive(); } } } return false; }
Example 16
Source File: AbruptClientDisconnectTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Override public void clientDisconnected(final InetSocketAddress clientAddress) { if (clientAddress.equals(getClientAddress())) { _closeLatch.countDown(); } }
Example 17
Source File: DataNode.java From hadoop with Apache License 2.0 | 5 votes |
/** * @param addr rpc address of the namenode * @return true if the datanode is connected to a NameNode at the * given address */ public boolean isConnectedToNN(InetSocketAddress addr) { for (BPOfferService bpos : getAllBpOs()) { for (BPServiceActor bpsa : bpos.getBPServiceActors()) { if (addr.equals(bpsa.getNNSocketAddress())) { return bpsa.isAlive(); } } } return false; }
Example 18
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 5 votes |
public boolean slaveUp(InetSocketAddress address, FreezeReason freezeReason) { if (!slaveBalancer.unfreeze(address, freezeReason)) { return false; } InetSocketAddress addr = masterEntry.getClient().getAddr(); // exclude master from slaves if (!config.checkSkipSlavesInit() && !addr.equals(address)) { if (slaveDown(addr, FreezeReason.SYSTEM)) { log.info("master {} excluded from slaves", addr); } } return true; }
Example 19
Source File: ServerUpdater.java From Core with MIT License | 4 votes |
private void addServer(ContainerEvent eventData) { ServerInfo serverInfo = this.getServerInfoForEvent(eventData); if (serverInfo.getAddress().getHostName() == null) { this.logger.warning("[Server Updater] Could not add server:" + serverInfo.getName()); this.logger.warning("[Server Updater] > Reason: No IP, is you network fine?"); this.logger.warning("[Server Updater] > Trigger-Event-Action: " + eventData.getAction()); return; } if (this.proxyServer.getServers().containsKey(serverInfo.getName())) { if (this.debug) { this.logger.warning("[Server Updater] Server with id " + serverInfo.getName() + " already exists in Bungeecord Proxy."); } InetSocketAddress currentAddress = this.proxyServer.getServers().get(serverInfo.getName()).getAddress(); if (!currentAddress.equals(serverInfo.getAddress())) { if (this.debug) { this.logger.warning("[Server Updater] > Server address of " + serverInfo.getName() + "changed!"); this.logger.warning("[Server Updater] >> Current: " + currentAddress.toString()); this.logger.warning("[Server Updater] >> New: " + serverInfo.getAddress().toString()); this.logger.warning("[Server Updater] >> Server removed from proxy to re-add it"); } this.proxyServer.getServers().remove(serverInfo.getName()); } else { if (this.debug) { this.logger.warning("[Server Updater] > Skipped!"); this.logger.warning("[Server Updater] > Trigger-Event-Action: " + eventData.getAction()); } return; } } this.proxyServer.getPluginManager().callEvent(new PreAddServerEvent( serverInfo, eventData.getEnvironmentVariables() )); this.proxyServer.getServers().put(serverInfo.getName(), serverInfo); this.logger.info("[Server Updater] Added server: " + serverInfo.getName()); this.logger.info("[Server Updater] > Address: " + serverInfo.getAddress().toString()); this.logger.info("[Server Updater] > MOTD: " + serverInfo.getMotd()); this.logger.info("[Server Updater] > Trigger-Event-Action: " + eventData.getAction()); this.proxyServer.getPluginManager().callEvent(new PostAddServerEvent( serverInfo, eventData.getEnvironmentVariables() )); }
Example 20
Source File: DFSUtil.java From RDFS with Apache License 2.0 | 3 votes |
/** * Given the InetSocketAddress for any configured communication with a * namenode, this method determines whether it is the configured * communication channel for the "default" namenode. * It does a reverse lookup on the list of default communication parameters * to see if the given address matches any of them. * Since the process of resolving URIs to Addresses is slightly expensive, * this utility method should not be used in performance-critical routines. * * @param conf - configuration * @param address - InetSocketAddress for configured communication with NN. * Configured addresses are typically given as URIs, but we may have to * compare against a URI typed in by a human, or the server name may be * aliased, so we compare unambiguous InetSocketAddresses instead of just * comparing URI substrings. * @param keys - list of configured communication parameters that should * be checked for matches. For example, to compare against RPC addresses, * provide the list DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, * DFS_NAMENODE_RPC_ADDRESS_KEY * @return - boolean confirmation if matched generic parameter */ public static boolean isDefaultNamenodeAddress(Configuration conf, InetSocketAddress address, String... keys) { for (String key : keys) { String candidateAddress = conf.get(key); if (candidateAddress != null && address.equals(NetUtils.createSocketAddr(candidateAddress))) return true; } return false; }