Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.classic.net;
 
 
 import  javax.jms.ObjectMessage;
 import  javax.jms.Session;
 import  javax.jms.Topic;
 import  javax.jms.TopicConnection;
 import  javax.jms.TopicConnectionFactory;
 import  javax.jms.TopicPublisher;
 import  javax.jms.TopicSession;
 
A simple appender that publishes events to a JMS Topic. The events are serialized and transmitted as JMS message type javax.jms.ObjectMessage. For more information about this appender, please refer to http://logback.qos.ch/manual/appenders.html#JMSTopicAppender

Author(s):
Ceki Gülcü
 
 public class JMSTopicAppender extends JMSAppenderBase<ILoggingEvent> {
 
   static int SUCCESSIVE_FAILURE_LIMIT = 3;
 
   TopicConnection topicConnection;
   TopicSession topicSession;
   TopicPublisher topicPublisher;
 
   int successiveFailureCount = 0;
   
The TopicConnectionFactoryBindingName option takes a string value. Its value will be used to lookup the appropriate TopicConnectionFactory from the JNDI context.
 
   public void setTopicConnectionFactoryBindingName(String tcfBindingName) {
     this. = tcfBindingName;
   }

  
Returns the value of the TopicConnectionFactoryBindingName option.
 
     return ;
   }

  
The TopicBindingName option takes a string value. Its value will be used to lookup the appropriate Topic from the JNDI context.
 
   public void setTopicBindingName(String topicBindingName) {
     this. = topicBindingName;
   }

  
Returns the value of the TopicBindingName option.
 
   public String getTopicBindingName() {
     return ;
   }

  
Options are activated and become effective only after calling this method.
 
   public void start() {
     TopicConnectionFactory topicConnectionFactory;
 
     try {
       Context jndi = buildJNDIContext();
 
       // addInfo("Looking up [" + tcfBindingName + "]");
       topicConnectionFactory = (TopicConnectionFactory) lookup(jndi,
           );
       // addInfo("About to create TopicConnection.");
      if ( != null) {
        this. = topicConnectionFactory.createTopicConnection(
            );
      } else {
        this. = topicConnectionFactory.createTopicConnection();
      }
      // addInfo(
      // "Creating TopicSession, non-transactional, "
      // + "in AUTO_ACKNOWLEDGE mode.");
      this. = .createTopicSession(false,
          Session.AUTO_ACKNOWLEDGE);
      // addInfo("Looking up topic name [" + topicBindingName + "].");
      Topic topic = (Topic) lookup(jndi);
      // addInfo("Creating TopicPublisher.");
      this. = .createPublisher(topic);
      // addInfo("Starting TopicConnection.");
      .start();
      jndi.close();
    } catch (Exception e) {
      addError("Error while activating options for appender named [" + 
          + "]."e);
    }
    if (this. != null && this. != null
        && this. != null) {
      super.start();
    }
  }

  
Close this JMSAppender. Closing releases all resources used by the appender. A closed appender cannot be re-opened.
  public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.) {
      return;
    }
    this. = false;
    try {
      if ( != null) {
        .close();
      }
      if ( != null) {
        .close();
      }
    } catch (Exception e) {
      addError("Error while closing JMSAppender [" +  + "]."e);
    }
    // Help garbage collection
     = null;
     = null;
     = null;
  }


  
This method called by AppenderBase.doAppend method to do most of the real appending work.
  public void append(ILoggingEvent event) {
    if (!isStarted()) {
      return;
    }
    try {
      ObjectMessage msg = .createObjectMessage();
      Serializable so = .transform(event);
      msg.setObject(so);
      .publish(msg);
       = 0;
    } catch (Exception e) {
        stop();
      }
      addError("Could not publish message in JMSTopicAppender [" +  + "]."e);
    }
  }

  
Returns the TopicConnection used for this appender. Only valid after start() method has been invoked.
  protected TopicConnection getTopicConnection() {
    return ;
  }

  
Returns the TopicSession used for this appender. Only valid after start() method has been invoked.
  protected TopicSession getTopicSession() {
    return ;
  }

  
Returns the TopicPublisher used for this appender. Only valid after start() method has been invoked.
  protected TopicPublisher getTopicPublisher() {
    return ;
  }
New to GrepCode? Check out our FAQ X