package me.prettyprint.cassandra.connection;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;

import me.prettyprint.cassandra.service.CassandraHostConfigurator;

public abstract class BackgroundCassandraHostService {

  protected ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

  protected final HConnectionManager connectionManager;
  protected final CassandraHostConfigurator cassandraHostConfigurator;

  protected ScheduledFuture sf;
  protected int retryDelayInSeconds;

  public BackgroundCassandraHostService(HConnectionManager connectionManager,
      CassandraHostConfigurator cassandraHostConfigurator) {
    this.connectionManager = connectionManager;
    this.cassandraHostConfigurator = cassandraHostConfigurator;
    
  }

  abstract void shutdown();

  abstract void applyRetryDelay();



  public int getRetryDelayInSeconds() {
    return retryDelayInSeconds;
  }

  public void setRetryDelayInSeconds(int retryDelayInSeconds) {
    this.retryDelayInSeconds = retryDelayInSeconds;
  }

}

@@ -176,16 +176,109 @@
 dFuture;
+%0Aimport java.util.concurrent.ThreadFactory;%0Aimport java.util.concurrent.atomic.AtomicInteger;
 %0A%0Aimport
@@ -399,32 +399,38 @@
  %7B%0A%0A  protected 
+final 
 ScheduledExecuto
@@ -450,55 +450,8 @@
 utor
- = Executors.newSingleThreadScheduledExecutor()
 ;%0A%0A 
@@ -604,16 +604,19 @@
 edFuture
+%3C?%3E
  sf;%0A  p
@@ -785,24 +785,156 @@
 igurator) %7B%0A
+    executor = Executors.newScheduledThreadPool(1, new DaemonThreadPoolFactory(%22Hector.%22 + getClass().getSimpleName() + %22Thread%22));%0A
     this.con
@@ -1311,7 +1311,477 @@
   %7D%0A
+  %0A  private static class DaemonThreadPoolFactory implements ThreadFactory %7B%0A%0A    private static final AtomicInteger count = new AtomicInteger(); %0A    private final String name;%0A%0A    public DaemonThreadPoolFactory(String name) %7B%0A      this.name = name;%0A    %7D%0A%0A    @Override%0A    public Thread newThread(Runnable r) %7B%0A        Thread t = new Thread(r);%0A        t.setDaemon(true);%0A        t.setName(name + %22-%22 + count.incrementAndGet());%0A        return t;%0A    %7D%0A      %0A  %7D%0A%0A%7D
 %0A
-%7D
 %0A

Fix for issue #220 Threads started by Hector should be marked as daemon-threads