Websphere MQ Everyplace

examples.midp.exampleapp.textapp
Class AppModel

java.lang.Object
  |
  +--examples.midp.exampleapp.textapp.AppModel
All Implemented Interfaces:
MessageConsumer, java.lang.Runnable
Direct Known Subclasses:
AppModelClient, AppModelServer

public abstract class AppModel
extends java.lang.Object
implements MessageConsumer, java.lang.Runnable

The aim of the text app is to have 3 queue managers:
The Gateway server - a server that will be sent messages.
The Registration server - a server that new clients have to register with before they can send messages to the gateway.
The Client - a client that send messages to the gateway.

The aim of this example is to show how a registration server can be used to create the necessary resources for a new client. This approach gives several advantages to larger networks of MQe devices.

This class implements a basic model for a text app. Functions are available to create listeners, define queues and sends messages for both clients and servers.

The message service is used to connunicate with the underlying MQe structure to simplify the design of the code.


Field Summary
static java.lang.String DEFAULT_CLIENT_QM
          Default name for the client QM.
static java.lang.String DEFAULT_GATEWAY
          Default location for the gatewar server.
static java.lang.String DEFAULT_GATEWAY_QM
          Default name for the gateway QM.
static java.lang.String DEFAULT_HOMESERVER_Q
          Default name for a home server queue.
static int DEFAULT_LISTENER_PORT
          Default port for listeners.
static java.lang.String DEFAULT_REGISTRATION
          Default location for the registration server.
static int DEFAULT_REGISTRATION_LISTENER_PORT
          Default port for listeners on the registration QM.
static java.lang.String DEFAULT_REGISTRATION_Q
          Default name for the registration queue.
static java.lang.String DEFAULT_REGISTRATION_QM
          Default name for the registration QM.
static java.lang.String DEFAULT_REGISTRATION_REPLY_Q
          Default name for the registration reply queue.
static java.lang.String DEFAULT_REPLY_Q
          Default name for a reply queue.
static java.lang.String DEFAULT_REQUEST_Q
          Default name for a request queue.
static java.lang.String DEFAULT_RULES
          Default rules file to use.
static java.lang.String GatewayCommand
           
static java.lang.String GatewayOptions
           
static java.lang.String RegistrationCommand
           
static java.lang.String RegistrationOptions
           
static short[] version
           
 
Constructor Summary
AppModel()
           
 
Method Summary
protected  java.lang.String[] chooseConnections()
          Return a list of connections used by the model.
protected  java.lang.String[] chooseLocalQueues()
          Return a list of local queues used by the model.
protected  java.lang.String[] chooseRemoteQueues()
          Return a list of remote queues used by the model.
protected  void clearLocalQueues()
          Clears all local queues as defined by localQueues[].
protected  void createListener()
          Generates a name for the listener from the queue manager and creates it.
 AppController getController()
          Gets the controller.
protected abstract  int getListenerPort()
          Returns the port that the queue manager listens on.
 java.lang.String getLocalQMname()
          Gets the localQMname.
 MQeMessageService getMsgService()
          Gets the msgService.
protected  void initialConfiguration()
          Called if the queue manager has not been started up previously.
protected  void initializeConnections()
          This creates all the connections specified in connections[].
protected  void initializeLocalQueues()
          This creates all the local queues specified in localQueues[].
protected abstract  void initializeOtherQueues()
          This creates all less common queues that a queue manager may need ( home server queues, store and forward queues etc).
protected  void initializeRemoteQueues()
          This creates all the remote queues specified in remoteQueues[].
protected abstract  boolean isServer()
          Used to check whether the model is a client or server.
