svn commit: r1219 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/net logback-core/src/main/java/ch/qos/logback/core/net logback-site/src/site/xdocTemplates/manual

Author: seb Date: Mon Jan 15 18:42:29 2007 New Revision: 1219 Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Log: On going work on JMS*Appender doc Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java ============================================================================== --- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java (original) +++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java Mon Jan 15 18:42:29 2007 @@ -18,78 +18,18 @@ import javax.jms.QueueSession; import javax.jms.Session; import javax.naming.Context; -import javax.naming.InitialContext; import ch.qos.logback.classic.spi.LoggingEvent; +import ch.qos.logback.core.AppenderBase; import ch.qos.logback.core.net.JMSAppenderBase; /** * A simple appender that publishes events to a JMS Queue. The events are * serialized and transmitted as JMS message type {@link * javax.jms.ObjectMessage}. - * - * <p> - * JMS {@link javax.jms.Queue queues} and - * {@link javax.jms.QueueConnectionFactory queue connection factories} are - * administered objects that are retrieved using JNDI messaging which in turn - * requires the retreival of a JNDI {@link Context}. - * * <p> - * There are two common methods for retrieving a JNDI {@link Context}. If a - * file resource named <em>jndi.properties</em> 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: - * - * <pre> - * InitialContext jndiContext = new InitialContext(); - * </pre> - * - * <p> - * Calling the no-argument <code>InitialContext()</code> 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). - * - * <p> - * In the second approach, several predetermined properties are set and these - * properties are passed to the <code>InitialContext</code> contructor to - * connect to the naming service provider. For example, to connect to JBoss - * naming service one would write: - * - * <pre> - * 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); - * </pre> - * - * where <em>hostname</em> is the host where the JBoss applicaiton server is - * running. - * - * <p> - * To connect to the the naming service of Weblogic application server one would - * write: - * - * <pre> - * 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); - * </pre> - * - * <p> - * Other JMS providers will obviously require different values. - * - * The initial JNDI context can be obtained by calling the no-argument - * <code>InitialContext()</code> method in EJBs. Only clients running in a - * separate JVM need to be concerned about the <em>jndi.properties</em> file - * and calling {@link InitialContext#InitialContext()} or alternatively - * correctly setting the different properties before calling {@link - * InitialContext#InitialContext(java.util.Hashtable)} method. - * + * For more information about this appender, please refer to: + * http://logback.qos.ch/manual/appenders.html#JMSQueueAppender * * @author Ceki Gülcü */ @@ -113,8 +53,8 @@ * Its value will be used to lookup the appropriate * <code>QueueConnectionFactory</code> from the JNDI context. */ - public void setQueueConnectionFactoryBindingName(String tcfBindingName) { - this.qcfBindingName = tcfBindingName; + public void setQueueConnectionFactoryBindingName(String qcfBindingName) { + this.qcfBindingName = qcfBindingName; } /** @@ -216,7 +156,7 @@ } /** - * This method called by {@link AppenderSkeleton#doAppend} method to do most + * This method called by {@link AppenderBase#doAppend} method to do most * of the real appending work. */ public void append(LoggingEvent event) { Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java ============================================================================== --- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java (original) +++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java Mon Jan 15 18:42:29 2007 @@ -45,24 +45,28 @@ private Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicSink.class); static public void main(String[] args) throws Exception { - if (args.length != 2) { + if (args.length < 2) { usage("Wrong number of arguments."); } String qcfBindingName = args[0]; String queueBindingName = args[1]; -// String username = args[2]; -// String password = args[3]; + String username = null; + String password = null; + if (args.length == 4) { + username = args[2]; + password = args[3]; + } LoggerContext loggerContext = (LoggerContext) LoggerFactory .getILoggerFactory(); ContextInitializer.autoConfig(loggerContext); - new JMSQueueSink(qcfBindingName, queueBindingName, null, null); + new JMSQueueSink(qcfBindingName, queueBindingName, username, password); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); // Loop until the word "exit" is typed - System.out.println("Type \"exit\" to quit JMSSink."); + System.out.println("Type \"exit\" to quit JMSQueueSink."); while (true) { String s = stdin.readLine(); if (s.equalsIgnoreCase("exit")) { @@ -89,7 +93,7 @@ System.out.println("Queue found: " + queue.getQueueName()); QueueConnection queueConnection = queueConnectionFactory - .createQueueConnection(); + .createQueueConnection(username, password); System.out.println("Queue Connection created"); QueueSession queueSession = queueConnection.createQueueSession(false, @@ -113,7 +117,8 @@ if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; event = (LoggingEvent) objectMessage.getObject(); - logger.callAppenders(event); + Logger log = (Logger) LoggerFactory.getLogger(event.getLoggerRemoteView().getName()); + log.callAppenders(event); } else { logger.warn("Received message is of type " + message.getJMSType() + ", was expecting ObjectMessage."); @@ -137,8 +142,8 @@ System.err.println(msg); System.err .println("Usage: java " - + JMSTopicSink.class.getName() - + " QueueConnectionFactoryBindingName QueueBindingName"); + + JMSQueueSink.class.getName() + + " QueueConnectionFactoryBindingName QueueBindingName Username Password"); System.exit(1); } } Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java ============================================================================== --- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java (original) +++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java Mon Jan 15 18:42:29 2007 @@ -18,9 +18,9 @@ import javax.jms.TopicPublisher; import javax.jms.TopicSession; import javax.naming.Context; -import javax.naming.InitialContext; import ch.qos.logback.classic.spi.LoggingEvent; +import ch.qos.logback.core.AppenderBase; import ch.qos.logback.core.net.JMSAppenderBase; /** @@ -28,68 +28,8 @@ * serialized and transmitted as JMS message type {@link * javax.jms.ObjectMessage}. * - * <p> - * JMS {@link javax.jms.Topic topics} and - * {@link javax.jms.TopicConnectionFactory topic connection factories} are - * administered objects that are retrieved using JNDI messaging which in turn - * requires the retreival of a JNDI {@link Context}. - * - * <p> - * There are two common methods for retrieving a JNDI {@link Context}. If a - * file resource named <em>jndi.properties</em> 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: - * - * <pre> - * InitialContext jndiContext = new InitialContext(); - * </pre> - * - * <p> - * Calling the no-argument <code>InitialContext()</code> 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). - * - * <p> - * In the second approach, several predetermined properties are set and these - * properties are passed to the <code>InitialContext</code> contructor to - * connect to the naming service provider. For example, to connect to JBoss - * naming service one would write: - * - * <pre> - * 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); - * </pre> - * - * where <em>hostname</em> is the host where the JBoss applicaiton server is - * running. - * - * <p> - * To connect to the the naming service of Weblogic application server one would - * write: - * - * <pre> - * 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); - * </pre> - * - * <p> - * Other JMS providers will obviously require different values. - * - * The initial JNDI context can be obtained by calling the no-argument - * <code>InitialContext()</code> method in EJBs. Only clients running in a - * separate JVM need to be concerned about the <em>jndi.properties</em> file - * and calling {@link InitialContext#InitialContext()} or alternatively - * correctly setting the different properties before calling {@link - * InitialContext#InitialContext(java.util.Hashtable)} method. - * + * For more information about this appender, please refer to + * http://logback.qos.ch/manual/appenders.html#JMSTopicAppender * * @author Ceki Gülcü */ @@ -217,7 +157,7 @@ /** - * This method called by {@link AppenderSkeleton#doAppend} method to do most + * This method called by {@link AppenderBase#doAppend} method to do most * of the real appending work. */ public void append(LoggingEvent event) { Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java ============================================================================== --- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java (original) +++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java Mon Jan 15 18:42:29 2007 @@ -45,24 +45,28 @@ private Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicSink.class); static public void main(String[] args) throws Exception { - if (args.length != 2) { + if (args.length < 2) { usage("Wrong number of arguments."); } String tcfBindingName = args[0]; String topicBindingName = args[1]; -// String username = args[2]; -// String password = args[3]; + String username = null; + String password = null; + if (args.length == 4) { + username = args[2]; + password = args[3]; + } LoggerContext loggerContext = (LoggerContext) LoggerFactory .getILoggerFactory(); ContextInitializer.autoConfig(loggerContext); - new JMSTopicSink(tcfBindingName, topicBindingName, null, null); + new JMSTopicSink(tcfBindingName, topicBindingName, username, password); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); // Loop until the word "exit" is typed - System.out.println("Type \"exit\" to quit JMSSink."); + System.out.println("Type \"exit\" to quit JMSTopicSink."); while (true) { String s = stdin.readLine(); if (s.equalsIgnoreCase("exit")) { @@ -89,7 +93,7 @@ System.out.println("Topic found: " + topic.getTopicName()); TopicConnection topicConnection = topicConnectionFactory - .createTopicConnection(); + .createTopicConnection(username, password); System.out.println("Topic Connection created"); TopicSession topicSession = topicConnection.createTopicSession(false, @@ -113,7 +117,8 @@ if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; event = (LoggingEvent) objectMessage.getObject(); - logger.callAppenders(event); + Logger log = (Logger) LoggerFactory.getLogger(event.getLoggerRemoteView().getName()); + log.callAppenders(event); } else { logger.warn("Received message is of type " + message.getJMSType() + ", was expecting ObjectMessage."); @@ -138,7 +143,7 @@ System.err .println("Usage: java " + JMSTopicSink.class.getName() - + " TopicConnectionFactoryBindingName TopicBindingName"); + + " TopicConnectionFactoryBindingName TopicBindingName Username Password"); System.exit(1); } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java Mon Jan 15 18:42:29 2007 @@ -13,6 +13,9 @@ /** * This class serves as a base class for * JMSTopicAppender and JMSQueueAppender + * + * For more information about this appender, please refer to: + * http://logback.qos.ch/manual/appenders.html#JMSAppenderBase * * @author Ceki Gülcü * @author Sébastien Pennec Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml ============================================================================== --- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml (original) +++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Mon Jan 15 18:42:29 2007 @@ -1811,10 +1811,39 @@ </p> <p> - It is working in a very similar manner to the <code>JMSTopicAppender</code>. + It works in a very similar manner to the <code>JMSTopicAppender</code>. </p> - queue's own options + <p> + Some options are proper to <code>JMSQueueAppender</code>. They are + listed below. + </p> + + <table> + <tr> + <th>Option Name</th> + <th>Type</th> + <th>Description</th> + </tr> + <tr> + <td><b><span class="option">QueueConnectionFactoryBindingName</span></b></td> + <td><code>String</code></td> + <td> + <p> + The name of the queue factory. There is no default value for this mandatory option. + </p> + </td> + </tr> + <tr> + <td><b><span class="option">QueueBindingName</span></b></td> + <td><code>String</code></td> + <td> + <p> + The name of the queue to use. There is no default value for this mandatory option. + </p> + </td> + </tr> + </table> jms comments
participants (1)
-
noreply.seb@qos.ch