1 package cz.cuni.amis.pogamut.base.utils.logging.jmx;
2
3 import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
4 import java.io.IOException;
5 import java.util.logging.LogRecord;
6 import javax.management.InstanceNotFoundException;
7 import javax.management.MBeanServerConnection;
8 import javax.management.Notification;
9 import javax.management.NotificationListener;
10 import javax.management.ObjectName;
11
12
13
14
15
16
17 public class LogCategoryJMXProxy extends LogCategory {
18
19 ObjectName categoryObjectName = null;
20 private MBeanServerConnection mbsc;
21
22 public LogCategoryJMXProxy(MBeanServerConnection mbsc, ObjectName parent, String categoryName) throws InstanceNotFoundException, IOException {
23 super(categoryName);
24 categoryObjectName = JMXLogCategories.getJMXLogCategoryName(parent, categoryName);
25 this.mbsc = mbsc;
26 }
27
28 public void enableLogReading() throws InstanceNotFoundException, IOException {
29
30 mbsc.addNotificationListener(categoryObjectName, new NotificationListener() {
31
32 @Override
33 public void handleNotification(Notification notification, Object handback) {
34
35
36 JMXLogRecordContainer container = (JMXLogRecordContainer)notification.getUserData();
37
38
39 log(container.getRecordWithParameters());
40 }
41 }, null, null);
42 }
43
44 }