The Java EE 6 Tutorial

ProcedureTo Build, Package, Deploy, and Run transactedexample Using Ant and the appclient Command

  1. In a terminal window, go to the following directory:

    tut-install/examples/jms/advanced/transactedexample/
    
  2. Create the necessary resources using the following command:


    ant create-resources
    

    This command creates three destination resources with the names jms/AQueue, jms/BQueue, and jms/CQueue, all of type javax.jms.Queue, and one destination resource with the name jms/OTopic, of type javax.jms.Topic.

  3. To build and package the client, type the following command:


    ant
    
  4. Deploy the client JAR file to the GlassFish Server, then retrieve the client stubs:


    ant getclient
    

    Ignore the message that states that the application is deployed at a URL.

  5. Use a command like the following to run the client.

    The argument specifies the number of computers to order.


    appclient -client client-jar/transactedexampleClient.jar 3
    

    The output looks something like this (along with some application client container output):


    Quantity to be ordered is 3
    Retailer: ordered 3 computer(s)
    Vendor: Retailer ordered 3 Computer(s)
    Vendor: ordered 3 monitor(s) and hard drive(s)
    Monitor Supplier: Vendor ordered 3 Monitor(s)
    Monitor Supplier: sent 3 Monitor(s)
      Monitor Supplier: committed transaction
      Vendor: committed transaction 1
    Hard Drive Supplier: Vendor ordered 3 Hard Drive(s)
    Hard Drive Supplier: sent 1 Hard Drive(s)
    Vendor: Completed processing for order 1
      Hard Drive Supplier: committed transaction
    Vendor: unable to send 3 computer(s)
      Vendor: committed transaction 2
    Retailer: Order not filled
    Retailer: placing another order
    Retailer: ordered 6 computer(s)
    Vendor: JMSException occurred: javax.jms.JMSException: 
    Simulated database concurrent access exception
    javax.jms.JMSException: Simulated database concurrent access exception
            at TransactedExample$Vendor.run(Unknown Source)
      Vendor: rolled back transaction 1
    Vendor: Retailer ordered 6 Computer(s)
    Vendor: ordered 6 monitor(s) and hard drive(s)
    Monitor Supplier: Vendor ordered 6 Monitor(s)
    Hard Drive Supplier: Vendor ordered 6 Hard Drive(s)
    Monitor Supplier: sent 6 Monitor(s)
      Monitor Supplier: committed transaction
    Hard Drive Supplier: sent 6 Hard Drive(s)
      Hard Drive Supplier: committed transaction
      Vendor: committed transaction 1
    Vendor: Completed processing for order 2
    Vendor: sent 6 computer(s)
    Retailer: Order filled
      Vendor: committed transaction 2
  6. After you run the client, you can delete the physical destinations and the destination resources. Go to the directory tut-install/examples/jms/advanced/transactedexample/ and type the following command:


    ant delete-resources