Websphere MQ Everyplace

examples.osgi.server
Class MQeServerApp

java.lang.Object
  |
  +--examples.osgi.server.MQeServerApp
All Implemented Interfaces:
MQeMessageListenerInterface, java.lang.Runnable

public class MQeServerApp
extends java.lang.Object
implements java.lang.Runnable, MQeMessageListenerInterface

Example MQe Application. An MQeQueueManager is defined and started with a listener and default queues in memory. MQe code is then run in a new thread which sits and via a message listener waits for incoming messages, any received messages are displayed in the console. This continues to listen until shutdownMQeServer() method is called at which time it stops and deletes the MQeQueueManager. This Example uses the helper class:

  . MQeAdmin - used to configure MQe Components. 
       
 
This class contains the MQe code to create a message listener and wait for messages. It is written this way to separate the MQe configuration code from the Application code. This class is expected to be used in a particular way with the 5 main methods being called in a defined order as detailed below:
  . MQeServerApp(String qmName, String regLocation)
         This constructor must be used, supplying the QM name and registry location
         to be used.
  . setServerAddressAndPort() 
         Sets the servers address and port, the address is ignored here.
  . setupMQeServer()
         This defines and starts a QM in memory and then adds and starts a listener.
  . runTest()
         This creates a new MQeServer and starts it in a new thread.
  . shutdownMQeServer()
         This stops the MQeServer thread and shutsdown and deletes the QM.
 
A main method is also supplied to enable testing of this class outside of the OSGI framework. By default the MQeTcpipHttpAdapter is used for comms and the MQeMemoryFieldsAdapter is used for registry storage. The Port to be used by the MQeListener can be configured by using the setReceiversAddressAndPort method.


Field Summary
static short[] version
           
 
Constructor Summary
MQeServerApp(java.lang.String qmName, java.lang.String regLocation)
          Constructor to create a new MQeServerApp.
 
Method Summary
static void main(java.lang.String[] args)
          This main method can be used to test the example outside of the OSGI framework.
 void messageArrived(MQeMessageEvent e)
          This method is called when a message arrives on a queue.
 void run()
          Run Method Adds the message listener to the default queue.
 void runTest()
          This creates and starts a new MQeServerApp object in its own thread.
 void setServerAddressAndPort(java.lang.String targetQMIPAddress, java.lang.String targetQMPort)
          Method used to set the servers address and port.
 void setupMQeServer()
          Checks to see if a QM is already running.
 void shutdownMQeServer()
          This stops the MQeServer thread and shutsdown and deletes the QM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static short[] version
Constructor Detail

MQeServerApp

public MQeServerApp(java.lang.String qmName,
                    java.lang.String regLocation)
Constructor to create a new MQeServerApp. This sets the QueueManger name and Registry location to be used by the MQeQueuemanager. It also creates a new MQeAdmin object to be used to setup MQe.

Method Detail

run

public void run()
Run Method Adds the message listener to the default queue.

Specified by:
run in interface java.lang.Runnable

setServerAddressAndPort

public void setServerAddressAndPort(java.lang.String targetQMIPAddress,
                                    java.lang.String targetQMPort)
Method used to set the servers address and port. The port number is what will be used by the MQeListener. If this method is not used then then default is 8085. Address parameter is not currently used.


setupMQeServer

public void setupMQeServer()
                    throws java.lang.Exception
Checks to see if a QM is already running. If not it uses the MQeAdmin to define a new QM, start it then create a listener and start it. If a QM is already running then an exception is thrown.

java.lang.Exception

runTest

public void runTest()
This creates and starts a new MQeServerApp object in its own thread. This sets a message listener on a Queue and prints out received messages. The MQeServer must be run in it's own thread or the BundleActivator.start methods will not return and the bundle will not start correctly.


shutdownMQeServer

public void shutdownMQeServer()
This stops the MQeServer thread and shutsdown and deletes the QM.


messageArrived

public void messageArrived(MQeMessageEvent e)
                    throws java.lang.Exception
This method is called when a message arrives on a queue. This checks the message arrived event is from the default queue and then checks if the message received is a JMS Message if so it calls printJMSMessage(msg) , to print it, otherwise it just prints out the contents of the messages "MsgData" field.

Specified by:
messageArrived in interface MQeMessageListenerInterface
Parameters:
e - com.ibm.mqe.MQeMessageEvent
Returns:
void
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
This main method can be used to test the example outside of the OSGI framework. In the framework the same job is done by the Activators start and stop methods.


Websphere MQ Everyplace