Class JmsManager
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.mom.JmsManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class JmsManager extends AbstractManager
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 Classes Modifier and Type Class Description static classJmsManager.JmsManagerConfigurationprivate static classJmsManager.JmsManagerFactoryprivate classJmsManager.ReconnectorHandles reconnecting to JMS on a Thread.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData
-
-
Field Summary
Fields Modifier and Type Field Description private JmsManager.JmsManagerConfigurationconfigurationprivate javax.jms.Connectionconnectionprivate javax.jms.Destinationdestination(package private) static JmsManager.JmsManagerFactoryFACTORYprivate JndiManagerjndiManagerprivate javax.jms.MessageProducermessageProducerprivate JmsManager.Reconnectorreconnectorprivate javax.jms.Sessionsession-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description privateJmsManager(java.lang.String name, JmsManager.JmsManagerConfiguration configuration)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancloseConnection()private booleancloseJndiManager()private booleancloseMessageProducer()private booleancloseSession()private javax.jms.ConnectioncreateConnection(JndiManager jndiManager)private javax.jms.DestinationcreateDestination(JndiManager jndiManager)javax.jms.MessagecreateMessage(java.io.Serializable object)Creates a TextMessage, MapMessage, or ObjectMessage from a Serializable object.private voidcreateMessageAndSend(LogEvent event, java.io.Serializable serializable)javax.jms.MessageConsumercreateMessageConsumer()Creates a MessageConsumer on this Destination using the current Session.javax.jms.MessageProducercreateMessageProducer(javax.jms.Session session, javax.jms.Destination destination)Creates a MessageProducer on this Destination using the current Session.private JmsManager.ReconnectorcreateReconnector()private javax.jms.SessioncreateSession(javax.jms.Connection connection)static JmsManagergetJmsManager(java.lang.String name, java.util.Properties jndiProperties, java.lang.String connectionFactoryName, java.lang.String destinationName, java.lang.String userName, char[] password, boolean immediateFail, long reconnectIntervalMillis)Gets a JmsManager using the specified configuration parameters.JmsManager.JmsManagerConfigurationgetJmsManagerConfiguration()(package private) JndiManagergetJndiManager()(package private) <T> Tlookup(java.lang.String destinationName)private javax.jms.MapMessagemap(MapMessage<?,?> log4jMapMessage, javax.jms.MapMessage jmsMapMessage)protected booleanreleaseSub(long timeout, java.util.concurrent.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, java.io.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 Detail
-
FACTORY
static final JmsManager.JmsManagerFactory FACTORY
-
configuration
private final JmsManager.JmsManagerConfiguration configuration
-
reconnector
private volatile JmsManager.Reconnector reconnector
-
jndiManager
private volatile JndiManager jndiManager
-
connection
private volatile javax.jms.Connection connection
-
session
private volatile javax.jms.Session session
-
destination
private volatile javax.jms.Destination destination
-
messageProducer
private volatile javax.jms.MessageProducer messageProducer
-
-
Constructor Detail
-
JmsManager
private JmsManager(java.lang.String name, JmsManager.JmsManagerConfiguration configuration)
-
-
Method Detail
-
getJmsManager
public static JmsManager getJmsManager(java.lang.String name, java.util.Properties jndiProperties, java.lang.String connectionFactoryName, java.lang.String destinationName, java.lang.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.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.jndiProperties- JNDI properties.- Returns:
- The JmsManager as configured.
-
closeConnection
private boolean closeConnection()
-
closeJndiManager
private boolean closeJndiManager()
-
closeMessageProducer
private boolean closeMessageProducer()
-
closeSession
private boolean closeSession()
-
createConnection
private javax.jms.Connection createConnection(JndiManager jndiManager) throws javax.naming.NamingException, javax.jms.JMSException
- Throws:
javax.naming.NamingExceptionjavax.jms.JMSException
-
createDestination
private javax.jms.Destination createDestination(JndiManager jndiManager) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
createMessage
public javax.jms.Message createMessage(java.io.Serializable object) throws javax.jms.JMSExceptionCreates 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:
javax.jms.JMSException- if the JMS provider fails to create this message due to some internal error.
-
createMessageAndSend
private void createMessageAndSend(LogEvent event, java.io.Serializable serializable) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
createMessageConsumer
public javax.jms.MessageConsumer createMessageConsumer() throws javax.jms.JMSExceptionCreates a MessageConsumer on this Destination using the current Session.- Returns:
- A MessageConsumer on this Destination.
- Throws:
javax.jms.JMSException- if the session fails to create a consumer due to some internal error.
-
createMessageProducer
public javax.jms.MessageProducer createMessageProducer(javax.jms.Session session, javax.jms.Destination destination) throws javax.jms.JMSExceptionCreates 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:
javax.jms.JMSException- if the session fails to create a MessageProducer due to some internal error.
-
createReconnector
private JmsManager.Reconnector createReconnector()
-
createSession
private javax.jms.Session createSession(javax.jms.Connection connection) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getJmsManagerConfiguration
public JmsManager.JmsManagerConfiguration getJmsManagerConfiguration()
-
getJndiManager
JndiManager getJndiManager()
-
lookup
<T> T lookup(java.lang.String destinationName) throws javax.naming.NamingException- Throws:
javax.naming.NamingException
-
map
private javax.jms.MapMessage map(MapMessage<?,?> log4jMapMessage, javax.jms.MapMessage jmsMapMessage)
-
releaseSub
protected boolean releaseSub(long timeout, java.util.concurrent.TimeUnit timeUnit)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
void send(LogEvent event, java.io.Serializable serializable)
-
-