package net.aeten.core.alert;

import net.aeten.core.event.Handler;
import net.aeten.core.event.Hook;
import net.aeten.core.event.HookEvent;
import net.aeten.core.event.HookEventGroup;
import net.aeten.core.event.RegisterableTransmitter;
import net.aeten.core.event.TransmitterFactory;

/**
 * 
 * @author Thomas Pérennou
 */
public final class Alert {

	private static final RegisterableTransmitter<HookEvent<AlertLevel, Hook>, AlertData> TRANSMITTER = TransmitterFactory.synchronous();
	
	public static final HookEventGroup<AlertLevel, Hook> EVENTS = HookEventGroup.get(AlertLevel.values(), new Hook[] {Hook.PRE, Hook.START, Hook.END, Hook.POST});

	private Alert() {}

	public static AlertData start(Object source, AlertLevel level, String title, String detail) {
		AlertData data = new AlertData(source, EVENTS.get(level, Hook.PRE), title, detail);
		TRANSMITTER.transmit(data);
		if (data.doIt()) {
			TRANSMITTER.transmit(EVENTS.hook(data, Hook.START));
		}
		return data;
	}
	
	public static AlertData start(Object source, AlertLevel level, String title) {
		AlertData data = new AlertData(source, EVENTS.get(level, Hook.PRE), title);
		TRANSMITTER.transmit(data);
		if (data.doIt()) {
			TRANSMITTER.transmit(EVENTS.hook(data, Hook.START));
		}
		return data;
	}
	
	public static void stop(AlertData data) {
		TRANSMITTER.transmit(EVENTS.hook(data, Hook.END));
		TRANSMITTER.transmit(EVENTS.hook(data, Hook.POST));
	}
	
	public static void addEventHandler(Handler<AlertData> eventHandler, HookEvent<AlertLevel, Hook>... eventList) {
		TRANSMITTER.addEventHandler(eventHandler, eventList);
	}

	public static void removeEventHandler(Handler<AlertData> eventHandler, HookEvent<AlertLevel, Hook>... eventList) {
		TRANSMITTER.removeEventHandler(eventHandler, eventList);
	}
}

@@ -351,144 +351,8 @@
  %7B%0A%0A
-%09private static final RegisterableTransmitter%3CHookEvent%3CAlertLevel, Hook%3E, AlertData%3E TRANSMITTER = TransmitterFactory.synchronous();%0A%09%0A
 %09pub
@@ -425,19 +425,21 @@
 ntGroup.
-get
+build
 (AlertLe
@@ -464,16 +464,17 @@
 Hook%5B%5D %7B
+ 
 Hook.PRE
@@ -510,13 +510,164 @@
 POST
+ 
 %7D);%0A%0A
+%09private static final RegisterableTransmitter%3CHookEvent%3CAlertLevel, Hook%3E, AlertData%3E TRANSMITTER = TransmitterFactory.synchronous(EVENTS.values());%0A%0A
 %09pri
@@ -680,16 +680,18 @@
 lert() %7B
+%0A%09
 %7D%0A%0A%09publ
@@ -987,33 +987,32 @@
 return data;%0A%09%7D%0A
-%09
 %0A%09public static 
@@ -1279,25 +1279,24 @@
 rn data;%0A%09%7D%0A
-%09
 %0A%09public sta
@@ -1437,17 +1437,16 @@
 T));%0A%09%7D%0A
-%09
 %0A%09public

Add Concurrent tools in util package and start remodeling of the SPI design