mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-11 03:13:51 +00:00
del[thread]: delete SafeRunnable
This commit is contained in:
1 parent
9f6f154e76
commit
13d284184d
7 files changed
+26
-51
No files matched your search
@@ -18,8 +18,8 @@ import com.zfoo.protocol.collection.CollectionUtils;
|
||||
import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject;
|
||||
import com.zfoo.protocol.util.AssertionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.util.SafeRunnable;
|
||||
import com.zfoo.protocol.util.RandomUtils;
|
||||
import com.zfoo.util.ThreadUtils;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -134,7 +134,7 @@ public abstract class EventBus {
|
||||
* Use the event thread specified by the hashcode to execute the task
|
||||
*/
|
||||
public static void execute(int executorHash, Runnable runnable) {
|
||||
executors[Math.abs(executorHash % EXECUTORS_SIZE)].execute(SafeRunnable.valueOf(runnable));
|
||||
executors[Math.abs(executorHash % EXECUTORS_SIZE)].execute(ThreadUtils.safeRunnable(runnable));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ package com.zfoo.net.router.answer;
|
||||
|
||||
import com.zfoo.net.router.attachment.SignalAttachment;
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.util.SafeRunnable;
|
||||
import com.zfoo.util.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -34,7 +34,7 @@ public class AsyncAnswer<T extends IPacket> implements IAsyncAnswer<T> {
|
||||
|
||||
private Runnable askCallback;
|
||||
|
||||
private SafeRunnable notCompleteCallback;
|
||||
private Runnable notCompleteCallback;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -52,8 +52,8 @@ public class AsyncAnswer<T extends IPacket> implements IAsyncAnswer<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsyncAnswer<T> notComplete(SafeRunnable notCompleteCallback) {
|
||||
this.notCompleteCallback = notCompleteCallback;
|
||||
public IAsyncAnswer<T> notComplete(Runnable notCompleteCallback) {
|
||||
this.notCompleteCallback = ThreadUtils.safeRunnable(notCompleteCallback);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class AsyncAnswer<T extends IPacket> implements IAsyncAnswer<T> {
|
||||
this.askCallback = askCallback;
|
||||
}
|
||||
|
||||
public SafeRunnable getNotCompleteCallback() {
|
||||
public Runnable getNotCompleteCallback() {
|
||||
return notCompleteCallback;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
package com.zfoo.net.router.answer;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.util.SafeRunnable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -36,6 +35,6 @@ public interface IAsyncAnswer<T extends IPacket> {
|
||||
* EN:If the asynchronous request does not return successfully, the method is called
|
||||
* CN:如果异步请求没有成功返回,那么就会回调该方法
|
||||
*/
|
||||
IAsyncAnswer<T> notComplete(SafeRunnable notCompleteCallback);
|
||||
IAsyncAnswer<T> notComplete(Runnable notCompleteCallback);
|
||||
|
||||
}
|
||||
@@ -24,8 +24,8 @@ import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject;
|
||||
import com.zfoo.protocol.util.AssertionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.scheduler.manager.SchedulerBus;
|
||||
import com.zfoo.util.SafeRunnable;
|
||||
import com.zfoo.protocol.util.RandomUtils;
|
||||
import com.zfoo.util.ThreadUtils;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -172,7 +172,7 @@ public final class TaskBus {
|
||||
}
|
||||
|
||||
public static void execute(int taskExecutorHash, Runnable runnable) {
|
||||
executors[calTaskExecutorHash(taskExecutorHash)].execute(SafeRunnable.valueOf(runnable));
|
||||
executors[calTaskExecutorHash(taskExecutorHash)].execute(ThreadUtils.safeRunnable(runnable));
|
||||
}
|
||||
|
||||
public static void execute(Object argument, Runnable runnable) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.scheduler.SchedulerContext;
|
||||
import com.zfoo.scheduler.model.vo.SchedulerDefinition;
|
||||
import com.zfoo.scheduler.util.TimeUtils;
|
||||
import com.zfoo.util.SafeRunnable;
|
||||
import com.zfoo.util.ThreadUtils;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import org.slf4j.Logger;
|
||||
@@ -168,7 +167,7 @@ public abstract class SchedulerBus {
|
||||
*/
|
||||
public static ScheduledFuture<?> scheduleAtFixedRate(Runnable runnable, long period, TimeUnit unit) {
|
||||
|
||||
return executor.scheduleAtFixedRate(SafeRunnable.valueOf(runnable), 0, period, unit);
|
||||
return executor.scheduleAtFixedRate(ThreadUtils.safeRunnable(runnable), 0, period, unit);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +176,7 @@ public abstract class SchedulerBus {
|
||||
*/
|
||||
public static ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||
|
||||
return executor.schedule(SafeRunnable.valueOf(runnable), delay, unit);
|
||||
return executor.schedule(ThreadUtils.safeRunnable(runnable), delay, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,5 +111,19 @@ public abstract class ThreadUtils {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static Runnable safeRunnable(Runnable runnable) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Exception e) {
|
||||
logger.error("unknown exception", e);
|
||||
} catch (Throwable t) {
|
||||
logger.error("unknown error", t);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
|
||||
enum Num {
|
||||
ONE,
|
||||
TWO,
|
||||
THREE
|
||||
}
|
||||
|
||||
public class EnumUtilsTest {
|
||||
|
||||
@Test
|
||||
public void isInEnumsTest() {
|
||||
Assert.assertTrue(EnumUtils.isInEnums("ONE", new Num[]{Num.ONE, Num.TWO, Num.THREE}));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user