Methods Summary |
---|
public void | activateOptions()Options are activated and become effective only after calling
this method.
TopicConnectionFactory topicConnectionFactory;
try {
Context jndi;
LogLog.debug("Getting initial context.");
if(initialContextFactoryName != null) {
Properties env = new Properties( );
env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
if(providerURL != null) {
env.put(Context.PROVIDER_URL, providerURL);
} else {
LogLog.warn("You have set InitialContextFactoryName option but not the "
+"ProviderURL. This is likely to cause problems.");
}
if(urlPkgPrefixes != null) {
env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
}
if(securityPrincipalName != null) {
env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
if(securityCredentials != null) {
env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
} else {
LogLog.warn("You have set SecurityPrincipalName option but not the "
+"SecurityCredentials. This is likely to cause problems.");
}
}
jndi = new InitialContext(env);
} else {
jndi = new InitialContext();
}
LogLog.debug("Looking up ["+tcfBindingName+"]");
topicConnectionFactory = (TopicConnectionFactory) lookup(jndi, tcfBindingName);
LogLog.debug("About to create TopicConnection.");
if(userName != null) {
topicConnection = topicConnectionFactory.createTopicConnection(userName,
password);
} else {
topicConnection = topicConnectionFactory.createTopicConnection();
}
LogLog.debug("Creating TopicSession, non-transactional, "
+"in AUTO_ACKNOWLEDGE mode.");
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
LogLog.debug("Looking up topic name ["+topicBindingName+"].");
Topic topic = (Topic) lookup(jndi, topicBindingName);
LogLog.debug("Creating TopicPublisher.");
topicPublisher = topicSession.createPublisher(topic);
LogLog.debug("Starting TopicConnection.");
topicConnection.start();
jndi.close();
} catch(Exception e) {
errorHandler.error("Error while activating options for appender named ["+name+
"].", e, ErrorCode.GENERIC_FAILURE);
}
|
public void | append(org.apache.log4j.spi.LoggingEvent event)This method called by {@link AppenderSkeleton#doAppend} method to
do most of the real appending work.
if(!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = topicSession.createObjectMessage();
if(locationInfo) {
event.getLocationInformation();
}
msg.setObject(event);
topicPublisher.publish(msg);
} catch(Exception e) {
errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
|
protected boolean | checkEntryConditions()
String fail = null;
if(this.topicConnection == null) {
fail = "No TopicConnection";
} else if(this.topicSession == null) {
fail = "No TopicSession";
} else if(this.topicPublisher == null) {
fail = "No TopicPublisher";
}
if(fail != null) {
errorHandler.error(fail +" for JMSAppender named ["+name+"].");
return false;
} else {
return true;
}
|
public synchronized void | close()Close this JMSAppender. Closing releases all resources used by the
appender. A closed appender cannot be re-opened.
// The synchronized modifier avoids concurrent append and close operations
if(this.closed)
return;
LogLog.debug("Closing appender ["+name+"].");
this.closed = true;
try {
if(topicSession != null)
topicSession.close();
if(topicConnection != null)
topicConnection.close();
} catch(Exception e) {
LogLog.error("Error while closing JMSAppender ["+name+"].", e);
}
// Help garbage collection
topicPublisher = null;
topicSession = null;
topicConnection = null;
|
public java.lang.String | getInitialContextFactoryName()Returns the value of the InitialContextFactoryName option.
See {@link #setInitialContextFactoryName} for more details on the
meaning of this option.
return initialContextFactoryName;
|
public boolean | getLocationInfo()Returns value of the LocationInfo property which
determines whether location (stack) info is sent to the remote
subscriber.
return locationInfo;
|
public java.lang.String | getPassword()
return password;
|
public java.lang.String | getProviderURL()
return providerURL;
|
public java.lang.String | getSecurityCredentials()
return securityCredentials;
|
public java.lang.String | getSecurityPrincipalName()
return securityPrincipalName;
|
public java.lang.String | getTopicBindingName()Returns the value of the TopicBindingName option.
return topicBindingName;
|
protected javax.jms.TopicConnection | getTopicConnection()Returns the TopicConnection used for this appender. Only valid after
activateOptions() method has been invoked.
return topicConnection;
|
public java.lang.String | getTopicConnectionFactoryBindingName()Returns the value of the TopicConnectionFactoryBindingName option.
return tcfBindingName;
|
protected javax.jms.TopicPublisher | getTopicPublisher()Returns the TopicPublisher used for this appender. Only valid after
activateOptions() method has been invoked.
return topicPublisher;
|
protected javax.jms.TopicSession | getTopicSession()Returns the TopicSession used for this appender. Only valid after
activateOptions() method has been invoked.
return topicSession;
|
java.lang.String | getURLPkgPrefixes()
return urlPkgPrefixes;
|
public java.lang.String | getUserName()
return userName;
|
protected java.lang.Object | lookup(javax.naming.Context ctx, java.lang.String name)
try {
return ctx.lookup(name);
} catch(NameNotFoundException e) {
LogLog.error("Could not find name ["+name+"].");
throw e;
}
|
public boolean | requiresLayout()The JMSAppender sends serialized events and consequently does not
require a layout.
return false;
|
public void | setInitialContextFactoryName(java.lang.String initialContextFactoryName)Setting the InitialContextFactoryName method will cause
this JMSAppender instance to use the {@link
InitialContext#InitialContext(Hashtable)} method instead of the
no-argument constructor. If you set this option, you should also
at least set the ProviderURL option.
See also {@link #setProviderURL(String)}.
this.initialContextFactoryName = initialContextFactoryName;
|
public void | setLocationInfo(boolean locationInfo)If true, the information sent to the remote subscriber will
include caller's location information. By default no location
information is sent to the subscriber.
this.locationInfo = locationInfo;
|
public void | setPassword(java.lang.String password)The paswword to use when creating a topic session.
this.password = password;
|
public void | setProviderURL(java.lang.String providerURL)
this.providerURL = providerURL;
|
public void | setSecurityCredentials(java.lang.String securityCredentials)
this.securityCredentials = securityCredentials;
|
public void | setSecurityPrincipalName(java.lang.String securityPrincipalName)
this.securityPrincipalName = securityPrincipalName;
|
public void | setTopicBindingName(java.lang.String topicBindingName)The TopicBindingName option takes a
string value. Its value will be used to lookup the appropriate
Topic from the JNDI context.
this.topicBindingName = topicBindingName;
|
public void | setTopicConnectionFactoryBindingName(java.lang.String tcfBindingName)The TopicConnectionFactoryBindingName option takes a
string value. Its value will be used to lookup the appropriate
TopicConnectionFactory from the JNDI context.
this.tcfBindingName = tcfBindingName;
|
public void | setURLPkgPrefixes(java.lang.String urlPkgPrefixes)
this.urlPkgPrefixes = urlPkgPrefixes;
|
public void | setUserName(java.lang.String userName)The user name to use when {@link
TopicConnectionFactory#createTopicConnection(String, String)
creating a topic session}. If you set this option, you should
also set the Password option. See {@link
#setPassword(String)}.
this.userName = userName;
|