Esempio n. 1
0
    public void onUp(Host host) {
      HostConnectionPool previous = addHost(host);
      ;
      loadBalancer.onUp(host);

      // This should not be necessary but it's harmless
      if (previous != null) previous.shutdown();
    }
Esempio n. 2
0
    private boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException {

      if (!isShutdown.compareAndSet(false, true)) return true;

      long start = System.nanoTime();
      boolean success = true;
      for (HostConnectionPool pool : pools.values())
        success &= pool.shutdown(timeout - Cluster.timeSince(start, unit), unit);
      return success;
    }
Esempio n. 3
0
    public void onAdd(Host host) {
      HostConnectionPool previous = addHost(host);
      ;
      loadBalancer.onAdd(host);

      // This should not be necessary, especially since the host is
      // supposed to be new, but it's safer to make that work correctly
      // if the even is triggered multiple times.
      if (previous != null) previous.shutdown();
    }
Esempio n. 4
0
    /*
     * When the set of live nodes change, the loadbalancer will change his
     * mind on host distances. It might change it on the node that came/left
     * but also on other nodes (for instance, if a node dies, another
     * previously ignored node may be now considered).
     *
     * This method ensures that all hosts for which a pool should exist
     * have one, and hosts that shouldn't don't.
     */
    private void updateCreatedPools() {
      for (Host h : cluster.getMetadata().allHosts()) {
        HostDistance dist = loadBalancingPolicy().distance(h);
        HostConnectionPool pool = pools.get(h);

        if (pool == null) {
          if (dist != HostDistance.IGNORED && h.getMonitor().isUp()) addOrRenewPool(h);
        } else if (dist != pool.hostDistance) {
          if (dist == HostDistance.IGNORED) {
            removePool(h);
          } else {
            pool.hostDistance = dist;
          }
        }
      }
    }
Esempio n. 5
0
    public void onDown(Host host) {
      loadBalancer.onDown(host);
      HostConnectionPool pool = pools.remove(host);

      // This should not be necessary but it's harmless
      if (pool != null) pool.shutdown();

      // If we've remove a host, the loadBalancer is allowed to change his mind on host distances.
      for (Host h : cluster.getMetadata().allHosts()) {
        if (!h.getMonitor().isUp()) continue;

        HostDistance dist = loadBalancer.distance(h);
        if (dist != HostDistance.IGNORED) {
          HostConnectionPool p = pools.get(h);
          if (p == null) addHost(host);
          else p.hostDistance = dist;
        }
      }
    }
Esempio n. 6
0
 private void removePool(Host host) {
   HostConnectionPool pool = pools.remove(host);
   if (pool != null) pool.shutdown();
 }
Esempio n. 7
0
 public void onRemove(Host host) {
   loadBalancer.onRemove(host);
   HostConnectionPool pool = pools.remove(host);
   if (pool != null) pool.shutdown();
 }
Esempio n. 8
0
    private void shutdown() {

      if (!isShutdown.compareAndSet(false, true)) return;

      for (HostConnectionPool pool : pools.values()) pool.shutdown();
    }