Class JmsManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.mom.jakarta.JmsManager
- All Implemented Interfaces:
AutoCloseable
Consider this class private; it is only public for access by integration tests.
JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects involving a configured ConnectionFactory and Destination.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classprivate static final classprivate final classHandles reconnecting to JMS on a Thread.Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JmsManager.JmsManagerConfigurationprivate jakarta.jms.Connectionprivate jakarta.jms.Destination(package private) static final JmsManager.JmsManagerFactoryprivate JndiManagerprivate jakarta.jms.MessageProducerprivate JmsManager.Reconnectorprivate jakarta.jms.SessionFields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateJmsManager(String name, JmsManager.JmsManagerConfiguration configuration) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanprivate booleanprivate booleanprivate booleanprivate jakarta.jms.ConnectioncreateConnection(JndiManager jndiManager) private jakarta.jms.DestinationcreateDestination(JndiManager jndiManager) private jakarta.jms.MessagecreateMessage(Serializable object) Creates a TextMessage, MapMessage, or ObjectMessage from a Serializable object.private voidcreateMessageAndSend(LogEvent event, Serializable serializable) private jakarta.jms.MessageProducercreateMessageProducer(jakarta.jms.Session session, jakarta.jms.Destination destination) Creates a MessageProducer on this Destination using the current Session.private JmsManager.Reconnectorprivate jakarta.jms.SessioncreateSession(jakarta.jms.Connection connection) static JmsManagergetJmsManager(String name, Properties jndiProperties, String connectionFactoryName, String destinationName, String userName, char[] password, boolean immediateFail, long reconnectIntervalMillis) Gets a JmsManager using the specified configuration parameters.(package private) JndiManager(package private) <T> Tprivate jakarta.jms.MapMessagemap(MapMessage<?, ?> log4jMapMessage, jakarta.jms.MapMessage jmsMapMessage) protected booleanreleaseSub(long timeout, TimeUnit timeUnit) May be overridden by managers to perform processing while the manager is being released and the lock is held.(package private) voidsend(LogEvent event, Serializable serializable) Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
Field Details
-
FACTORY
-
configuration
-
reconnector
-
jndiManager
-
connection
private volatile jakarta.jms.Connection connection -
session
private volatile jakarta.jms.Session session -
destination
private volatile jakarta.jms.Destination destination -
messageProducer
private volatile jakarta.jms.MessageProducer messageProducer
-
-
Constructor Details
-
JmsManager
-
-
Method Details
-
getJmsManager
public static JmsManager getJmsManager(String name, Properties jndiProperties, String connectionFactoryName, String destinationName, String userName, char[] password, boolean immediateFail, long reconnectIntervalMillis) Gets a JmsManager using the specified configuration parameters.- Parameters:
name- The name to use for this JmsManager.jndiProperties- JNDI properties.connectionFactoryName- The binding name for theConnectionFactory.destinationName- The binding name for theDestination.userName- The userName to connect with ornullfor no authentication.password- The password to use with the given userName ornullfor no authentication.immediateFail- Whether or not to fail immediately with aAppenderLoggingExceptionwhen connecting to JMS fails.reconnectIntervalMillis- How to log sleep in milliseconds before trying to reconnect to JMS.- Returns:
- The JmsManager as configured.
-
closeConnection
private boolean closeConnection() -
closeJndiManager
private boolean closeJndiManager() -
closeMessageProducer
private boolean closeMessageProducer() -
closeSession
private boolean closeSession() -
createConnection
private jakarta.jms.Connection createConnection(JndiManager jndiManager) throws NamingException, jakarta.jms.JMSException - Throws:
NamingExceptionjakarta.jms.JMSException
-
createDestination
- Throws:
NamingException
-
createMessage
Creates a TextMessage, MapMessage, or ObjectMessage from a Serializable object.For instance, when using a text-based
Layoutsuch asPatternLayout, theLogEventmessage will be serialized to a String.When using a layout such as
SerializedLayout, the LogEvent message will be serialized as a Java object.When using a layout such as
MessageLayoutand the LogEvent message is a Log4j MapMessage, the message will be serialized as a JMS MapMessage.- Parameters:
object- The LogEvent or String message to wrap.- Returns:
- A new JMS message containing the provided object.
- Throws:
jakarta.jms.JMSException- if the JMS provider fails to create this message due to some internal error.
-
createMessageAndSend
private void createMessageAndSend(LogEvent event, Serializable serializable) throws jakarta.jms.JMSException - Throws:
jakarta.jms.JMSException
-
createMessageProducer
private jakarta.jms.MessageProducer createMessageProducer(jakarta.jms.Session session, jakarta.jms.Destination destination) throws jakarta.jms.JMSException Creates a MessageProducer on this Destination using the current Session.- Parameters:
session- The JMS Session to use to create the MessageProducerdestination- The JMS Destination for the MessageProducer- Returns:
- A MessageProducer on this Destination.
- Throws:
jakarta.jms.JMSException- if the session fails to create a MessageProducer due to some internal error.
-
createReconnector
-
createSession
private jakarta.jms.Session createSession(jakarta.jms.Connection connection) throws jakarta.jms.JMSException - Throws:
jakarta.jms.JMSException
-
getJmsManagerConfiguration
-
getJndiManager
JndiManager getJndiManager() -
lookup
- Throws:
NamingException
-
map
private jakarta.jms.MapMessage map(MapMessage<?, ?> log4jMapMessage, jakarta.jms.MapMessage jmsMapMessage) -
releaseSub
Description copied from class:AbstractManagerMay be overridden by managers to perform processing while the manager is being released and the lock is held. A timeout is passed for implementors to use as they see fit.- Overrides:
releaseSubin classAbstractManager- Parameters:
timeout- timeouttimeUnit- timeout time unit- Returns:
- true if all resources were closed normally, false otherwise.
-
send
-