- TimeUnit unit = TimeUnit.MILLISECONDS;
- if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() == null) {
- return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit));
- }
- if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() != null) {
- return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit, getTicksPerWheel()));
- }
- if (getTickDuration() == null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) {
- return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency()));
- }
- if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) {
- return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(),
- unit));
- }
- if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() != null) {
- return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(),
- unit, getTicksPerWheel()));
- }
- return new HashedWheelTimerCloseable(new HashedWheelTimer());
- }
-
- static final private class HashedWheelTimerCloseable implements AutoCloseable, Timer {
-
- private final Timer timer;
-
- public HashedWheelTimerCloseable(Timer timer) {
- this.timer = timer;
- }
-
- @Override
- public void close() throws Exception {
- stop();
- }
-
- @Override
- public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
- return this.timer.newTimeout(task, delay, unit);
- }
-
- @Override
- public Set<Timeout> stop() {
- return this.timer.stop();
- }
-