Class LoggerContextAdmin
- java.lang.Object
-
- javax.management.NotificationBroadcasterSupport
-
- org.apache.logging.log4j.core.jmx.LoggerContextAdmin
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,javax.management.NotificationBroadcaster,javax.management.NotificationEmitter,LoggerContextAdminMBean
public class LoggerContextAdmin extends javax.management.NotificationBroadcasterSupport implements LoggerContextAdminMBean, java.beans.PropertyChangeListener
Implementation of theLoggerContextAdminMBeaninterface.
-
-
Field Summary
Fields Modifier and Type Field Description private static intBUFFER_SIZEprivate static StatusLoggerLOGGERprivate LoggerContextloggerContextprivate javax.management.ObjectNameobjectNameprivate static intPAGEprivate java.util.concurrent.atomic.AtomicLongsequenceNoprivate static intTEXT_BUFFER-
Fields inherited from interface org.apache.logging.log4j.core.jmx.LoggerContextAdminMBean
NOTIF_TYPE_RECONFIGURED, PATTERN
-
-
Constructor Summary
Constructors Constructor Description LoggerContextAdmin(LoggerContext loggerContext, java.util.concurrent.Executor executor)Constructs a newLoggerContextAdminwith theExecutorto be used for sendingNotifications asynchronously to listeners.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static javax.management.MBeanNotificationInfocreateNotificationInfo()private ConfigurationgetConfig()java.lang.StringgetConfigClassName()Returns the class name of theConfigurationof the instrumented LoggerContext.java.lang.StringgetConfigFilter()Returns a string description of all Filters configured in theConfigurationof the instrumented LoggerContext.java.lang.StringgetConfigLocationUri()Returns the configuration location URI as a String.java.lang.StringgetConfigName()Returns the name of the Configuration of the instrumented LoggerContext.java.util.Map<java.lang.String,java.lang.String>getConfigProperties()Returns a map with configured properties.java.lang.StringgetConfigText()Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText.java.lang.StringgetConfigText(java.lang.String charsetName)Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText.java.lang.StringgetName()Returns the name of the instrumentedLoggerContext.javax.management.ObjectNamegetObjectName()Returns theObjectNameof this mbean.java.lang.StringgetStatus()Returns the status of the instrumentedLoggerContext.private longnextSeqNo()private longnow()voidpropertyChange(java.beans.PropertyChangeEvent evt)private java.lang.StringreadContents(java.io.InputStream in, java.nio.charset.Charset charset)Returns the contents of the specified input stream as a String.voidsetConfigLocationUri(java.lang.String configLocation)Sets the configuration location to the specified URI.voidsetConfigText(java.lang.String configText, java.lang.String charsetName)Sets the configuration text.
-
-
-
Field Detail
-
PAGE
private static final int PAGE
- See Also:
- Constant Field Values
-
TEXT_BUFFER
private static final int TEXT_BUFFER
- See Also:
- Constant Field Values
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
LOGGER
private static final StatusLogger LOGGER
-
sequenceNo
private final java.util.concurrent.atomic.AtomicLong sequenceNo
-
objectName
private final javax.management.ObjectName objectName
-
loggerContext
private final LoggerContext loggerContext
-
-
Constructor Detail
-
LoggerContextAdmin
public LoggerContextAdmin(LoggerContext loggerContext, java.util.concurrent.Executor executor)
Constructs a newLoggerContextAdminwith theExecutorto be used for sendingNotifications asynchronously to listeners.- Parameters:
executor- used to send notifications asynchronouslyloggerContext- the instrumented object
-
-
Method Detail
-
createNotificationInfo
private static javax.management.MBeanNotificationInfo createNotificationInfo()
-
getStatus
public java.lang.String getStatus()
Description copied from interface:LoggerContextAdminMBeanReturns the status of the instrumentedLoggerContext.- Specified by:
getStatusin interfaceLoggerContextAdminMBean- Returns:
- the LoggerContext status.
-
getName
public java.lang.String getName()
Description copied from interface:LoggerContextAdminMBeanReturns the name of the instrumentedLoggerContext.- Specified by:
getNamein interfaceLoggerContextAdminMBean- Returns:
- the name of the instrumented
LoggerContext.
-
getConfig
private Configuration getConfig()
-
getConfigLocationUri
public java.lang.String getConfigLocationUri()
Description copied from interface:LoggerContextAdminMBeanReturns the configuration location URI as a String.- Specified by:
getConfigLocationUriin interfaceLoggerContextAdminMBean- Returns:
- the configuration location
-
setConfigLocationUri
public void setConfigLocationUri(java.lang.String configLocation) throws java.net.URISyntaxException, java.io.IOExceptionDescription copied from interface:LoggerContextAdminMBeanSets the configuration location to the specified URI. This will cause the instrumentedLoggerContextto reconfigure.- Specified by:
setConfigLocationUriin interfaceLoggerContextAdminMBean- Parameters:
configLocation- location of the configuration file inURIformat.- Throws:
java.net.URISyntaxException- if the format of the specified configLocationURI is incorrectjava.io.IOException- if an error occurred reading the specified location
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
getConfigText
public java.lang.String getConfigText() throws java.io.IOExceptionDescription copied from interface:LoggerContextAdminMBeanReturns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText. If reading a file, this method assumes the file's character encoding is UTF-8.- Specified by:
getConfigTextin interfaceLoggerContextAdminMBean- Returns:
- the configuration text
- Throws:
java.io.IOException- if a problem occurred reading the contents of the config file.
-
getConfigText
public java.lang.String getConfigText(java.lang.String charsetName) throws java.io.IOExceptionDescription copied from interface:LoggerContextAdminMBeanReturns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText.- Specified by:
getConfigTextin interfaceLoggerContextAdminMBean- Parameters:
charsetName- the encoding to use to convert the file's bytes into the resulting string.- Returns:
- the configuration text
- Throws:
java.io.IOException- if a problem occurred reading the contents of the config file.
-
readContents
private java.lang.String readContents(java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOExceptionReturns the contents of the specified input stream as a String.- Parameters:
in- stream to read fromcharset- MUST not be null- Returns:
- stream contents
- Throws:
java.io.IOException- if a problem occurred reading from the stream.
-
setConfigText
public void setConfigText(java.lang.String configText, java.lang.String charsetName)Description copied from interface:LoggerContextAdminMBeanSets the configuration text. This does not replace the contents of the configuration file, but does cause the instrumentedLoggerContextto be reconfigured with the specified text.- Specified by:
setConfigTextin interfaceLoggerContextAdminMBean- Parameters:
configText- the configuration text in XML or JSON formatcharsetName- name of theCharsetused to convert the specified configText to bytes
-
getConfigName
public java.lang.String getConfigName()
Description copied from interface:LoggerContextAdminMBeanReturns the name of the Configuration of the instrumented LoggerContext.- Specified by:
getConfigNamein interfaceLoggerContextAdminMBean- Returns:
- the Configuration name
-
getConfigClassName
public java.lang.String getConfigClassName()
Description copied from interface:LoggerContextAdminMBeanReturns the class name of theConfigurationof the instrumented LoggerContext.- Specified by:
getConfigClassNamein interfaceLoggerContextAdminMBean- Returns:
- the class name of the
Configuration.
-
getConfigFilter
public java.lang.String getConfigFilter()
Description copied from interface:LoggerContextAdminMBeanReturns a string description of all Filters configured in theConfigurationof the instrumented LoggerContext.- Specified by:
getConfigFilterin interfaceLoggerContextAdminMBean- Returns:
- a string description of all Filters configured
-
getConfigProperties
public java.util.Map<java.lang.String,java.lang.String> getConfigProperties()
Description copied from interface:LoggerContextAdminMBeanReturns a map with configured properties.- Specified by:
getConfigPropertiesin interfaceLoggerContextAdminMBean- Returns:
- a map with configured properties.
-
getObjectName
public javax.management.ObjectName getObjectName()
Returns theObjectNameof this mbean.- Specified by:
getObjectNamein interfaceLoggerContextAdminMBean- Returns:
- the
ObjectName - See Also:
LoggerContextAdminMBean.PATTERN
-
nextSeqNo
private long nextSeqNo()
-
now
private long now()
-
-