사건처리
2026년 4월 23일 09:30분
민수기 11장은 백성의 원망이 사건으로 등록되고, 하나님이 응답합니다. 원망 → 메추라기 공급, 모세의 고충 → 장로 70인 지원. 나는 이벤트 타입에 따라 다른 핸들러가 실행되는 이벤트 버스를 구현했습니다.
package com.jesusbornd.numbers;
import java.util.*;
import java.util.function.Consumer;
public class Numbers_11_Chapter_Lv2 {
record Event(String type, String detail) {}
static class EventBus {
private final Map<String, List<Consumer<Event>>> listeners = new HashMap<>();
EventBus on(String type, Consumer<Event> handler) {
listeners.computeIfAbsent(type, k -> new ArrayList<>()).add(handler);
return this;
}
void publish(Event event) {
System.out.println("📢 이벤트: [" + event.type() + "] " + event.detail());
List<Consumer<Event>> handlers = listeners.getOrDefault(event.type(), List.of());
if (handlers.isEmpty()) System.out.println(" → 핸들러 없음");
else handlers.forEach(h -> h.accept(event));
}
}
public static void main(String[] args) {
EventBus bus = new EventBus()
.on("GRUMBLE", e -> System.out.println(" → 메추라기 공급 (응답)"))
.on("GRUMBLE", e -> System.out.println(" → 진노: 일부 사망"))
.on("BURDEN", e -> System.out.println(" → 장로 70인 세워 짐 분담"));
bus.publish(new Event("GRUMBLE", "고기를 원함"));
bus.publish(new Event("BURDEN", "모세가 혼자 감당하기 어려움"));
bus.publish(new Event("RAIN", "비 요청"));
}
}
from dataclasses import dataclass
from collections import defaultdict
from typing import Callable
@dataclass
class Event:
type: str
detail: str
class EventBus:
def __init__(self):
self._listeners: dict[str, list[Callable[[Event], None]]] = defaultdict(list)
def on(self, event_type: str, handler: Callable[[Event], None]) -> "EventBus":
self._listeners[event_type].append(handler)
return self
def publish(self, event: Event):
print(f"📢 이벤트: [{event.type}] {event.detail}")
handlers = self._listeners.get(event.type, [])
if not handlers:
print(" → 핸들러 없음")
for handler in handlers:
handler(event)
if __name__ == "__main__":
bus = (
EventBus()
.on("GRUMBLE", lambda e: print(" → 메추라기 공급 (응답)"))
.on("GRUMBLE", lambda e: print(" → 진노: 일부 사망"))
.on("BURDEN", lambda e: print(" → 장로 70인 세워 짐 분담"))
)
bus.publish(Event("GRUMBLE", "고기를 원함"))
bus.publish(Event("BURDEN", "모세가 혼자 감당하기 어려움"))
bus.publish(Event("RAIN", "비 요청"))
Search
Categories
← 목록으로
Comments
불평이 터질 때 어떻게 처리하느냐가 리더십의 진짜 시험이에요.