protected  void monitorLocalQueues()
          Will start monitoring of all local queues as specified in localQueues[].
 void processStatus(java.lang.String msg)
          Displays a message using the controller or if no controller is set, prints it to System.out.
 void registerWithCentral(java.lang.String QMname, java.lang.String Qname)
          Used to register a queue manager with the registration server.
 void run()
          Starts the model running (initialize should have been run first).
 void sendNewMessage(java.lang.String message)
          Sends a message to the default queue on the default queue manager.
 void setLocalQMname(java.lang.String localQMname)
          Sets the localQMname.
 void setMsgService(MQeMessageService msgService)
          Sets the msgService.
 void start(AppController controller, java.lang.String localQMname)
          Initializes the model and all necessary components.
protected  java.lang.String statusReport()
          Produces a status report for the queue manager.
 void stop()
          Stops the model and clears any local queues of messages befor closing the message service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface examples.midp.exampleapp.messageservice.MessageConsumer
processDataGramMsg, processReplyMsg, processRequestMsg
 

Field Detail

version

public static short[] version

DEFAULT_REGISTRATION_QM

public static final java.lang.String DEFAULT_REGISTRATION_QM
Default name for the registration QM.

See Also:
Constant Field Values

DEFAULT_GATEWAY_QM

public static final java.lang.String DEFAULT_GATEWAY_QM
Default name for the gateway QM.

See Also:
Constant Field Values

DEFAULT_CLIENT_QM

public static final java.lang.String DEFAULT_CLIENT_QM
Default name for the client QM.

See Also:
Constant Field Values

DEFAULT_LISTENER_PORT

public static final int DEFAULT_LISTENER_PORT
Default port for listeners.

See Also:
Constant Field Values

DEFAULT_REGISTRATION_LISTENER_PORT

public static final int DEFAULT_REGISTRATION_LISTENER_PORT
Default port for listeners on the registration QM.

This is to allow the gateway and registration QMs on the same machine.

See Also:
Constant Field Values

DEFAULT_GATEWAY

public static final java.lang.String DEFAULT_GATEWAY
Default location for the gatewar server.

See Also:
Constant Field Values

DEFAULT_REGISTRATION

public static final java.lang.String DEFAULT_REGISTRATION
Default location for the registration server.

See Also:
Constant Field Values

GatewayCommand

public static final java.lang.String GatewayCommand

GatewayOptions

public static final java.lang.String GatewayOptions

RegistrationCommand

public static final java.lang.String RegistrationCommand

RegistrationOptions

public static final java.lang.String RegistrationOptions

DEFAULT_REQUEST_Q

public static final java.lang.String DEFAULT_REQUEST_Q
Default name for a request queue.

See Also:
Constant Field Values

DEFAULT_REPLY_Q

public static final java.lang.String DEFAULT_REPLY_Q
Default name for a reply queue.

See Also:
Constant Field Values

DEFAULT_REGISTRATION_Q

public static final java.lang.String DEFAULT_REGISTRATION_Q
Default name for the registration queue.

See Also:
Constant Field Values

DEFAULT_REGISTRATION_REPLY_Q

public static final java.lang.String DEFAULT_REGISTRATION_REPLY_Q
Default name for the registration reply queue.

See Also:
Constant Field Values

DEFAULT_HOMESERVER_Q

public static final java.lang.String DEFAULT_HOMESERVER_Q
Default name for a home server queue.

See Also:
Constant Field Values

DEFAULT_RULES

public static final java.lang.String DEFAULT_RULES
Default rules file to use.

See Also:
Constant Field Values
Constructor Detail

AppModel

public AppModel()
Method Detail

run

public void run()
Starts the model running (initialize should have been run first). This involves monitoring all local queues.

Specified by:
run in interface java.lang.Runnable
Returns:
void

start

public void start(AppController controller,
                  java.lang.String localQMname)
           throws java.lang.Exception
Initializes the model and all necessary components. Needs to be given the name of the queue manager to initialize.

Parameters:
controller - The model's controller
localQMname - The name for local queue manager
Returns:
void
java.lang.Exception

initialConfiguration

protected void initialConfiguration()
                             throws java.lang.Exception
Called if the queue manager has not been started up previously. This will create all the necessary queues, connections, listeners etc for the queue manager to function. This will be saved in the registry for the next time the queue manager is started.

