@Override public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof EstimateMapKey)) { return false; } EstimateMapKey that = (EstimateMapKey) obj; return this.clientId.equals(that.clientId) && this.serverId.equals(that.serverId); } }
/** * If it is most loaded then return its LoadHolder; otherwise return null; */ private LoadHolder isCurrentServerMostLoaded(ServerLocation currentServer, Map<ServerLocation, LoadHolder> groupServers) { final LoadHolder currentLH = groupServers.get(currentServer); if (currentLH == null) return null; final float currentLoad = currentLH.getLoad(); for (Map.Entry<ServerLocation, LoadHolder> loadEntry : groupServers.entrySet()) { ServerLocation location = loadEntry.getKey(); if (location.equals(currentServer)) { continue; } LoadHolder nextLoadReference = loadEntry.getValue(); float nextLoad = nextLoadReference.getLoad(); if (nextLoad > currentLoad) { // found a server who has a higher load than us return null; } } return currentLH; }
/** * Return true if we have a connection to the currentServer whose lifetime has expired. * Otherwise return false; */ public synchronized boolean hasExpiredCnxToServer(ServerLocation currentServer) { if (!this.allConnections.isEmpty()) { final long now = System.nanoTime(); for (Iterator it = this.allConnections.iterator(); it.hasNext();) { PooledConnection pc = (PooledConnection) it.next(); if (pc.shouldDestroy()) { // this con has already been destroyed so ignore it continue; } else if (currentServer.equals(pc.getServer())) { { long life = pc.remainingLife(now, lifetimeTimeoutNanos); if (life <= 0) { return true; } } } } } return false; }
/** * Returns a pooled connection that can have its underlying cnx to currentServer replaced by a * new connection. * * @return null if a target could not be found */ public synchronized PooledConnection findReplacementTarget(ServerLocation currentServer) { final long now = System.nanoTime(); for (Iterator it = this.allConnections.iterator(); it.hasNext();) { PooledConnection pc = (PooledConnection) it.next(); if (currentServer.equals(pc.getServer())) { if (!pc.shouldDestroy() && pc.remainingLife(now, lifetimeTimeoutNanos) <= 0) { removeFromEndpointMap(pc); return pc; } } } return null; }
this.connectionManager.activate(conn); borrow = false; if (!conn.getServer().equals(server)) {
/** * Extend the life of the first expired connection to sl. */ public synchronized void extendLifeOfCnxToServer(ServerLocation sl) { if (!this.allConnections.isEmpty()) { final long now = System.nanoTime(); for (Iterator it = this.allConnections.iterator(); it.hasNext();) { PooledConnection pc = (PooledConnection) it.next(); if (pc.remainingLife(now, lifetimeTimeoutNanos) > 0) { // no more connections whose lifetime could have expired break; // note don't ignore idle connections because they are still connected // } else if (pc.remainingIdle(now, idleTimeoutNanos) <= 0) { // // this con has already idle expired so ignore it } else if (pc.shouldDestroy()) { // this con has already been destroyed so ignore it } else if (sl.equals(pc.getEndpoint().getLocation())) { // we found a connection to whose lifetime we can extend it.remove(); pc.setBirthDate(now); getPoolStats().incLoadConditioningExtensions(); this.allConnections.add(pc); // break so we only do this to the oldest connection break; } } } }
try { nextConnection.activate(); if (nextConnection.getServer().equals(server)) { itr.remove(); return nextConnection;
if (sl.equals(currentServer)) { this.allConnectionsMap.extendLifeOfCnxToServer(currentServer); break;
|| !this.connection.getServer().equals(this.sender.getServerLocation())) { if (logger.isDebugEnabled()) { logger.debug(