Example usage for java.net InetSocketAddress equals

List of usage examples for java.net InetSocketAddress equals

Introduction

In this page you can find the example usage for java.net InetSocketAddress equals.

Prototype

@Override
public final boolean equals(Object obj) 

Source Link

Document

Compares this object against the specified object.

Usage

From source file:com.dotmarketing.business.MemcachedCacheAdministratorImpl.java

public void removeServer(String inetAddress) {
    synchronized (this) {
        try {//  w w w .  j av a2 s  .  com
            Logger.info(this.getClass(), "***\t Memcached Config removing server:" + inetAddress);
            boolean reset = false;

            List<InetSocketAddress> newServers = new ArrayList<InetSocketAddress>();
            List<Integer> newWeights = new ArrayList<Integer>();
            InetSocketAddress addr = AddrUtil.getOneAddress(inetAddress);
            for (int i = 0; i < _servers.size(); i++) {
                InetSocketAddress ip = _servers.get(i);
                if (ip.equals(addr) || ip.toString().endsWith(addr.toString())) {
                    reset = true;
                } else {
                    newServers.add(ip);
                    newWeights.add(_weights.get(i));
                }
            }
            if (reset) {
                MemcachedClient x = getClient();
                this._servers = newServers;
                this._weights = newWeights;
                this._client = null;
                x.shutdown();
                x = null;
            }
        } catch (Exception e) {
            Logger.error(this.getClass(), "No memcache client can be built:" + e.getMessage(), e);
        }
    }
}

From source file:com.dotmarketing.business.MemcachedCacheAdministratorImpl.java

public void addServer(String inetAddress, int weight) {
    synchronized (this) {
        Logger.info(this.getClass(), "***\t Memcached Config adding server:" + inetAddress + " " + weight);

        boolean reset = true;

        try {/*from w w  w. j  a  v a2 s. com*/
            List<InetSocketAddress> newServers = new ArrayList<InetSocketAddress>();
            List<Integer> newWeights = new ArrayList<Integer>();
            InetSocketAddress addr = AddrUtil.getOneAddress(inetAddress);
            newServers.add(addr);
            newWeights.add(weight);

            for (int i = 0; i < _servers.size(); i++) {
                InetSocketAddress ip = _servers.get(i);
                if (ip.equals(addr) || ip.toString().endsWith(addr.toString())) {
                    reset = false;
                } else {
                    newWeights.add(_weights.get(i));
                    newServers.add(ip);
                }
            }

            if (reset) {
                MemcachedClient x = getClient();
                this._servers = newServers;
                this._weights = newWeights;
                this._client = null;
                x.shutdown();
                x = null;
            }
        } catch (Exception e) {
            Logger.error(this.getClass(), "No memcache client can be built:" + e.getMessage(), e);
        }
    }
}

From source file:org.apache.hadoop.mapred.RemoteJTProxy.java

@Override
public InetSocketAddressWritable getNewJobTrackerAddress(InetSocketAddressWritable failedTracker)
        throws IOException {
    // Die immediately if restarting is disabled
    if (maxRemoteJTFailures == 0) {
        throw new IOException("Restarting remote JT is disabled.");
    }//from w  ww. j a v a2s.  com
    assert remoteJTAddr != null : "Not started, but got request to restart.";
    if (clientLock.readLock().tryLock()) {
        // We're not restarting, check address
        InetSocketAddress seenAddr = remoteJTAddr;
        clientLock.readLock().unlock();
        // seenAddr is safe to use, because even if restarting takes place, this
        // is the address of JT that either is fully running or dead
        // (not currently restarting)
        if (seenAddr.equals(failedTracker.getAddress())) {
            // Not restarted yet
            return null;
        } else {
            LOG.info("Serving new job tracker address request with " + seenAddr + " old "
                    + failedTracker.getAddress());
            return new InetSocketAddressWritable(seenAddr);
        }
    } else {
        // Currently restarting
        return null;
    }
}

From source file:org.apache.hadoop.hbase.master.TestRegionPlacement.java

/**
 * Verify all the online region servers has been updated to the
 * latest assignment plan/*from  www  . j  a  va2  s. c  om*/
 * @param plan
 * @throws IOException
 */
