package examples.jms.sessionpool;

import javax.jms.*;

/**
 * The WebLogic Server can be configured to manage a pool of 
 * message listeners. Messages matching a particular
 * selection criteria are processed in parallel by listeners
 * in the pool.  This feature is described in chapter 8 of
 * the JMS Specification, version 1.0.1.
 * <p>
 * @author Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
 */

public class MsgListener
  implements MessageListener
{
  private Session session;

  /**
   * When creating message listeners, a constructor is called with the
   * listener's session object.  If a matching constructor does not 
   * exist, the default (no argument) constructor is called.
   */
  public MsgListener(Session session)
  {
    this.session = session;
  }

  /* MessageListener interface */

  public void onMessage(Message msg)
  {
    try {
      String msgText = ((TextMessage)msg).getText();
      String threadName = "<"+Thread.currentThread().getName()+ ">";

      System.out.println(threadName + ": Receiving JMS Message: "+ msgText);
      msg.acknowledge();
    } catch (JMSException jmse) {
      jmse.printStackTrace();
    }
  }


}




