Websphere MQ Everyplace

examples.midp.exampleapp.messageservice
Class MQeMessageService

java.lang.Object
  |
  +--examples.midp.exampleapp.messageservice.MQeMessageService
All Implemented Interfaces:
MessageService, MQeMessageListenerInterface, MQeMessageServiceConstants

public class MQeMessageService
extends java.lang.Object
implements MessageService, MQeMessageListenerInterface, MQeMessageServiceConstants

This implements a message service and aims to wrap an mqe queue manager and provide all basic functionality with a simpler interface.

This means that all queue and queue manager creation and administration will be done via this class.

Functions can be split up as follows:

 Message Service Functions
 ---------------------------------------------
 getMessageConsumer()
 getQMname()
 getStartupParameters()
 setStartupParameters()
 messageArrived() [inherited from MQeMessageListenerInterface]
 processAlias()

 Queue Manager Functions
 ---------------------------------------------
 createListener()

 Messaging Functions
 ---------------------------------------------
 primeAdminMessage()
 processAdminMessage()
 


Field Summary
static short[] version
           
 
Fields inherited from interface examples.midp.exampleapp.messageservice.MQeMessageServiceConstants
DEFAULT_BASEDIRNAME, DEFAULT_CHANNEL, DEFAULT_CHANNELATTRRULES, DEFAULT_COMPRESSOR, DEFAULT_CRYPTOR, DEFAULT_EVENTLOG, DEFAULT_FASTNETWORK, DEFAULT_FILEREGISTRY, DEFAULT_LISTENERADAPTER, DEFAULT_LISTENERPORT, DEFAULT_MAXCHANNELS, DEFAULT_MSGLOG, DEFAULT_NETWORK, DEFAULT_PIN, DEFAULT_PRIVATEREGISTRY, DEFAULT_QUEUEMANAGER, DEFAULT_TIMEINTERVAL, DEFAULT_TRACE, DEFAULT_TRANSPORTER
 
Constructor Summary
MQeMessageService()
           
 
Method Summary
 boolean checkAdminReply(MQeAdminMsg replyMsg)
          Check to see if a good reply was received.
 void close()
          Closes the message service, allowing it to tidy up.
protected  void closeQM()
          Closes down the queue manager.
 void createConnection(java.lang.String onQMgr, java.lang.String name, java.lang.String adapter, java.lang.String parms, java.lang.String options)
          Create a new connection definition.
 void createHomeServerQueue(java.lang.String onQMgr, java.lang.String qm, java.lang.String q, long pollTime)
          Creates a home server queue.
 void createListener(java.lang.String listenerName)
          Create a new listener and start it running.
 void createLocalQueue(java.lang.String onQMgr, java.lang.String q, boolean sync)
          Creates a new (simple) local queue with no cryptor or compressor.
 void createLocalQueue(java.lang.String onQMgr, java.lang.String q, boolean sync, java.lang.String compressor, java.lang.String cryptor)
          Creates a new local queue.
 void createQueueManager()
          Creates the queue manager.
 void createRemoteQueue(java.lang.String onQMgr, java.lang.String qm, java.lang.String q, boolean sync)
          Creates a new (simple) remote queue with no cryptor of compressor.
 void createRemoteQueue(java.lang.String onQMgr, java.lang.String qm, java.lang.String q, boolean sync, java.lang.String compressor, java.lang.String cryptor)
          Creates a new remote queue.
 void createStoreAndForwardQueue(java.lang.String onQMgr, java.lang.String qm, java.lang.String q)
          Creates a store and forward queue.
 void emptyQueue(java.lang.String queueManagerName, java.lang.String queueName)
          Deletes all messages from a named queue.
 MQeMsgObject getMessage(java.lang.String queueManagerName, java.lang.String queueName, MQeFields filter)
          Get a message from a given queue manager/queue.
 MessageConsumer getMessageConsumer()
          Returns a reference to the GUI object that handles consumption of messages.
 java.lang.String getQMname()
          Gets the name of the local queue manager.
 MQeMsgObject getSecureMessage(java.lang.String queueManagerName, java.lang.String queueName, MQeFields filter, MQeAttribute attribute)
          Gets a secure message from a given queue manager/queue.
 MQeMessageServiceParameters getStartupParameters()
          Returns the startup parameters given to the message service when it was initialized.
 void messageArrived(MQeMessageEvent e)
          Processes a new message event.
 void monitorQueue(java.lang.String queueManagerName, java.lang.String queueName)
          Setup a monitor that will check for new messages on a queue.
 void open()
          Performs the processing needed to activate the system.
 MQeFields primeAdminMsg(java.lang.String onQMgr, MQeAdminMsg msg)
          Prime an admin message.
 MQeAdminMsg processAdminMsg(java.lang.String onQMgr, MQeAdminMsg msg)
          Send the admin message, wait for a reply and check for success.
 void processAlias()
          Process the class alias names in the configuration data.
 void processMessages(java.lang.String queueManagerName, java.lang.String queueName, MQeFields match)
          Process any messages that match a filter on a given queue.
 void sendMessage(java.lang.String queueManagerName, java.lang.String queueName, MQeMsgObject message)
          Send a message to a given queue manager/queue.
 void sendSecureMessage(java.lang.String queueManagerName, java.lang.String queueName, MQeMsgObject message, MQeAttribute attribute)
          Send a secure message to a given queue manager/queue.
 void setMessageConsumer(MessageConsumer GUI)
          Let the message service know the graphical component that can display messages.
 void setStartupParameters(MQeMessageServiceParameters parms)
          Set the object that contains any parameters required to start the message service.
 void updateQueueManager(java.lang.String onQMgr, MQeFields parms)
          Change the characteristics of a queue manager.
 MQeMsgObject waitForReply(java.lang.String onQMgr, java.lang.String onQueue, MQeFields msgTest)
          Wait a while for a message to turn up on a queue.
 
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

