⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unifysupplier.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
package com.wls8unleashed.jms;

import javax.jms.*;
import javax.naming.*;
import java.util.*;
import java.io.*;

/**
 * Implements the functionality to produce a message to
 * a destination. Extends the UnifyManager for init info.
 */
public class UnifySupplier extends UnifyManager{

	private MessageProducer producer;

	/** 
	 * Initializes the unified JMS supplier.
	 */
	public UnifySupplier(Context context){

    // Call superclass QueueManager constructor
		super(context);
		
		try{
  		// Create generic producer
  		System.out.println("Creating generic JMS producer...");
			producer = session.createProducer(destination);
    }catch(JMSException e){
      System.out.println("Problem creating Queue Sender");
      e.printStackTrace();
    }		
	}

	/**
   * Send an order message to a destination.
   */
	public void sendOrder(OrderItem message) throws JMSException {
		System.out.println("Sending order message:" + message);

		// Create empty ObjectMessage on session
		System.out.println("Creating empty object message...");
		ObjectMessage sendingMessage = session.createObjectMessage();
		
		// Start the generic JMS connection
		System.out.println("Starting generic JMS connection...");
		connection.start();
		
		// Set the order object onto the message carrier
		System.out.println("Setting order item into message...");
		sendingMessage.setObject((Serializable) message);
		
		// Send the message
		System.out.println("Sending the order message...");
		producer.send(sendingMessage);
	}

	/**
	  * Close JMS related objects.
	  */
	public void close() throws JMSException {
		producer.close();
		session.close();
		connection.close();
	}


  /**
   * Main method used to execute the UnifySupplier example
   */
	public static void main(String[] args) {
    try{
			// Get some orders from the OrderManager class
			System.out.println("Getting a bunch of orders to send...");
			Collection orders = OrderManager.getOrders();

			// For each order, get order request and send to consumer
			Iterator it = orders.iterator();
			while (it.hasNext()) {
				// Get an OrderItem object to send
				OrderItem item = (OrderItem) it.next();

				// Create JNDI context
				Context context = Props.getInitialContext();

				// Create new QueueSupplier
				System.out.println("Creating new UnifySupplier...");
				UnifySupplier supplier = new UnifySupplier(context);
               
        // Send the order
        System.out.println("Initiating order to send...");
        supplier.sendOrder(item);
        
        // Close UnifySupplier
        System.out.println("Closing UnifySupplier...");
        supplier.close();
      }
    }catch(Exception e){
      System.out.println("Problem executing unified model supplier");
      e.printStackTrace();
    }      
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -