import static java.util.Objects.requireNonNull;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public final class DefaultInstructionSchedulerFactory implements InstructionSchedulerFactory, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(DefaultInstructionSchedulerFactory.class);
+ private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder()
+ .setNameFormat("programming-timer-%d")
+ .setDaemon(true)
+ .build();
+ private final ExecutorService exec = Executors.newSingleThreadExecutor();
+ private final Timer timer = new HashedWheelTimer(THREAD_FACTORY);
private final DataBroker dataProvider;
private final NotificationPublishService notifs;
- private final Timer timer;
private final RpcProviderService rpcProviderRegistry;
private final ClusterSingletonServiceProvider cssp;
- private final ExecutorService exec = Executors.newSingleThreadExecutor();
@Inject
@Activate
public DefaultInstructionSchedulerFactory(@Reference final DataBroker dataProvider,
@Reference final RpcProviderService rpcProviderRegistry,
@Reference final NotificationPublishService notifs,
- @Reference(target = "(type=global-timer)") final Timer timer,
@Reference final ClusterSingletonServiceProvider cssp) {
this.dataProvider = requireNonNull(dataProvider);
this.notifs = requireNonNull(notifs);
- this.timer = requireNonNull(timer);
this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
this.cssp = requireNonNull(cssp);
}
public void close() {
// FIXME: This can have weird effects: should we keep track of all schedulers and refcount?
exec.shutdown();
+ timer.stop();
}
}