MQeMessageService

public MQeMessageService()
Method Detail

checkAdminReply

public boolean checkAdminReply(MQeAdminMsg replyMsg)
                        throws java.lang.Exception
Check to see if a good reply was received. If not, detail the error(s) that occured.

Parameters:
replyMsg - Reply message to check
Returns:
boolean - true if good
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Closes the message service, allowing it to tidy up.
- stop new incoming requests (stop channel listener)
- stop the queue manager.
- close any incoming requests.

Although this only calls closeQMgr, in the future, other things may also require being closed.

Specified by:
close in interface MessageService
Returns:
void
Throws:
java.lang.Exception

closeQM

protected void closeQM()
                throws java.lang.Exception
Closes down the queue manager.

Returns:
void
java.lang.Exception

createConnection

public void createConnection(java.lang.String onQMgr,
                             java.lang.String name,
                             java.lang.String adapter,
                             java.lang.String parms,
                             java.lang.String options)
                      throws java.lang.Exception
Create a new connection definition.

Specified by:
createConnection in interface MessageService
Parameters:
onQMgr - Which QMgr to send the admin message
name - Name of the connection
adapter - Adapter plus base parms to be used
parms - Connection parameters
options - Connection options
Returns:
void
Throws:
java.lang.Exception

createListener

public void createListener(java.lang.String listenerName)
                    throws java.lang.Exception
Create a new listener and start it running.

This function can be divided into 2 parts
- the creation of the listener
- the starting of the listener

Parameters:
listenerName - The name of listener
Returns:
void
Throws:
java.lang.Exception

createHomeServerQueue

public void createHomeServerQueue(java.lang.String onQMgr,
                                  java.lang.String qm,
                                  java.lang.String q,
                                  long pollTime)
                           throws java.lang.Exception
Creates a home server queue.

Specified by:
createHomeServerQueue in interface MessageService
Parameters:
onQMgr - Which QMgr to send the admin message
qm - Queue manager the queue resides on
q - Name of the queue
pollTime - The polltime for checking for messages
0 = do not poll check for messages on call to triggerTransmission()
Returns:
void
Throws:
java.lang.Exception

createLocalQueue

public void createLocalQueue(java.lang.String onQMgr,
                             java.lang.String q,
                             boolean sync)
                      throws java.lang.Exception
Creates a new (simple) local queue with no cryptor or compressor.

Parameters:
onQMgr - The queue manager that the queue is located on
q - The name of the queue
sync - True for a synchronous queue, false for async
Returns:
void
Throws:
java.lang.Exception

createLocalQueue

public void createLocalQueue(java.lang.String onQMgr,
                             java.lang.String q,
                             boolean sync,
                             java.lang.String compressor,
                             java.lang.String cryptor)
                      throws java.lang.Exception
Creates a new local queue.

Specified by:
createLocalQueue in interface MessageService
Parameters:
onQMgr - The queue manager that the queue is located on
q - The name of the queue
sync - True for a synchronous queue, false for async
compressor - The compressor class to use
cryptor - The cryptor class to use
Returns:
void
Throws:
java.lang.Exception

createQueueManager

public void createQueueManager()
                        throws java.lang.Exception
