Websphere MQ Everyplace

examples.osgi.client
Class MQeClientApp

java.lang.Object
  |
  +--examples.osgi.client.MQeClientApp
All Implemented Interfaces:
java.lang.Runnable

public class MQeClientApp
extends java.lang.Object
implements java.lang.Runnable

Example MQe Application. This checks to see if an MQeQueueManager is already running in the JVM, if so it assumes it is running in the same runtime as the server application and so uses that QueueManager. If no QueueManager is detected then a new one is defined and started in memory and a connection definition and remote queue definition are setup to the server. Code is then run in a new thread which sends a single message to the server. No checks are made to ensure the message is received. If we created a new QueueManager for the Client then it is stopped and deleted when it is stopped by calling shutdownMQeClient(). This Example uses a helper class:

  . MQeAdmin - used to configure MQe Components. 
       
 
This class contains the code to create and send a message. It is written this way to separate the MQe configuration code from 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:
  . MQeClientApp(String qmName, String regLocation)
         This constructor must be used, supplying the QM name and registry location
         to be used.
  . setServerAddressAndPort
         sets the port and address where the MQeServerApp is running
  . setupMQeClient()
         This defines and starts a QM in memory with default queues.
  . runJMSTest()
         This creates a new MQeClient and starts it in a new thread.
  . shutdownMQeClient()
         This shutsdown and deletes the QM.
 
A main method is also supplied to enable testing of this class outside of the OSGI framework. The MQeClientApp has been written so that it can be either run in the same JVM as the MQeServerApp in which case it will share the underlying MQeQueueManager OR it can be run in its own JVM, perhaps even on a seperate machine, in this case the MQeClientApp starts has its own QueueManager. In either case the MQeServerApp should be started first. By default the MQeTcpipHttpAdapter is used for comms and the MQeMemoryFieldsAdapter is used for registry storage. The port and address where the MQeServerApp is running can be configured by using the setReceiversAddressAndPort method.


Field Summary
static short[] version
           
 
Constructor Summary
MQeClientApp(java.lang.String qmName, java.lang.String regLocation)
          Constructor to create a new MQeClientApp.
 
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 run()
          Run Method Creates and sends the message.
 void runTest()
          This starts the new MQeClientApp object in its own thread.
 void setServerAddressAndPort(java.lang.String targetQMIPAddress, java.lang.String targetQMPort)
          Method used to set the recievers address and port.
 void setupMQeClient()
          Checks to see if a QM is already running.
 void shutdownMQeClient()
          This stops the sending thread.
 
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

MQeClientApp

public MQeClientApp(java.lang.String qmName,
                    java.lang.String regLocation)
Constructor to create a new MQeClientApp. 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 Creates and sends the message.

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 recievers address and port. If this method is not used then then default is 8085 on 127.0.0.1.


setupMQeClient

public void setupMQeClient()
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 connection defintion to the servers QM. It then adds a remote queue defintion to the servers local queue. If a QM is already running then it assumes the server has already been started in the same JVM so uses that QM.


runTest

public void runTest()
This starts the new MQeClientApp object in its own thread. This uses the run method to send a single message to the reciever.


shutdownMQeClient

public void shutdownMQeClient()
This stops the sending thread. If we started our own QM in setupMQeClient() then we shutsdown and deletes the QM.


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