bb.util
Class MemoryMonitorListenerImpl

java.lang.Object
  extended by bb.util.MemoryMonitorListenerImpl
All Implemented Interfaces:
MemoryMonitorListener, Closeable
Direct Known Subclasses:
MemoryMonitor.UnitTest.ListenerTest

public class MemoryMonitorListenerImpl
extends Object
implements MemoryMonitorListener

Simple implementation of MemoryMonitorListener which logs most events to its own internal Logger. The one exception is onMemoryState, which writes the data to a separate file instead.

This class is multithread safe: every public method is synchronized.


Field Summary
private  int countState
           
private  long instanceId
           
private static AtomicLong instanceIdNext
           
private  Logger2 logger2
           
private  PrintWriter pw
           
private static String separator
           
 
Constructor Summary
MemoryMonitorListenerImpl()
           
 
Method Summary
 void close()
          Called when the associated MemoryMonitor is being closed.
private  File makeFile()
           
 void onMemoryLow(MemoryState state)
          Called whenever the associated MemoryMonitor instance first detects the low memory state when previously it had detected a not low memory state.
 void onMemoryNotLow(MemoryState state)
          Called whenever the associated MemoryMonitor instance first detects a not low memory state when previously it had detected the low memory state.
 void onMemoryState(MemoryState state)
          Called whenever the associated MemoryMonitor instance has measured a new memory state.
 void onMonitoringError(Throwable t)
          Called when the associated MemoryMonitor instance has detected some error while monitoring.
 void onMonitoringStarted()
          Called when the associated MemoryMonitor instance has just started monitoring.
 void onMonitoringStopped()
          Called when the associated MemoryMonitor instance has just stopped monitoring.
static String toStringHeader(String separator)
          Returns a description of the data written by onMemoryState.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

separator

private static final String separator
See Also:
Constant Field Values

instanceIdNext

private static final AtomicLong instanceIdNext

instanceId

private final long instanceId

countState

private int countState

pw

private final PrintWriter pw

logger2

private final Logger2 logger2
Constructor Detail

MemoryMonitorListenerImpl

public MemoryMonitorListenerImpl()
                          throws RuntimeException
Throws:
RuntimeException
Method Detail

toStringHeader

public static String toStringHeader(String separator)
                             throws IllegalArgumentException
Returns a description of the data written by onMemoryState.

Throws:
IllegalArgumentException - if separator == null or separator.length() == 0

makeFile

private File makeFile()

onMonitoringStarted

public void onMonitoringStarted()
Description copied from interface: MemoryMonitorListener
Called when the associated MemoryMonitor instance has just started monitoring. This method will be called repeatedly if MemoryMonitor goes thru multiple start and stop cycles.

Specified by:
onMonitoringStarted in interface MemoryMonitorListener

onMonitoringStopped

public void onMonitoringStopped()
Description copied from interface: MemoryMonitorListener
Called when the associated MemoryMonitor instance has just stopped monitoring. This method will be called repeatedly if MemoryMonitor goes thru multiple start and stop cycles.

Specified by:
onMonitoringStopped in interface MemoryMonitorListener

onMonitoringError

public void onMonitoringError(Throwable t)
Description copied from interface: MemoryMonitorListener
Called when the associated MemoryMonitor instance has detected some error while monitoring.

Specified by:
onMonitoringError in interface MemoryMonitorListener
Parameters:
t - the Throwable which caused the error

onMemoryState

public void onMemoryState(MemoryState state)
Description copied from interface: MemoryMonitorListener
Called whenever the associated MemoryMonitor instance has measured a new memory state. This method will be called repeatedly.

Specified by:
onMemoryState in interface MemoryMonitorListener
Parameters:
state - the MemoryState which was just measured

onMemoryLow

public void onMemoryLow(MemoryState state)
                 throws RuntimeException
Description copied from interface: MemoryMonitorListener
Called whenever the associated MemoryMonitor instance first detects the low memory state when previously it had detected a not low memory state. This method will be called repeatedly if the memory cycles in and out of low memory.

Specified by:
onMemoryLow in interface MemoryMonitorListener
Parameters:
state - the MemoryState for which low memory was just detected
Throws:
RuntimeException

onMemoryNotLow

public void onMemoryNotLow(MemoryState state)
Description copied from interface: MemoryMonitorListener
Called whenever the associated MemoryMonitor instance first detects a not low memory state when previously it had detected the low memory state. This method will be called repeatedly if the memory cycles in and out of low memory.

Specified by:
onMemoryNotLow in interface MemoryMonitorListener
Parameters:
state - the MemoryState for which not low memory was just detected

close

public void close()
Description copied from interface: MemoryMonitorListener
Called when the associated MemoryMonitor is being closed.

Specified by:
close in interface MemoryMonitorListener
Specified by:
close in interface Closeable