private void verifyRegionServerUpdated(FavoredNodesPlan plan) throws IOException {
    // Verify all region servers contain the correct favored nodes information
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    for (int i = 0; i < SLAVES; i++) {
        HRegionServer rs = cluster.getRegionServer(i);
        for (HRegion region : rs.getOnlineRegions(TableName.valueOf("testRegionAssignment"))) {
            InetSocketAddress[] favoredSocketAddress = rs
                    .getFavoredNodesForRegion(region.getRegionInfo().getEncodedName());
            List<ServerName> favoredServerList = plan.getAssignmentMap().get(region.getRegionInfo());

            // All regions are supposed to have favored nodes,
            // except for hbase:meta and ROOT
            if (favoredServerList == null) {
                HTableDescriptor desc = region.getTableDesc();
                // Verify they are ROOT and hbase:meta regions since no favored nodes
                assertNull(favoredSocketAddress);
                assertTrue("User region " + region.getTableDesc().getTableName() + " should have favored nodes",
                        (desc.isRootRegion() || desc.isMetaRegion()));
            } else {
                // For user region, the favored nodes in the region server should be
                // identical to favored nodes in the assignmentPlan
                assertTrue(favoredSocketAddress.length == favoredServerList.size());
                assertTrue(favoredServerList.size() > 0);
                for (int j = 0; j < favoredServerList.size(); j++) {
                    InetSocketAddress addrFromRS = favoredSocketAddress[j];
                    InetSocketAddress addrFromPlan = InetSocketAddress.createUnresolved(
                            favoredServerList.get(j).getHostname(), favoredServerList.get(j).getPort());

                    assertNotNull(addrFromRS);
                    assertNotNull(addrFromPlan);
                    assertTrue(
                            "Region server " + rs.getServerName().getHostAndPort() + " has the " + positions[j]
                                    + " for region " + region.getRegionNameAsString() + " is " + addrFromRS
                                    + " which is inconsistent with the plan " + addrFromPlan,
                            addrFromRS.equals(addrFromPlan));
                }
            }
        }
    }
}

From source file:org.apache.bookkeeper.client.TestRegionAwareEnsemblePlacementPolicy.java

@Test(timeout = 60000)
public void testReplaceBookieWithEnoughBookiesInDifferentRegion() throws Exception {
    InetSocketAddress addr1 = new InetSocketAddress("127.0.0.2", 3181);
    InetSocketAddress addr2 = new InetSocketAddress("127.0.0.3", 3181);
    InetSocketAddress addr3 = new InetSocketAddress("127.0.0.4", 3181);
    InetSocketAddress addr4 = new InetSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getAddress().getHostAddress(), NetworkTopology.DEFAULT_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getAddress().getHostAddress(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getAddress().getHostAddress(), "/region2/r3");
    StaticDNSResolver.addNodeToRack(addr4.getAddress().getHostAddress(), "/region3/r4");
    // Update cluster
    Set<InetSocketAddress> addrs = new HashSet<InetSocketAddress>();
    addrs.add(addr1);/*from w  w w  .ja v a2 s  .  c  o m*/
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<InetSocketAddress>());
    // replace node under r2
    Set<InetSocketAddress> excludedAddrs = new HashSet<InetSocketAddress>();
    excludedAddrs.add(addr1);
    InetSocketAddress replacedBookie = repp.replaceBookie(addr2, excludedAddrs);

    assertFalse(addr1.equals(replacedBookie));
    assertTrue(addr3.equals(replacedBookie) || addr4.equals(replacedBookie));
}

From source file:edu.umass.cs.reconfiguration.Reconfigurator.java

private AddressMessenger<JSONObject> getMessenger(InetSocketAddress receiver) {
    if (receiver.equals(this.consistentNodeConfig.getBindSocketAddress(this.getMyID()))) {
        log.log(Level.FINE, "{0} using messenger for {1}; bindAddress is {2}", new Object[] { this, receiver,
                this.consistentNodeConfig.getBindSocketAddress(this.getMyID()) });
        return this.messenger;
    } else {/*from   w  ww .  jav a 2 s.c  om*/
        log.log(Level.FINE, "{0} using clientMessenger for {1}; bindAddress is {2}", new Object[] { this,
                receiver, this.consistentNodeConfig.getBindSocketAddress(this.getMyID()) });
        return this.getClientMessenger(receiver);
    }
}

