View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package cz.cuni.amis.pogamut.base.utils.logging.jmx;
7   
8   import java.io.Serializable;
9   import java.util.LinkedList;
10  import java.util.logging.LogRecord;
11  
12  /**
13   * Because LogRecord is not serializing parameters, I have to pass the log record in the 
14   * container with parameters beside anbd reassemble at the destination.
15   * 
16   * Only serializable parameters are stored.
17   *
18   * Passing from JMXLogRecordNotification to LogCategoryJMXProxy
19   * @author Honza
20   */
21  public class JMXLogRecordContainer implements Serializable {
22      private LogRecord record;
23      private LinkedList parameters = new LinkedList();;
24      
25      public JMXLogRecordContainer(LogRecord record) {
26          this.record = record;
27          
28          Object[] allParameters = record.getParameters();
29          if(allParameters != null){
30              for (Object parameter : allParameters) {
31                  if (Serializable.class.isAssignableFrom(parameter.getClass())) {
32                      parameters.add(parameter);
33                  }
34              }
35          }
36      }
37  
38      public void printInfo() {
39          System.out.println("JMXContainer record: " + record + ", " + parameters.size() + " parameters");
40          for (Object o : parameters) {
41              System.out.println( " * " + o);
42          }
43      }
44  
45      public LogRecord getRecordWithParameters() {
46          record.setParameters(parameters.toArray());
47          return record;
48      }
49  }