The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
JMSReceiver.java
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package org.apache.log4j.net;
import java.io.FileInputStream;
import java.util.Properties;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TopicConnection;
import javax.jms.Topic;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSubscriber;
import javax.jms.Session;
import javax.jms.TopicSession;
import javax.jms.ObjectMessage;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.plugins.Plugin;
import org.apache.log4j.plugins.Receiver;
/**
JMSReceiver receives a remote logging event on a configured
JSM topic and "posts" it to a LoggerRepository as if the event was
generated locally. This class is designed to receive events from
the JMSAppender class (or classes that send compatible events).
<p>Once the event has been "posted", it will be handled by the
appenders currently configured in the LoggerRespository.
<p>This implementation borrows heavily from the JMSSink
implementation.
@author Mark Womack
@author Paul Smith
@author Stephen Pain
@since 1.3
*/
public class JMSReceiver extends Receiver implements MessageListener {
private static Logger logger = Logger.getLogger(JMSReceiver.class);
private boolean active = false;
protected String topicFactoryName;
protected String topicName;
protected String userId;
protected String password;
protected TopicConnection topicConnection;
protected String jndiPath;
private String remoteInfo;
private String providerUrl;
public JMSReceiver() { }
public JMSReceiver(String _topicFactoryName, String _topicName,
String _userId, String _password, String _jndiPath) {
topicFactoryName = _topicFactoryName;
topicName = _topicName;
userId = _userId;
password = _password;
jndiPath = _jndiPath;
}
/**
* Sets the path to a properties file containing
* the initial context and jndi provider url
*/
public void setJndiPath(String _jndiPath) {
jndiPath = _jndiPath;
}
/**
* Gets the path to a properties file containing
* the initial context and jndi provider url
*/
public String getJndiPath() {
return jndiPath;
}
/**
Sets the JMS topic factory name to use when creating the
JMS connection. */
public void setTopicFactoryName(String _topicFactoryName) {
topicFactoryName = _topicFactoryName;
}
/**
Gets the curernt JMS topic factory name property. */
public String getTopicFactoryName() {
return topicFactoryName;
}
/**
* Sets the JMS topic name to use when creating the
* JMS connection.
*/
public void setTopicName(String _topicName) {
topicName = _topicName;
}
/**
* Gets the curernt JMS topic name property.
*/
public String getTopicName() {
return topicName;
}
/**
Sets the user id to use when creating the
JMS connection. */
public void setUserId(String _userId) {
userId = _userId;
}
/**
* Gets the current user id property.
*/
public String getUserId() {
return userId;
}
/**
* Sets the password to use when creating the
* JMS connection.
*/
public void setPassword(String _password) {
password = _password;
}
/**
* Gets the curernt password property.
*/
public String getPassword() {
return password;
}
/**
* Returns true if the receiver is the same class and they are
* configured for the same properties, and super class also considers
* them to be equivalent. This is used by PluginRegistry when determining
* if the a similarly configured receiver is being started.
*
* @param testPlugin The plugin to test equivalency against.
* @return boolean True if the testPlugin is equivalent to this plugin.
*/
public boolean isEquivalent(Plugin testPlugin) {
// only do full check if an instance of this class
if (testPlugin instanceof JMSReceiver) {
JMSReceiver receiver = (JMSReceiver)testPlugin;
// check for same topic name and super class equivalency
return (
topicFactoryName.equals(receiver.getTopicFactoryName()) &&
(jndiPath == null || jndiPath.equals(receiver.getJndiPath())) &&
super.isEquivalent(testPlugin)
);
}
return false;
}
/**
Returns true if this receiver is active. */
public synchronized boolean isActive() {
return active;
}
/**
Sets the flag to indicate if receiver is active or not. */
protected synchronized void setActive(boolean _active) {
active = _active;
}
/**
Starts the JMSReceiver with the current options. */
public void activateOptions() {
if (!isActive()) {
try {
remoteInfo = topicFactoryName + ":" + topicName;
Context ctx = null;
if (jndiPath == null || jndiPath.equals("")) {
ctx = new InitialContext();
} else {
Properties p = new Properties();
p.load(new FileInputStream(jndiPath));
ctx = new InitialContext(p);
}
// give some more flexibility about the choice of a tab name
providerUrl = (String)ctx.getEnvironment().get(Context.PROVIDER_URL);
TopicConnectionFactory topicConnectionFactory;
topicConnectionFactory =
(TopicConnectionFactory) lookup(ctx, topicFactoryName);
if (userId != null && password != null) {
topicConnection =
topicConnectionFactory.createTopicConnection(userId, password);
} else {
topicConnection =
topicConnectionFactory.createTopicConnection();
}
TopicSession topicSession =
topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)ctx.lookup(topicName);
TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(this);
topicConnection.start();
setActive(true);
} catch(Exception e) {
setActive(false);
if (topicConnection != null) {
try {
topicConnection.close();
} catch (Exception e2) {
// do nothing
}
topicConnection = null;
}
logger.error("Could not start JMSReceiver.", e);
}
}
}
/**
Called when the receiver should be stopped. */
public synchronized void shutdown() {
if (isActive()) {
// mark this as no longer running
setActive(false);
if (topicConnection != null) {
try {
topicConnection.close();
} catch (Exception e) {
// do nothing
}
topicConnection = null;
}
}
}
public void onMessage(Message message) {
try {
if(message instanceof ObjectMessage) {
// get the logging event and post it to the repository
ObjectMessage objectMessage = (ObjectMessage) message;
LoggingEvent event = (LoggingEvent) objectMessage.getObject();
// store the known remote info in an event property
event.setProperty("log4j.remoteSourceInfo", remoteInfo);
event.setProperty("log4j.jmsProviderUrl", providerUrl);
doPost(event);
} else {
logger.warn("Received message is of type "+message.getJMSType()
+", was expecting ObjectMessage.");
}
} catch(Exception e) {
logger.error("Exception thrown while processing incoming message.", e);
}
}
protected static Object lookup(Context ctx, String name) throws NamingException {
try {
return ctx.lookup(name);
} catch(NameNotFoundException e) {
logger.error("Could not find name ["+name+"].");
throw e;
}
}
}