mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-14 20:17:51 +00:00
perf[event]: post exception whatever if the exceptionFunction is override or not
This commit is contained in:
1 parent
837b6d8e9d
commit
f7e6e51edd
2 files changed
+31
-10
No files matched your search
@@ -15,6 +15,7 @@ package com.zfoo.event.manager;
|
|||||||
import com.zfoo.event.enhance.IEventReceiver;
|
import com.zfoo.event.enhance.IEventReceiver;
|
||||||
import com.zfoo.event.model.ExceptionEvent;
|
import com.zfoo.event.model.ExceptionEvent;
|
||||||
import com.zfoo.event.model.IEvent;
|
import com.zfoo.event.model.IEvent;
|
||||||
|
import com.zfoo.event.model.TripleConsumer;
|
||||||
import com.zfoo.protocol.collection.CollectionUtils;
|
import com.zfoo.protocol.collection.CollectionUtils;
|
||||||
import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject;
|
import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject;
|
||||||
import com.zfoo.protocol.util.AssertionUtils;
|
import com.zfoo.protocol.util.AssertionUtils;
|
||||||
@@ -60,10 +61,7 @@ public abstract class EventBus {
|
|||||||
/**
|
/**
|
||||||
* event exception handler
|
* event exception handler
|
||||||
*/
|
*/
|
||||||
public static TriConsumer<IEventReceiver, IEvent, Throwable> exceptionFunction = (receiver, event, throwable) -> {
|
public static TripleConsumer<IEventReceiver, IEvent, Throwable> exceptionFunction = null;
|
||||||
logger.error("bean:[{}] event:[{}] unhandled exception", receiver.getBean().getClass().getSimpleName(), event.getClass().getSimpleName(), throwable);
|
|
||||||
post(new ExceptionEvent(receiver, event, throwable));
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* event noReceiver handler
|
* event noReceiver handler
|
||||||
*/
|
*/
|
||||||
@@ -129,15 +127,15 @@ public abstract class EventBus {
|
|||||||
try {
|
try {
|
||||||
receiver.invoke(event);
|
receiver.invoke(event);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
exceptionFunction.accept(receiver, event, t);
|
if (exceptionFunction == null) {
|
||||||
|
logger.error("bean:[{}] event:[{}] unhandled exception", receiver.getBean().getClass().getSimpleName(), event.getClass().getSimpleName(), t);
|
||||||
|
} else {
|
||||||
|
exceptionFunction.accept(receiver, event, t);
|
||||||
|
}
|
||||||
|
post(new ExceptionEvent(receiver, event, t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface TriConsumer<T, U, V> {
|
|
||||||
void accept(T t, U u, V v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void asyncExecute(Runnable runnable) {
|
public static void asyncExecute(Runnable runnable) {
|
||||||
asyncExecute(RandomUtils.randomInt(), runnable);
|
asyncExecute(RandomUtils.randomInt(), runnable);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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.event.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author godotg
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TripleConsumer<L, M, R> {
|
||||||
|
|
||||||
|
void accept(L left, M middle, R right);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user