Skip to content

Commit

Permalink
ref[event]: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Apr 10, 2024
1 parent 966fe14 commit 76c20ff
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions event/src/main/java/com/zfoo/event/manager/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void post(IEvent event) {
for (var receiver : receivers) {
switch (receiver.bus()) {
case CurrentThread -> doReceiver(receiver, event);
case AsyncThread -> execute(event.executorHash(), () -> doReceiver(receiver, event));
case AsyncThread -> asyncExecute(event.executorHash(), () -> doReceiver(receiver, event));
// case VirtualThread -> Thread.ofVirtual().name("virtual-on" + clazz.getSimpleName()).start(() -> doReceiver(receiver, event));
}
}
Expand All @@ -132,13 +132,13 @@ private static void doReceiver(IEventReceiver receiver, IEvent event) {
}

public static void asyncExecute(Runnable runnable) {
execute(RandomUtils.randomInt(), runnable);
asyncExecute(RandomUtils.randomInt(), runnable);
}

/**
* Use the event thread specified by the hashcode to execute the task
*/
public static void execute(int executorHash, Runnable runnable) {
public static void asyncExecute(int executorHash, Runnable runnable) {
executors[Math.abs(executorHash % EXECUTORS_SIZE)].execute(ThreadUtils.safeRunnable(runnable));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void arrayTest() throws InterruptedException {

var countDownLatch = new CountDownLatch(executorSize);
for (var i = 0; i < executorSize; i++) {
EventBus.execute(i, new Runnable() {
EventBus.asyncExecute(i, new Runnable() {
@Override
public void run() {
addAndRemoveArray();
Expand Down
2 changes: 1 addition & 1 deletion orm/src/main/java/com/zfoo/orm/cache/EntityCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void accept(Pair<PK, PNode<E>> pair, LazyCache.RemovalCause removalCause)
var entity = pnode.getEntity();
@SuppressWarnings("unchecked")
var entityClass = (Class<E>) entityDef.getClazz();
EventBus.execute(entityClass.hashCode(), new Runnable() {
EventBus.asyncExecute(entityClass.hashCode(), new Runnable() {
@Override
public void run() {
var collection = OrmContext.getOrmManager().getCollection(entityClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void schedulePersist() {
if (!OrmContext.isStop()) {
SchedulerBus.schedule(() -> {
if (!OrmContext.isStop()) {
EventBus.execute(entityDef.getClazz().hashCode(), () -> {
EventBus.asyncExecute(entityDef.getClazz().hashCode(), () -> {
entityCaches.persistAll();
schedulePersist();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public TimeOrmPersister(EntityDef entityDef, EntityCache<?, ?> entityCaches) {
public void start() {
SchedulerBus.scheduleAtFixedRate(() -> {
if (!OrmContext.isStop()) {
EventBus.execute(entityDef.getClazz().hashCode(), () -> entityCaches.persistAll());
EventBus.asyncExecute(entityDef.getClazz().hashCode(), () -> entityCaches.persistAll());
}
}, rate, TimeUnit.MILLISECONDS);
}
Expand Down

0 comments on commit 76c20ff

Please sign in to comment.