FileDocCategorySizeDatePackage
Main.javaAPI DocJBoss 4.2.14098Fri Jul 13 20:55:36 BST 2007org.jboss.tutorial.mdbstandalone

Main

public class Main extends Object
Comment
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
Constructors Summary
Methods Summary
private static voidexecuteQueue()


      QueueConnection cnn = null;
      QueueSender sender = null;
      QueueSession session = null;

      Queue queue = (Queue) getInitialContext().lookup("queue/mdbtest");
      QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");
      cnn = factory.createQueueConnection();
      session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

      TextMessage msg = session.createTextMessage("Hello World");

      sender = session.createSender(queue);
      sender.send(msg);

      Thread.sleep(1000);
      session.close();
      cnn.close();
   
private static voidexecuteTopic()


      TopicConnection cnn = null;
      TopicPublisher sender = null;
      TopicSession session = null;

      Topic topic = (Topic) getInitialContext().lookup("topic/topictest");
      TopicConnectionFactory factory = (TopicConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");
      cnn = factory.createTopicConnection();
      session = cnn.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);

      TextMessage msg = session.createTextMessage("Hello World");

      sender = session.createPublisher(topic);
      sender.send(msg);

      Thread.sleep(1000);
      session.close();
      cnn.close();
   
public static javax.naming.InitialContextgetInitialContext()

      Hashtable props = getInitialContextProperties();
      return new InitialContext(props);
   
private static java.util.HashtablegetInitialContextProperties()

      Hashtable props = new Hashtable();
      props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
      props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      return props;
   
public static voidmain(java.lang.String[] args)

      EJB3StandaloneBootstrap.boot(null);
      // initialize JBoss MQ core services
      EJB3StandaloneBootstrap.deployXmlResource("jboss-jms-beans.xml");
      // initialize configured test queue and topic
      EJB3StandaloneBootstrap.deployXmlResource("testjms.xml");
      // scan classpath for ejbs and MDBs
      EJB3StandaloneBootstrap.scanClasspath();

      executeQueue();
      executeTopic();

      EJB3StandaloneBootstrap.shutdown();