Browse Source
Merge pull request #519 from hand515/master
add ThreadFactory for HashedWheelTimer
master
Nikita Koksharov
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
23 additions and
5 deletions
-
src/main/java/com/corundumstudio/socketio/scheduler/HashedWheelScheduler.java
-
src/main/java/com/corundumstudio/socketio/scheduler/HashedWheelTimeoutScheduler.java
|
|
@ -15,19 +15,28 @@ |
|
|
|
*/ |
|
|
|
package com.corundumstudio.socketio.scheduler; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.ThreadFactory; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
|
import io.netty.util.HashedWheelTimer; |
|
|
|
import io.netty.util.Timeout; |
|
|
|
import io.netty.util.TimerTask; |
|
|
|
import io.netty.util.internal.PlatformDependent; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
public class HashedWheelScheduler implements CancelableScheduler { |
|
|
|
|
|
|
|
private final Map<SchedulerKey, Timeout> scheduledFutures = PlatformDependent.newConcurrentHashMap(); |
|
|
|
private final HashedWheelTimer executorService = new HashedWheelTimer(); |
|
|
|
private final HashedWheelTimer executorService; |
|
|
|
|
|
|
|
public HashedWheelScheduler() { |
|
|
|
executorService = new HashedWheelTimer(); |
|
|
|
} |
|
|
|
|
|
|
|
public HashedWheelScheduler(ThreadFactory threadFactory) { |
|
|
|
executorService = new HashedWheelTimer(threadFactory); |
|
|
|
} |
|
|
|
|
|
|
|
private volatile ChannelHandlerContext ctx; |
|
|
|
|
|
|
|
|
|
@ -31,15 +31,24 @@ import io.netty.util.TimerTask; |
|
|
|
import io.netty.util.internal.PlatformDependent; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentMap; |
|
|
|
import java.util.concurrent.ThreadFactory; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
public class HashedWheelTimeoutScheduler implements CancelableScheduler { |
|
|
|
|
|
|
|
private final ConcurrentMap<SchedulerKey, Timeout> scheduledFutures = PlatformDependent.newConcurrentHashMap(); |
|
|
|
private final HashedWheelTimer executorService = new HashedWheelTimer(); |
|
|
|
private final HashedWheelTimer executorService; |
|
|
|
|
|
|
|
private volatile ChannelHandlerContext ctx; |
|
|
|
|
|
|
|
public HashedWheelTimeoutScheduler() { |
|
|
|
executorService = new HashedWheelTimer(); |
|
|
|
} |
|
|
|
|
|
|
|
public HashedWheelTimeoutScheduler(ThreadFactory threadFactory) { |
|
|
|
executorService = new HashedWheelTimer(threadFactory); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void update(ChannelHandlerContext ctx) { |
|
|
|
this.ctx = ctx; |
|
|
|