"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsManager.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

JmsManager.java  (apache-log4j-2.11.1-src):JmsManager.java  (apache-log4j-2.11.2-src)
skipping to change at line 36 skipping to change at line 36
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.jms.Destination; import javax.jms.Destination;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.MapMessage; import javax.jms.MapMessage;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractManager; import org.apache.logging.log4j.core.appender.AbstractManager;
import org.apache.logging.log4j.core.appender.AppenderLoggingException; import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.core.appender.ManagerFactory; import org.apache.logging.log4j.core.appender.ManagerFactory;
import org.apache.logging.log4j.core.net.JndiManager; import org.apache.logging.log4j.core.net.JndiManager;
import org.apache.logging.log4j.core.util.Log4jThread; import org.apache.logging.log4j.core.util.Log4jThread;
import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.BiConsumer; import org.apache.logging.log4j.util.BiConsumer;
/** /**
skipping to change at line 132 skipping to change at line 131
} }
private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsManagerConfiguration> { private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsManagerConfiguration> {
@Override @Override
public JmsManager createManager(final String name, final JmsManagerConfi guration data) { public JmsManager createManager(final String name, final JmsManagerConfi guration data) {
try { try {
return new JmsManager(name, data); return new JmsManager(name, data);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.error("Error creating JmsManager using JmsManagerConfigur ation [{}]", data, e); logger().error("Error creating JmsManager using JmsManagerConfig uration [{}]", data, e);
return null; return null;
} }
} }
} }
/** /**
* Handles reconnecting to a Socket on a Thread. * Handles reconnecting to JMS on a Thread.
*/ */
private class Reconnector extends Log4jThread { private class Reconnector extends Log4jThread {
private final CountDownLatch latch = new CountDownLatch(1); private final CountDownLatch latch = new CountDownLatch(1);
private volatile boolean shutdown = false; private volatile boolean shutdown = false;
private final Object owner; private final Object owner;
public Reconnector(final Object owner) { private Reconnector(final Object owner) {
super("JmsManager-Reconnector"); super("JmsManager-Reconnector");
this.owner = owner; this.owner = owner;
} }
public void latch() { public void latch() {
try { try {
latch.await(); latch.await();
} catch (final InterruptedException ex) { } catch (final InterruptedException ex) {
// Ignore the exception. // Ignore the exception.
} }
skipping to change at line 178 skipping to change at line 177
connection2.start(); connection2.start();
synchronized (owner) { synchronized (owner) {
jndiManager = jndiManager2; jndiManager = jndiManager2;
connection = connection2; connection = connection2;
session = session2; session = session2;
destination = destination2; destination = destination2;
messageProducer = messageProducer2; messageProducer = messageProducer2;
reconnector = null; reconnector = null;
shutdown = true; shutdown = true;
} }
LOGGER.debug("Connection reestablished to {}", configuration); logger().debug("Connection reestablished to {}", configuration);
} }
@Override @Override
public void run() { public void run() {
while (!shutdown) { while (!shutdown) {
try { try {
sleep(configuration.getReconnectIntervalMillis()); sleep(configuration.getReconnectIntervalMillis());
reconnect(); reconnect();
} catch (final InterruptedException | JMSException | NamingExcep tion e) { } catch (final InterruptedException | JMSException | NamingExcep tion e) {
LOGGER.debug("Cannot reestablish JMS connection to {}: {}", configuration, e.getLocalizedMessage(), logger().debug("Cannot reestablish JMS connection to {}: {}" , configuration, e.getLocalizedMessage(),
e); e);
} finally { } finally {
latch.countDown(); latch.countDown();
} }
} }
} }
public void shutdown() { public void shutdown() {
shutdown = true; shutdown = true;
} }
} }
private static final Logger LOGGER = StatusLogger.getLogger();
static final JmsManagerFactory FACTORY = new JmsManagerFactory(); static final JmsManagerFactory FACTORY = new JmsManagerFactory();
/** /**
* Gets a JmsManager using the specified configuration parameters. * Gets a JmsManager using the specified configuration parameters.
* *
* @param name * @param name
* The name to use for this JmsManager. * The name to use for this JmsManager.
* @param connectionFactoryName * @param connectionFactoryName
* The binding name for the {@link javax.jms.ConnectionFactory}. * The binding name for the {@link javax.jms.ConnectionFactory}.
* @param destinationName * @param destinationName
* The binding name for the {@link javax.jms.Destination}. * The binding name for the {@link javax.jms.Destination}.
* @param userName * @param userName
* The userName to connect with or {@code null} for no authentica tion. * The userName to connect with or {@code null} for no authentica tion.
* @param password * @param password
* The password to use with the given userName or {@code null} fo r no authentication. * The password to use with the given userName or {@code null} fo r no authentication.
* @param immediateFail * @param immediateFail
* Whether or not to fail immediately with a {@link AppenderLoggi ngException} when connecting to JMS * Whether or not to fail immediately with a {@link AppenderLoggi ngException} when connecting to JMS
* fails. * fails.
* @param reconnectIntervalMillis * @param reconnectIntervalMillis
* How to log sleep in milliseconds before trying to reconnect to JMS. * How to log sleep in milliseconds before trying to reconnect to JMS.
* @param jndiManager * @param jndiProperties
* The JndiManager to look up JMS information through. * JNDI properties.
* @return The JmsManager as configured. * @return The JmsManager as configured.
*/ */
public static JmsManager getJmsManager(final String name, final Properties j ndiProperties, public static JmsManager getJmsManager(final String name, final Properties j ndiProperties,
final String connectionFactoryName, final String destinationName, fi nal String userName, final String connectionFactoryName, final String destinationName, fi nal String userName,
final char[] password, final boolean immediateFail, final long recon nectIntervalMillis) { final char[] password, final boolean immediateFail, final long recon nectIntervalMillis) {
final JmsManagerConfiguration configuration = new JmsManagerConfiguratio n(jndiProperties, connectionFactoryName, final JmsManagerConfiguration configuration = new JmsManagerConfiguratio n(jndiProperties, connectionFactoryName,
destinationName, userName, password, immediateFail, reconnectInt ervalMillis); destinationName, userName, password, immediateFail, reconnectInt ervalMillis);
return getManager(name, FACTORY, configuration); return getManager(name, FACTORY, configuration);
} }
skipping to change at line 456 skipping to change at line 453
closed &= closeMessageProducer(); closed &= closeMessageProducer();
closed &= closeSession(); closed &= closeSession();
closed &= closeConnection(); closed &= closeConnection();
return closed && this.jndiManager.stop(timeout, timeUnit); return closed && this.jndiManager.stop(timeout, timeUnit);
} }
void send(final LogEvent event, final Serializable serializable) { void send(final LogEvent event, final Serializable serializable) {
if (messageProducer == null) { if (messageProducer == null) {
if (reconnector != null && !configuration.isImmediateFail()) { if (reconnector != null && !configuration.isImmediateFail()) {
reconnector.latch(); reconnector.latch();
} if (messageProducer == null) {
if (messageProducer == null) { throw new AppenderLoggingException(
throw new AppenderLoggingException( "Error sending to JMS Manager '" + getName() + "': J
"Error sending to JMS Manager '" + getName() + "': JMS m MS message producer not available");
essage producer not available"); }
} }
} }
synchronized (this) { synchronized (this) {
try { try {
createMessageAndSend(event, serializable); createMessageAndSend(event, serializable);
} catch (final JMSException causeEx) { } catch (final JMSException causeEx) {
if (configuration.isRetry() && reconnector == null) { if (configuration.isRetry() && reconnector == null) {
reconnector = createReconnector(); reconnector = createReconnector();
try { try {
closeJndiManager(); closeJndiManager();
reconnector.reconnect(); reconnector.reconnect();
} catch (NamingException | JMSException reconnEx) { } catch (NamingException | JMSException reconnEx) {
LOGGER.debug("Cannot reestablish JMS connection to {}: { }; starting reconnector thread {}", logger().debug("Cannot reestablish JMS connection to {}: {}; starting reconnector thread {}",
configuration, reconnEx.getLocalizedMessage(), r econnector.getName(), reconnEx); configuration, reconnEx.getLocalizedMessage(), r econnector.getName(), reconnEx);
reconnector.start(); reconnector.start();
throw new AppenderLoggingException( throw new AppenderLoggingException(
String.format("Error sending to %s for %s", getN ame(), configuration), causeEx); String.format("JMS exception sending to %s for % s", getName(), configuration), causeEx);
} }
try { try {
createMessageAndSend(event, serializable); createMessageAndSend(event, serializable);
} catch (final JMSException e) { } catch (final JMSException e) {
throw new AppenderLoggingException( throw new AppenderLoggingException(
String.format("Error sending to %s after reestab String.format("Error sending to %s after reestab
lishing connection for %s", getName(), lishing JMS connection for %s",
configuration), getName(), configuration),
causeEx); causeEx);
} }
} }
} }
} }
} }
} }
 End of changes. 12 change blocks. 
20 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)