Returns:
void
java.lang.Exception

createListener

protected void createListener()
                       throws java.lang.Exception
Generates a name for the listener from the queue manager and creates it. This is done by taking the name of the queue manager and attaching '_Listener' to the end.

Returns:
void
java.lang.Exception

chooseConnections

protected java.lang.String[] chooseConnections()
Return a list of connections used by the model.


chooseLocalQueues

protected java.lang.String[] chooseLocalQueues()
Return a list of local queues used by the model.


chooseRemoteQueues

protected java.lang.String[] chooseRemoteQueues()
Return a list of remote queues used by the model.


initializeConnections

protected void initializeConnections()
                              throws java.lang.Exception
This creates all the connections specified in connections[].

Returns:
void
java.lang.Exception

initializeLocalQueues

protected void initializeLocalQueues()
                              throws java.lang.Exception
This creates all the local queues specified in localQueues[].

Returns:
void
java.lang.Exception

initializeRemoteQueues

protected void initializeRemoteQueues()
                               throws java.lang.Exception
This creates all the remote queues specified in remoteQueues[].

Returns:
void
java.lang.Exception

monitorLocalQueues

protected void monitorLocalQueues()
                           throws java.lang.Exception
Will start monitoring of all local queues as specified in localQueues[].

Returns:
void
java.lang.Exception

clearLocalQueues

protected void clearLocalQueues()
Clears all local queues as defined by localQueues[].

Returns:
void

processStatus

public void processStatus(java.lang.String msg)
Displays a message using the controller or if no controller is set, prints it to System.out.

Specified by:
processStatus in interface MessageConsumer
Parameters:
msg - The message to be displayed
Returns:
void

registerWithCentral

public void registerWithCentral(java.lang.String QMname,
                                java.lang.String Qname)
                         throws java.lang.Exception
Used to register a queue manager with the registration server. Not necessarily only clients that will want to register with reg server so this is located in the base abstract model rather than the client.

Registering involves simply sending a message to the registration server and waiting for a reply. The reply will contain a success bool indicating whether the registration was a success or not.

Parameters:
QMname - The name of the queue manager
Qname - The name of the queue
Returns:
void
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Stops the model and clears any local queues of messages befor closing the message service.

Returns:
void
java.lang.Exception

getLocalQMname

public java.lang.String getLocalQMname()
Gets the localQMname.

Returns:
String - name of the local queue manager

setLocalQMname

public void setLocalQMname(java.lang.String localQMname)
Sets the localQMname.

Parameters:
localQMname - The localQMname to set
Returns:
void

getMsgService

public MQeMessageService getMsgService()
Gets the msgService.

Returns:
MQeMessageService - the message service

setMsgService

public void setMsgService(MQeMessageService msgService)
Sets the msgService.

Parameters:
msgService - The msgService to set
Returns:
void

getController

public AppController getController()
Gets the controller.

Returns:
AppController - the controller

sendNewMessage

public void sendNewMessage(java.lang.String message)
                    throws java.lang.Exception
Sends a message to the default queue on the default queue manager.

Parameters:
message - The message to send
Returns:
void
java.lang.Exception

statusReport

protected java.lang.String statusReport()
Produces a status report for the queue manager. This lists The type of the model (client/server), the queues and connections and listener port.

Returns:
String - the status report

isServer

protected abstract boolean isServer()
Used to check whether the model is a client or server. This determines whether a listener should be created and whether the model should register with the central server.

This design has problem with expandability if, in the future, a server that registers with the central server is required.

Returns:
boolean - true if server, false if client

initializeOtherQueues

protected abstract void initializeOtherQueues()
                                       throws java.lang.Exception
This creates all less common queues that a queue manager may need ( home server queues, store and forward queues etc).

Returns:
void
java.lang.Exception

getListenerPort

protected abstract int getListenerPort()
Returns the port that the queue manager listens on. (unimportant to clients, as they don't have listeners).

Returns:
int - port to listen on

Websphere MQ Everyplace