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.Queue;
 import  javax.jms.QueueConnection;
 import  javax.jms.QueueConnectionFactory;
 import  javax.jms.QueueSender;
 import  javax.jms.QueueSession;
 import  javax.jms.Session;
 
A simple appender that publishes events to a JMS Queue. 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#JMSQueueAppender

Author(s):
Ceki Gülcü
 
 public class JMSQueueAppender extends JMSAppenderBase<ILoggingEvent> {
 
   static int SUCCESSIVE_FAILURE_LIMIT = 3;
 
   QueueConnection queueConnection;
   QueueSession queueSession;
   QueueSender queueSender;
 
   int successiveFailureCount = 0;
 
The QueueConnectionFactoryBindingName option takes a string value. Its value will be used to lookup the appropriate QueueConnectionFactory from the JNDI context.
 
   public void setQueueConnectionFactoryBindingName(String qcfBindingName) {
     this. = qcfBindingName;
   }

  
Returns the value of the QueueConnectionFactoryBindingName option.
 
     return ;
   }

  
The QueueBindingName option takes a string value. Its value will be used to lookup the appropriate Queue from the JNDI context.
 
   public void setQueueBindingName(String queueBindingName) {
     this. = queueBindingName;
   }

  
Returns the value of the QueueBindingName option.
 
   public String getQueueBindingName() {
     return ;
   }

  
Options are activated and become effective only after calling this method.
 
   public void start() {
     QueueConnectionFactory queueConnectionFactory;
 
     try {
       Context jndi = buildJNDIContext();
 
       // addInfo("Looking up [" + qcfBindingName + "]");
       queueConnectionFactory = (QueueConnectionFactory) lookup(jndi,
           );
       // addInfo("About to create QueueConnection.");
      if ( != null) {
        this. = queueConnectionFactory.createQueueConnection(
            );
      } else {
        this. = queueConnectionFactory.createQueueConnection();
      }
      // addInfo(
      // "Creating QueueSession, non-transactional, "
      // + "in AUTO_ACKNOWLEDGE mode.");
      this. = .createQueueSession(false,
          Session.AUTO_ACKNOWLEDGE);
      // addInfo("Looking up queue name [" + queueBindingName + "].");
      Queue queue = (Queue) lookup(jndi);
      // addInfo("Creating QueueSender.");
      this. = .createSender(queue);
      // addInfo("Starting QueueConnection.");
      .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);
      .send(msg);
       = 0;
    } catch (Exception e) {
        stop();
      }
      addError("Could not send message in JMSQueueAppender [" +  + "]."e);
    }
  }

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

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

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