41 package com.sun.jmx.examples.scandir;
48 import java.io.FileOutputStream;
49 import java.io.IOException;
50 import java.io.OutputStream;
51 import java.util.Collections;
52 import java.util.LinkedList;
53 import java.util.List;
54 import java.util.logging.Logger;
55 import javax.management.MBeanNotificationInfo;
56 import javax.management.MBeanRegistration;
57 import javax.management.MBeanServer;
58 import javax.management.Notification;
59 import javax.management.NotificationBroadcasterSupport;
60 import javax.management.ObjectName;
61 import javax.xml.bind.JAXBException;
93 private static final Logger
LOG =
150 Collections.synchronizedList(
new LinkedList<ResultRecord>() {
153 while (max > 0 && size() >= max) {
199 public ObjectName
preRegister(MBeanServer server, ObjectName name)
247 }
catch (Exception x) {
248 LOG.finest(
"Failed to close log properly: "+x);
272 final OutputStream newStream;
274 if ((force==
false) && (
logCount < maxRecords))
276 final OutputStream oldStream =
logStream;
281 if (oldStream !=
null) {
287 newStream = (newFile==
null)?
null:
new FileOutputStream(newFile,
true);
329 synchronized (
this) {
375 getNextSeqNumber(),
"memory log cleared"));
396 if (before==
false && after==
true)
399 getNextSeqNumber(),
"memory log capacity reached"));
407 final String basename;
408 final long maxRecords;
409 synchronized (
this) {
416 final OutputStream stream =
420 if (stream ==
null)
return;
422 synchronized (
this) {
428 }
catch (JAXBException x) {
429 final IllegalArgumentException iae =
430 new IllegalArgumentException(
"bad record",x);
431 LOG.finest(
"Failed to log record: "+x);
444 "com.sun.jmx.examples.scandir.log.file.switched";
452 "com.sun.jmx.examples.scandir.log.memory.full";
460 "com.sun.jmx.examples.scandir.log.memory.cleared";
471 return new MBeanNotificationInfo[] {
472 new MBeanNotificationInfo(
new String[] {
474 Notification.class.getName(),
475 "Emitted when the log file is switched")
477 new MBeanNotificationInfo(
new String[] {
479 Notification.class.getName(),
480 "Emitted when the memory log capacity is reached")
482 new MBeanNotificationInfo(
new String[] {
484 Notification.class.getName(),
485 "Emitted when the memory log is cleared")
492 synchronized (
this) {
493 if (
logFile ==
null)
return null;
494 if (absolute)
return logFile.getAbsolutePath();
503 if (logConfigBean ==
null)
504 throw new IllegalArgumentException(
"logConfigBean is null");
505 synchronized (
this) {
511 if ((filename !=
null && !filename.equals(logname))
512 || (filename ==
null && logname !=
null)) {
523 ResultLogConfig getConfig() {