From source file:edu.umass.cs.reconfiguration.Reconfigurator.java

private boolean sendClientReconfigurationPacket(ClientReconfigurationPacket response) {
    try {//from   w ww .j  av  a  2 s .  com
        InetSocketAddress querier = this.getQuerier(response);
        if (querier.equals(response.getCreator())) {
            // only response can go back to client
            log.log(Level.INFO, "{0} sending client RESPONSE {1}:{2} back to client",
                    new Object[] { this, response.getSummary(), response.getResponseMessage(), querier });
            (this.getClientMessenger(response.getMyReceiver())).sendToAddress(querier,
                    new JSONMessenger.JSONObjectByteableWrapper(response
                    // .toJSONObject()
                    ));
        } else {
            // may be a request or response
            log.log(Level.INFO, "{0} sending {1} {2} to reconfigurator {3}", new Object[] { this,
                    response.isRequest() ? "request" : "RESPONSE", response.getSummary(), querier });
            assert (this.messenger.sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(response
            // .toJSONObject()
            )) > 0);
        }
    } catch (IOException /* | JSONException */ e) {
        log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage());
        e.printStackTrace();
    }
    return true;
}

From source file:edu.umass.cs.reconfiguration.Reconfigurator.java

private InetSocketAddress getQuerier(ClientReconfigurationPacket response) {
    InetSocketAddress forwarder = response.getForwader();
    InetSocketAddress me = this.consistentNodeConfig.getBindSocketAddress(getMyID());
    // if there is a forwarder that is not me, relay back
    if (forwarder != null && !forwarder.equals(me)) {
        return forwarder;
    } else {/*from   w w w.  j  ava  2 s . c o m*/
        // return directly to creator
        return response.getCreator();
    }
}

From source file:edu.umass.cs.reconfiguration.Reconfigurator.java

private InetSocketAddress getQuerier(RCRecordRequest<NodeIDType> rcRecReq) {
    InetSocketAddress forwarder = rcRecReq.startEpoch.getForwarder();
    InetSocketAddress me = this.consistentNodeConfig.getBindSocketAddress(getMyID());
    // if there is a forwarder that is not me, relay back
    if (forwarder != null && !forwarder.equals(me))
        return forwarder;
    else/* www.ja  va2 s.c  o  m*/
        // return directly to creator
        return rcRecReq.startEpoch.creator;
}

From source file:edu.umass.cs.reconfiguration.Reconfigurator.java

private void sendCreateConfirmationToClient(RCRecordRequest<NodeIDType> rcRecReq, String headName) {
    if (rcRecReq.startEpoch.creator == null || !rcRecReq.getInitiator().equals(getMyID()) || headName == null) {
        return;/*from  w  w  w .  j a  v  a2 s.  c  om*/
    }

    DelayProfiler.updateDelay(ProfilerKeys.create.toString(), rcRecReq.startEpoch.getInitTime());
    try {
        InetSocketAddress querier = this.getQuerier(rcRecReq);
        CreateServiceName response = (CreateServiceName) (new CreateServiceName(rcRecReq.startEpoch.creator,
                headName, rcRecReq.getEpochNumber(), null, rcRecReq.startEpoch.getMyReceiver()))
                        .setForwader(rcRecReq.startEpoch.getForwarder()).makeResponse();
        // need to use different messengers for client and forwarder
        if (querier.equals(rcRecReq.startEpoch.creator)) {
            log.log(Level.INFO, "{0} sending creation confirmation {1} back to client",
                    new Object[] { this, response.getSummary(), querier });
            // this.getClientMessenger()
            (this.getMessenger(rcRecReq.startEpoch.getMyReceiver())).sendToAddress(querier,
                    new JSONMessenger.JSONObjectByteableWrapper(response
                    // .toJSONObject()
                    ));
        } else {
            log.log(Level.INFO, "{0} sending creation confirmation {1} to forwarding reconfigurator {2}",
                    new Object[] { this, response.getSummary(), querier });
            this.messenger.sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(
                    response.setForwardee(this.consistentNodeConfig.getNodeSocketAddress(getMyID()))
            // .toJSONObject()
            ));
        }
    } catch (IOException /* | JSONException */ e) {
        log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage());
        e.printStackTrace();
    }
}