]> git.somenet.org - pub/jan/dst18.git/blob - ass2-aop/src/test/java/dst/ass2/aop/event/EventBusHandler.java
GITOLITE.txt
[pub/jan/dst18.git] / ass2-aop / src / test / java / dst / ass2 / aop / event / EventBusHandler.java
1 package dst.ass2.aop.event;
2
3 import java.util.logging.Handler;
4 import java.util.logging.LogRecord;
5
6 import dst.ass2.aop.IPluginExecutable;
7
8 /**
9  * Logging handler that uses the {@link EventBus} for publishing events.
10  */
11 public class EventBusHandler extends Handler {
12     @SuppressWarnings("unchecked")
13     @Override
14     public void publish(LogRecord record) {
15         if (record.getLoggerName().endsWith("PluginExecutable") && record.getMessage().contains("PluginExecutable")) {
16             try {
17                 Class<? extends IPluginExecutable> clazz = (Class<? extends IPluginExecutable>) Class.forName(record.getLoggerName());
18                 EventBus.getInstance().add(EventType.INFO, clazz, record.getSourceClassName());
19             } catch (ClassNotFoundException e) {
20                 throw new RuntimeException(e);
21             }
22         }
23     }
24
25     /**
26      * Simply does nothing.
27      */
28     @Override
29     public void flush() {
30     }
31
32     /**
33      * Simply does nothing.
34      */
35     @Override
36     public void close() {
37     }
38 }