Creates the queue manager.

Specified by:
createQueueManager in interface MessageService
Returns:
void
Throws:
java.lang.Exception

createRemoteQueue

public void createRemoteQueue(java.lang.String onQMgr,
                              java.lang.String qm,
                              java.lang.String q,
                              boolean sync)
                       throws java.lang.Exception
Creates a new (simple) remote queue with no cryptor of compressor.

Parameters:
onQMgr - Which QMgr to send the admin message
qm - Queue manager the queue resides on
q - Name of the queue
sync - True for synchronous, false for asynchronous
Returns:
void
Throws:
java.lang.Exception

createRemoteQueue

public void createRemoteQueue(java.lang.String onQMgr,
                              java.lang.String qm,
                              java.lang.String q,
                              boolean sync,
                              java.lang.String compressor,
                              java.lang.String cryptor)
                       throws java.lang.Exception
Creates a new remote queue.

Specified by:
createRemoteQueue in interface MessageService
Parameters:
onQMgr - Which QMgr to send the admin message
qm - Queue manager the queue resides on
q - Name of the queue
sync - True for synchronous, false for asynchronous
compressor - The compressor class to use
cryptor - The cryptor class to use
Returns:
void
Throws:
java.lang.Exception

createStoreAndForwardQueue

public void createStoreAndForwardQueue(java.lang.String onQMgr,
                                       java.lang.String qm,
                                       java.lang.String q)
                                throws java.lang.Exception
Creates a store and forward queue.

Specified by:
createStoreAndForwardQueue in interface MessageService
Parameters:
onQMgr - Which QMgr to send the admin message
qm - Queue manager the queue resides on
q - Name of the queue
Returns:
void
Throws:
java.lang.Exception

emptyQueue

public void emptyQueue(java.lang.String queueManagerName,
                       java.lang.String queueName)
                throws java.lang.Exception
Deletes all messages from a named queue.

Specified by:
emptyQueue in interface MessageService
Parameters:
queueManagerName - Queue manager the queue resides on
queueName - Name of the queue
Returns:
void
Throws:
java.lang.Exception

getMessage

public MQeMsgObject getMessage(java.lang.String queueManagerName,
                               java.lang.String queueName,
                               MQeFields filter)
                        throws java.lang.Exception
Get a message from a given queue manager/queue.

Specified by:
getMessage in interface MessageService
Parameters:
queueManagerName - Which QMgr to get the message from
queueName - Which queue to get the message from
filter - Get a message that matches the filter
Returns:
MQeMsgObject
Throws:
java.lang.Exception

getMessageConsumer

public MessageConsumer getMessageConsumer()
Returns a reference to the GUI object that handles consumption of messages.

Returns:
MessageConsumer

getQMname

public java.lang.String getQMname()
                           throws java.lang.Exception
Gets the name of the local queue manager.

Returns:
String
Throws:
java.lang.Exception

getSecureMessage

public MQeMsgObject getSecureMessage(java.lang.String queueManagerName,
                                     java.lang.String queueName,
                                     MQeFields filter,
                                     MQeAttribute attribute)
                              throws java.lang.Exception
Gets a secure message from a given queue manager/queue.

Specified by:
getSecureMessage in interface MessageService
Parameters:
queueManagerName - Which QMgr to get the message from
queueName - Which queue to get the message from
filter - Get a message that matches the filter
attribute - The attribute used to decode the secure message
Returns:
MQeMsgObject
Throws:
java.lang.Exception

getStartupParameters

public MQeMessageServiceParameters getStartupParameters()
                                                 throws java.lang.Exception
Returns the startup parameters given to the message service when it was initialized.

Returns:
MQeMessageServiceParameters
java.lang.Exception

messageArrived

public void messageArrived(MQeMessageEvent e)
Processes a new message event. A new message has arrived on a queue that is being monitored, tell the GUI about it.

Specified by:
messageArrived in interface MQeMessageListenerInterface
Parameters:
e - The event that has occurred
Returns:
void

monitorQueue

public void monitorQueue(java.lang.String queueManagerName,
                         java.lang.String queueName)
Setup a monitor that will check for new messages on a queue. If this is a local queue then a message listener can be used to automatically monitor for new messages. If this is a remote queue then the remote queue will have to be polled either automatically or by user request to see if there are any new messages.

NOTE: monitoring of remote queues is not yet implemented!

Specified by:
monitorQueue in interface MessageService
Parameters:
queueManagerName - Queue manager the queue resides on
queueName - Name of the queue
Returns:
void

open

public void open()
          throws java.lang.Exception
