public class JMSAppender extends AppenderSkeleton
ObjectMessage
.
JMS topics
and topic
connection factories
are administered objects that are retrieved
using JNDI messaging which in turn requires the retrieval of a JNDI
Context
.
There are two common methods for retrieving a JNDI Context
. If a file resource named jndi.properties is
available to the JNDI API, it will use the information found
therein to retrieve an initial JNDI context. To obtain an initial
context, your code will simply call:
InitialContext jndiContext = new InitialContext();
Calling the no-argument InitialContext()
method
will also work from within Enterprise Java Beans (EJBs) because it
is part of the EJB contract for application servers to provide each
bean an environment naming context (ENC).
In the second approach, several predetermined properties are set
and these properties are passed to the InitialContext
constructor to connect to the naming service provider. For example,
to connect to JBoss naming service one would write:
Properties env = new Properties( ); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); env.put(Context.PROVIDER_URL, "jnp://hostname:1099"); env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); InitialContext jndiContext = new InitialContext(env);where hostname is the host where the JBoss application server is running.
To connect to the the naming service of Weblogic application server one would write:
Properties env = new Properties( ); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); env.put(Context.PROVIDER_URL, "t3://localhost:7001"); InitialContext jndiContext = new InitialContext(env);
Other JMS providers will obviously require different values.
The initial JNDI context can be obtained by calling the
no-argument InitialContext()
method in EJBs. Only
clients running in a separate JVM need to be concerned about the
jndi.properties file and calling InitialContext.InitialContext()
or alternatively correctly
setting the different properties before calling InitialContext.InitialContext(java.util.Hashtable)
method.
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
构造器和说明 |
---|
JMSAppender() |
限定符和类型 | 方法和说明 |
---|---|
void |
activateOptions()
Options are activated and become effective only after calling
this method.
|
void |
append(LoggingEvent event)
This method called by
AppenderSkeleton.doAppend(com.fr.third.apache.log4j.spi.LoggingEvent) method to
do most of the real appending work. |
protected boolean |
checkEntryConditions() |
void |
close()
Close this JMSAppender.
|
java.lang.String |
getInitialContextFactoryName()
Returns the value of the InitialContextFactoryName option.
|
boolean |
getLocationInfo()
Returns value of the LocationInfo property which
determines whether location (stack) info is sent to the remote
subscriber.
|
java.lang.String |
getPassword() |
java.lang.String |
getProviderURL() |
java.lang.String |
getSecurityCredentials() |
java.lang.String |
getSecurityPrincipalName() |
java.lang.String |
getTopicBindingName()
Returns the value of the TopicBindingName option.
|
protected javax.jms.TopicConnection |
getTopicConnection()
Returns the TopicConnection used for this appender.
|
java.lang.String |
getTopicConnectionFactoryBindingName()
Returns the value of the TopicConnectionFactoryBindingName option.
|
protected javax.jms.TopicPublisher |
getTopicPublisher()
Returns the TopicPublisher used for this appender.
|
protected javax.jms.TopicSession |
getTopicSession()
Returns the TopicSession used for this appender.
|
java.lang.String |
getUserName() |
protected java.lang.Object |
lookup(javax.naming.Context ctx,
java.lang.String name) |
boolean |
requiresLayout()
The JMSAppender sends serialized events and consequently does not
require a layout.
|
void |
setInitialContextFactoryName(java.lang.String initialContextFactoryName)
Setting the InitialContextFactoryName method will cause
this
JMSAppender instance to use the InitialContext.InitialContext(Hashtable) method instead of the
no-argument constructor. |
void |
setLocationInfo(boolean locationInfo)
If true, the information sent to the remote subscriber will
include caller's location information.
|
void |
setPassword(java.lang.String password)
The paswword to use when creating a topic session.
|
void |
setProviderURL(java.lang.String providerURL) |
void |
setSecurityCredentials(java.lang.String securityCredentials) |
void |
setSecurityPrincipalName(java.lang.String securityPrincipalName) |
void |
setTopicBindingName(java.lang.String topicBindingName)
The TopicBindingName option takes a
string value.
|
void |
setTopicConnectionFactoryBindingName(java.lang.String tcfBindingName)
The TopicConnectionFactoryBindingName option takes a
string value.
|
void |
setURLPkgPrefixes(java.lang.String urlPkgPrefixes) |
void |
setUserName(java.lang.String userName)
The user name to use when
creating a topic session . |
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
public void setTopicConnectionFactoryBindingName(java.lang.String tcfBindingName)
TopicConnectionFactory
from the JNDI context.public java.lang.String getTopicConnectionFactoryBindingName()
public void setTopicBindingName(java.lang.String topicBindingName)
Topic
from the JNDI context.public java.lang.String getTopicBindingName()
public boolean getLocationInfo()
public void activateOptions()
activateOptions
在接口中 OptionHandler
activateOptions
在类中 AppenderSkeleton
protected java.lang.Object lookup(javax.naming.Context ctx, java.lang.String name) throws javax.naming.NamingException
javax.naming.NamingException
protected boolean checkEntryConditions()
public void close()
public void append(LoggingEvent event)
AppenderSkeleton.doAppend(com.fr.third.apache.log4j.spi.LoggingEvent)
method to
do most of the real appending work.append
在类中 AppenderSkeleton
public java.lang.String getInitialContextFactoryName()
setInitialContextFactoryName(java.lang.String)
for more details on the
meaning of this option.public void setInitialContextFactoryName(java.lang.String initialContextFactoryName)
JMSAppender
instance to use the 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 setProviderURL(String)
.
public java.lang.String getProviderURL()
public void setProviderURL(java.lang.String providerURL)
public void setURLPkgPrefixes(java.lang.String urlPkgPrefixes)
public java.lang.String getSecurityCredentials()
public void setSecurityCredentials(java.lang.String securityCredentials)
public java.lang.String getSecurityPrincipalName()
public void setSecurityPrincipalName(java.lang.String securityPrincipalName)
public java.lang.String getUserName()
public void setUserName(java.lang.String userName)
creating a topic session
. If you set this option, you should
also set the Password option. See setPassword(String)
.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
public void setLocationInfo(boolean locationInfo)
protected javax.jms.TopicConnection getTopicConnection()
protected javax.jms.TopicSession getTopicSession()
protected javax.jms.TopicPublisher getTopicPublisher()
public boolean requiresLayout()