FileDocCategorySizeDatePackage
SimpleJMSListener.javaAPI DocApache Axis 1.47010Sat Apr 22 18:57:26 BST 2006org.apache.axis.transport.jms

SimpleJMSListener

public class SimpleJMSListener extends Object implements javax.jms.MessageListener
SimpleJMSListener implements the javax.jms.MessageListener interface. Its basic purpose is listen asynchronously for messages and to pass them off to SimpleJMSWorker for processing. Note: This is a simple JMS listener that does not pool worker threads and is not otherwise tuned for performance. As such, its intended use is not for production code, but for demos, debugging, and performance profiling.
author
Jaime Meritt (jmeritt@sonicsoftware.com)
author
Richard Chung (rchung@sonicsoftware.com)
author
Dave Chappell (chappell@sonicsoftware.com)

Fields Summary
protected static Log
log
private static boolean
doThreads
private JMSConnector
connector
private JMSEndpoint
endpoint
private org.apache.axis.server.AxisServer
server
private HashMap
connectorProps
private static org.apache.axis.server.AxisServer
myAxisServer
Constructors Summary
public SimpleJMSListener(HashMap connectorMap, HashMap cfMap, String destination, String username, String password, boolean doThreads)


        
                                
                                
         
    
        SimpleJMSListener.doThreads = doThreads;

        try {
            // create a JMS connector using the default vendor adapter
            JMSVendorAdapter adapter = JMSVendorAdapterFactory.getJMSVendorAdapter();
            connector = JMSConnectorFactory.createServerConnector(connectorMap,
                                                                  cfMap,
                                                                  username,
                                                                  password,
                                                                  adapter);
            connectorProps = connectorMap;
        } catch (Exception e) {
            log.error(Messages.getMessage("exception00"), e);
            throw e;
        }

        // create the appropriate endpoint for the indicated destination
        endpoint = connector.createEndpoint(destination);
    
Methods Summary
public static final java.util.HashMapcreateCFMap(org.apache.axis.utils.Options options)

        String cfFile = options.isValueSet('c");
        if(cfFile == null)
            return null;

        Properties cfProps = new Properties();
        cfProps.load(new BufferedInputStream(new FileInputStream(cfFile)));
        HashMap cfMap = new HashMap(cfProps);
        return cfMap;
    
public static final java.util.HashMapcreateConnectorMap(org.apache.axis.utils.Options options)

        HashMap connectorMap = new HashMap();
        if (options.isFlagSet('t") > 0)
        {
            //queue is default so only setup map if topic domain is required
            connectorMap.put(JMSConstants.DOMAIN, JMSConstants.DOMAIN_TOPIC);
        }
        return connectorMap;
    
protected static org.apache.axis.server.AxisServergetAxisServer()


       
    
        return myAxisServer;
    
protected JMSConnectorgetConnector()

        return connector;
    
public static voidmain(java.lang.String[] args)

        Options options = new Options(args);

        // first check if we should print usage
        if ((options.isFlagSet('?") > 0) || (options.isFlagSet('h") > 0))
            printUsage();

        SimpleJMSListener listener = new SimpleJMSListener(createConnectorMap(options),
                                                           createCFMap(options),
                                                           options.isValueSet('d"),
                                                           options.getUser(),
                                                           options.getPassword(),
                                                           options.isFlagSet('s") > 0);
        listener.start();
    
public voidonMessage(javax.jms.Message message)
This method is called asynchronously whenever a message arrives.

param
message

        try
        {
            // pass off the message to a worker as a BytesMessage
            SimpleJMSWorker worker = new SimpleJMSWorker(this, (BytesMessage)message);

            // do we allow multi-threaded workers?
            if (doThreads) {
                Thread t = new Thread(worker);
                t.start();
            } else {
                worker.run();
            }
        }
        catch(ClassCastException cce)
        {
            log.error(Messages.getMessage("exception00"), cce);
            cce.printStackTrace();
            return;
        }
    
public static voidprintUsage()

        System.out.println("Usage: SimpleJMSListener [options]");
        System.out.println(" Opts: -? this message");
        System.out.println();
        System.out.println("       -c connection factory properties filename");
        System.out.println("       -d destination");
        System.out.println("       -t topic [absence of -t indicates queue]");
        System.out.println();
        System.out.println("       -u username");
        System.out.println("       -w password");
        System.out.println();
        System.out.println("       -s single-threaded listener");
        System.out.println("          [absence of option => multithreaded]");

        System.exit(1);
    
public voidshutdown()

        endpoint.unregisterListener(this);
        connector.stop();
        connector.shutdown();
    
public voidstart()

        endpoint.registerListener(this, connectorProps);
        connector.start();