Performs the processing needed to activate the system. Starts the local queue manager (and configures it if it is not already configured).

Specified by:
open in interface MessageService
Returns:
void
Throws:
java.lang.Exception

primeAdminMsg

public MQeFields primeAdminMsg(java.lang.String onQMgr,
                               MQeAdminMsg msg)
                        throws java.lang.Exception
Prime an admin message. Sets the admin message with items such as who to reply to along with a unique identifier that can be used to check for a matching response.

Parameters:
onQMgr - The name of the queue manager where the message will be sent.
msg - The admin message to prime
Returns:
MQeFields - a unique identifier for this request
Throws:
java.lang.Exception

processAdminMsg

public MQeAdminMsg processAdminMsg(java.lang.String onQMgr,
                                   MQeAdminMsg msg)
                            throws java.lang.Exception
Send the admin message, wait for a reply and check for success. throws an exception if there is an error.

Parameters:
onQMgr - The name of the queue manager where the message will be sent.
msg - The admin message to send
Returns:
MQeAdminMsg - the response to the message
Throws:
java.lang.Exception

processAlias

public void processAlias()
                  throws java.lang.Exception
Process the class alias names in the configuration data.

This maps one class name to another, or acts as an alias to a class name.

 [Alias]
      (ascii)EventLog=.....        class to use to write event logs
      (ascii)Network=.....         Adapter class for network support
      (ascii)QueueManager=.....    class to use for Queue manager
      (ascii)Registry=.....        class to use for Registry functions
      (ascii)Trace=.....           class to provide trace functions
 

Returns:
void
Throws:
java.lang.Exception

processMessages

public void processMessages(java.lang.String queueManagerName,
                            java.lang.String queueName,
                            MQeFields match)
Process any messages that match a filter on a given queue.

A very simplistic approach is taken to handling any messages found: If the message is a request then the processMessage() method is called on the GUI, if it is a reply or datagram or not specified then the displayMessage method is called on the GUI.

NOTE: The message is only browsed in this method so the message is left on the queue it is down to anyone processing the message to get/delete it on the queue!

Specified by:
processMessages in interface MessageService
Parameters:
queueManagerName - Which QMgr to browse
queueName - Which queue to browse
match - Only return fields matching
Returns:
void

sendMessage

public void sendMessage(java.lang.String queueManagerName,
                        java.lang.String queueName,
                        MQeMsgObject message)
                 throws java.lang.Exception
Send a message to a given queue manager/queue.

Specified by:
sendMessage in interface MessageService
Parameters:
queueManagerName - Which QMgr to send the message
queueName - Which queue to send the message to
message - The message to send
Returns:
void
Throws:
java.lang.Exception

sendSecureMessage

public void sendSecureMessage(java.lang.String queueManagerName,
                              java.lang.String queueName,
                              MQeMsgObject message,
                              MQeAttribute attribute)
                       throws java.lang.Exception
Send a secure message to a given queue manager/queue. This is a message that requires a cryptor or compressor.

Specified by:
sendSecureMessage in interface MessageService
Parameters:
queueManagerName - Which QMgr to send the message
queueName - Which queue to send the message to
message - The message to send
Returns:
void
Throws:
java.lang.Exception

setMessageConsumer

public void setMessageConsumer(MessageConsumer GUI)
Let the message service know the graphical component that can display messages.

Specified by:
setMessageConsumer in interface MessageService
Parameters:
GUI - The message consumer to be set to
Returns:
void

setStartupParameters

public void setStartupParameters(MQeMessageServiceParameters parms)
Set the object that contains any parameters required to start the message service.

Parameters:
parms - The name of the local queue manager

updateQueueManager

public void updateQueueManager(java.lang.String onQMgr,
                               MQeFields parms)
                        throws java.lang.Exception
Change the characteristics of a queue manager.

Specified by:
updateQueueManager in interface MessageService
Parameters:
onQMgr - The name of the queue manager where the admin message will be sent.
parms - The parameters that need updating
Returns:
void
Throws:
java.lang.Exception

waitForReply

public MQeMsgObject waitForReply(java.lang.String onQMgr,
                                 java.lang.String onQueue,
                                 MQeFields msgTest)
                          throws java.lang.Exception
Wait a while for a message to turn up on a queue.

Specified by:
waitForReply in interface MessageService
Parameters:
onQMgr - Queue manager to wait on
onQueue - Queue to wait on
msgTest - Filter for a specific message
Returns:
MQeMsgObject - the reply message
Throws:
java.lang.Exception

Websphere MQ Everyplace