diff --git a/event/src/main/java/com/zfoo/event/manager/EventBus.java b/event/src/main/java/com/zfoo/event/manager/EventBus.java index 833e5d23..c95fe3c4 100644 --- a/event/src/main/java/com/zfoo/event/manager/EventBus.java +++ b/event/src/main/java/com/zfoo/event/manager/EventBus.java @@ -15,6 +15,7 @@ package com.zfoo.event.manager; import com.zfoo.event.enhance.IEventReceiver; import com.zfoo.event.model.ExceptionEvent; import com.zfoo.event.model.IEvent; +import com.zfoo.event.model.TripleConsumer; import com.zfoo.protocol.collection.CollectionUtils; import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject; import com.zfoo.protocol.util.AssertionUtils; @@ -60,10 +61,7 @@ public abstract class EventBus { /** * event exception handler */ - public static TriConsumer exceptionFunction = (receiver, event, throwable) -> { - logger.error("bean:[{}] event:[{}] unhandled exception", receiver.getBean().getClass().getSimpleName(), event.getClass().getSimpleName(), throwable); - post(new ExceptionEvent(receiver, event, throwable)); - }; + public static TripleConsumer exceptionFunction = null; /** * event noReceiver handler */ @@ -129,15 +127,15 @@ public abstract class EventBus { try { receiver.invoke(event); } 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 { - void accept(T t, U u, V v); - } - public static void asyncExecute(Runnable runnable) { asyncExecute(RandomUtils.randomInt(), runnable); } diff --git a/event/src/main/java/com/zfoo/event/model/TripleConsumer.java b/event/src/main/java/com/zfoo/event/model/TripleConsumer.java new file mode 100644 index 00000000..c5185303 --- /dev/null +++ b/event/src/main/java/com/zfoo/event/model/TripleConsumer.java @@ -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 { + + void accept(L left, M middle, R right); + +}