|
Websphere MQ Everyplace | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.mqe.MQe | +--com.ibm.mqe.MQeRule | +--com.ibm.mqe.MQeQueueManagerRule
This class contains methods that are invoked when the queue manager performs certain operations. The rules can affect the outcome of these operations. This class contains the default queue manager rules. Typically, these default rules would be overridden to provide appropriate behavior for a given WebSphere MQ Everyplace solution.
Note:Any unexpected exception thrown from a user's rule method (for instance, a null pointer exception) will result in the default behaviour being applied as though the rule invocation had never occurred.
Field Summary |
Constructor Summary | |
MQeQueueManagerRule()
|
Method Summary | |
boolean |
activateQueues()
This rule decides whether to activate certain queues at queue manager startup time. |
boolean |
addQueue(MQeQueueProxy Queue)
This rule is called when a new queue is added to the queue manager. |
void |
deleteMessage(java.lang.String destQMgr,
java.lang.String destQ,
MQeFields filter)
This rule is called when a delete message operation occurs. |
void |
getMessage(java.lang.String destQMgr,
java.lang.String destQ,
MQeFields filter,
MQeAttribute attribute,
long confirmID)
This rule is called when a get message operation occurs. |
int |
getRetryCount()
Deprecated. This method is no longer used. |
void |
peerConnection(java.lang.String qmgrName)
Deprecated. This method is no longer called, as peer channels are not supported in version 2 of MQe |
void |
putMessage(java.lang.String destQMgr,
java.lang.String destQ,
MQeMsgObject msg,
MQeAttribute attribute,
long confirmID)
This rule is called when a put message operation occurs. |
void |
queueManagerActivate()
This rule is called when the queue manager is activated. |
void |
queueManagerClose()
This rule is called when the queue manager is closed. |
void |
removeQueue(MQeQueueProxy Queue)
This rule is called when a queue is to be removed from the queue manager. |
boolean |
transmit(MQeQueueProxy queue)
This rule is called for each remote asynchronous queue definition when a transmission of pending messages is taking place. |
boolean |
triggerTransmission(int triggerCount,
MQeFields msg)
This rule returns a boolean value which denotes whether or not to allow, at this time, the triggering of communications (where communications includes both the transmission of pending messages from remote asynchronous queue definitions and the stimulation of the Home Server Queue into polling its Store-and-Forward Queue). |
void |
undo(java.lang.String destQMgr,
java.lang.String destQ,
long confirmID)
This rule is called when an undo operation occurs. |
Methods inherited from class com.ibm.mqe.MQeRule |
activate, close, newRule |
Methods inherited from class com.ibm.mqe.MQe |
abbreviate, alias, asciiToByte, byteToAscii, byteToHex, byteToHex, byteToInt, byteToLong, byteToShort, byteToUnicode, fileSeparator, getEventLogHandler, hexToAscii, hexToByte, intToByte, isCLDC, loadClass, loadObject, log, setEventLogHandler, setLoader, sliceByteArray, type, unicodeToByte, uniqueValue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MQeQueueManagerRule()
Method Detail |
public void queueManagerActivate() throws java.lang.Exception
This rule is called when the queue manager is activated.
java.lang.Exception
- Note : This exception is retained for backward compatibility only and any exception thrown in this method will be caught and ignored.
// Called when the Queue manager is activated public void queueManagerActivate()throws Exception { super.queueManagerActivate(); // background thread which triggers transmission th = new Thread(this, "TriggerThread"); toldToStop = false; th.start(); // start timer thread } // Background thread run method. // Triggers transmission every interval until thread is stopped. public void run() { // Do a sleep-trigger-sleep-trigger loop until the queue manager closes or we get // an exception. while (!toldToStop) { try { // Count down until we've waited enough // We do a tight loop with a smaller granularity because // otherwise we would stop a queue manager from closing quickly long timeToWait = MILLISECS_BETWEEN_TRIGGER_TRANSMITS; while (timeToWait > 0 && !toldToStop) { // sleep for specified interval Thread.sleep(MILLISECS_BETWEEN_CLOSE_CHECKS); // We've waited for some time. Account for this in the overall wait. timeToWait -= MILLISECS_BETWEEN_CLOSE_CHECKS; } if (!toldToStop) { // trigger transmission on QMgr (which is rule owner) ((MQeQueueManager) owner).triggerTransmission(); } } catch (Exception e) { e.printStackTrace(); } } }
public void queueManagerClose() throws java.lang.Exception
This rule is called when the queue manager is closed.
java.lang.Exception
- Note : This exception is retained for backward compatibility only and any exception thrown in this method will be caught and ignored.
queueManagerActivate()
// Called when a Queue manager Close is called public void queueManagerClose()throws Exception { super.queueManagerClose(); // Tell the background thread to stop, as the queue manager is closing now. toldToStop = true; // Now wait for the background thread, if it's not already stopped. if (th != null) { try { // Only wait for a certain time before giving up and timing out. th.join(MAX_WAIT_FOR_BACKGROUND_THREAD_MILLISECONDS); // Free up the thread control block for garbage collection. th = null; } catch (InterruptedException e) {// Don't propogate the exception. // Assume that the thread will stop shortly anyway. } } }
public boolean addQueue(MQeQueueProxy Queue) throws java.lang.Exception
This rule is called when a new queue is added to the queue manager.
The rule is called before the addition of the queue, and so the rule is able to reject the operation by throwing an exception.
This rule also decides whether to activate the queue immediately or to activate the queue when it is first used. The default behaviour of the rule is to activate all home-server queues immediately. All other types of queue are activated when they are first used.
Queue
- An MQeQueueProxy
object that is being added to
the queue manager.
true - Activate the queue immediately. false - Activate the queue when first used.
java.lang.Exception
removeQueue(com.ibm.mqe.MQeQueueProxy)
// Don't allow asynchronous queues to be added to this Queue Manager public boolean addQueue(MQeQueueProxy queue) throws Exception { boolean result = super.addQueue(queue); if (queue.isRemoteQueue() && !queue.isSynchronous()) { result = false; } return (result); }
public void removeQueue(MQeQueueProxy Queue) throws java.lang.Exception
This rule is called when a queue is to be removed from the queue manager.
The rule is called before the removal of the queue, so the rule is able to reject the operation by throwing an exception.
Queue
- An MQeQueueProxy
object that is to be removed
from the queue manager.
java.lang.Exception
addQueue(com.ibm.mqe.MQeQueueProxy)
// This rule prevents the removal of the Payroll Queue public void removeQueue(MQeQueueProxy queue) throws Exception { if (queue.getQueueName().equals("PayrollQueue")) { throw new MQeException(Except_Rule, "Can't delete this queue"); } }
public void deleteMessage(java.lang.String destQMgr, java.lang.String destQ, MQeFields filter) throws java.lang.Exception
This rule is called when a delete message operation occurs.
The rule is called before the operation takes place, and so the rule can stop the operation by throwing an exception.
destQMgr
- A String containing the name of the queue manager that
owns the queue on which this operation takes place. A value of null denotes
that the local queue manager is to be used.destQ
- A String containing the name of the queue on which this
operation takes place.filter
- This is the filter to be used for the delete message operation.
It is an MQeFields
object containing message fields
(for example, priority and message ID ).
java.lang.Exception
// This rule blocks message deletes on 'TopSecretQueue' public void deleteMessage(String destQMgr, String destQ, MQeFields filter) throws Exception { super.deleteMessage(destQMgr, destQ, filter); if (destQMgr == null || destQMgr.equals(((MQeQueueManager) owner).getName())) { if (destQ.equals("TopSecretQueue")) { throw new MQeException(Except_Rule, "Can't delete on this Queue"); } } }
public void getMessage(java.lang.String destQMgr, java.lang.String destQ, MQeFields filter, MQeAttribute attribute, long confirmID) throws java.lang.Exception
This rule is called when a get message operation occurs.
The rule is called before the operation takes place, and so the rule can stop the operation by throwing an exception.
destQMgr
- A String containing the name of the queue manager that
owns the queue on which this operation takes place. A value of null denotes
that the local queue manager is to be used.destQ
- A String containing the name of the queue on which this
operation takes place.filter
- This is the filter to be used for the get message operation.
It is an MQeFields
object containing message fields.
(for example, priority and message ID )attribute
- An MQe Attribute object used to provide message-level
security.confirmID
- A long value denoting whether or not to use guaranteed
message delivery. A nonzero value leaves the message locked on the target
queue, it is not removed until a subsequent confirm flow. A value of zero
removes the message from the target queue without the need for a subsequent
confirm.
This value is also used in the event of a get message failure. The application should store the value, and use it to reset the messages that matched the get to their previous state (via the undo() command).
java.lang.Exception
putMessage(java.lang.String, java.lang.String, com.ibm.mqe.MQeMsgObject, com.ibm.mqe.MQeAttribute, long)
//This rule only allows GETs from 'OutboundQueue',if a password is //supplied as part of the filter public void getMessage(String destQMgr, String destQ, MQeFields filter, MQeAttribute attr, long confirmId) throws Exception { super.getMessage(destQMgr, destQ, filter, attr, confirmId); if ((destQMgr.equals(((MQeQueueManager) owner).getName()) && (destQ.equals("OutboundQueue")))) { if (!(filter.contains("Password"))) { throw new MQeException(Except_Rule, "Password not supplied"); } else { String pwd = filter.getAscii("Password"); if (!(pwd.equals("1234"))) { throw new MQeException(Except_Rule, "Incorrect password"); } } } }
public void putMessage(java.lang.String destQMgr, java.lang.String destQ, MQeMsgObject msg, MQeAttribute attribute, long confirmID) throws java.lang.Exception
This rule is called when a put message operation occurs.
The rule is called before the operation takes place, so the rule can stop the operation by throwing an exception.
destQMgr
- A String containing the name of the queue manager that
owns the queue on which this operation takes place. A value of null denotes
that the local queue manager is to be used.destQ
- A String containing the name of the queue on which this
operation takes place.msg
- The message object that is being placed on the target queue.attribute
- null , or an MQeAttribute object defining the authenticator,
cryptor, and compressor to be associated with this message.confirmID
- A long value denoting whether or not to use assures
message delivery. A nonzero value locks the message on the target queue, it
is not made visible until a subsequent confirm flow. A value of zero transmits
the message without the need for a subsequent confirm.
Also, this value can be used in the event of a put message failure. By passing this value to the undo command, the application can remove any messages that were left in an incomplete state by the failed put operation.
java.lang.Exception
getMessage(java.lang.String, java.lang.String, com.ibm.mqe.MQeFields, com.ibm.mqe.MQeAttribute, long)
// Only allow msgs containing an ID field to be placed on the Queue public void putMessage(String destQMgr, String destQ, MQeMsgObject msg, MQeAttribute attribute, long confirmId) throws Exception { if (!(msg.contains(MQe.Msg_MsgID))) { throw new MQeException(Except_Rule, "Msg must contain an ID"); } }
public void undo(java.lang.String destQMgr, java.lang.String destQ, long confirmID) throws java.lang.Exception
This rule is called when an undo operation occurs.
The rule is called to inform the rule that the operation is taking place.
destQMgr
- A String containing the name of the queue manager that
owns the queue on which this operation takes place. A value of null denotes
that the local queue manager is to be used.destQ
- A String containing the name of the queue on which this
operation takes place.confirmID
- A long value that was the confirmID used by the operation
which is being undone. All messages matching this confirmID are restored to
their previous state.
java.lang.Exception
public void undo(String destQMgr, String destQ, long confirmId) { // log the undo event System.out.println("Undo operation performed on queuemanager " + destQMgr + ", queue " + destQ); }
public boolean triggerTransmission(int triggerCount, MQeFields msg)
This rule returns a boolean value which denotes whether or not to allow, at this time, the triggering of communications (where communications includes both the transmission of pending messages from remote asynchronous queue definitions and the stimulation of the Home Server Queue into polling its Store-and-Forward Queue).
This rule is invoked by the queue manager in two situations :
triggerCount
- The number of messages awaiting transmission on remote asynchronous queues.msg
- This parameter is always null, it is retained for backward compatibility.
None
transmit(com.ibm.mqe.MQeQueueProxy)
// Decides if transmission of messages is allowed public boolean triggerTransmission(int noOfMsgs, MQeFields msgFields) { return true; // always allow transmission }
public final int getRetryCount()
This rule returns the number of retry attempts for a failed network operation.
The queue manager calls this rule when creating a new channel object. The value returned by this rule is passed to the channel, and it is used in the event of a network operation failure.
none
public boolean activateQueues()
This rule decides whether to activate certain queues at queue manager startup time. The queues that can be activated are remote asynchronous queue definitions, home-server queues, and store-and-forward queues.
Activating these queues means that an attempt is made to transmit any messages that they hold. The triggerTransmission() method of the MQeQueueManagerRules class is also consulted to check that an attempt to transmit is allowed. Queues are normally not activated until an operation is performed on them. It can be useful to activate these queues immediately on queue manager startup because they may have transmission timer threads, or other functions associated with them.
none
public boolean activateQueues() { if (timeToTransmit()) { // if in cheap transmission period return true; // then activate queues } else { // otherwise return false; // don't activate queues } } private boolean timeToTransmit() { Calendar calendar = Calendar.getInstance(); int currentHour = calendar.get(calendar.HOUR_OF_DAY); if (currentHour >= 18 || currentHour < 9) { return true; } else { return false; } }
public boolean transmit(MQeQueueProxy queue)
This rule is called for each remote asynchronous queue definition when a transmission of pending messages is taking place. The rule allows transmission to be disabled on a per-queue basis.
When a queue manager attempts to send all its pending messages, this rule is called for each queue that contains messages awaiting transmission. This rule decides whether to allow the transmission of those messages for the supplied queue.
queue
- A MQeQueueProxy
object that holds messages awaiting
transmission.
none
triggerTransmission(int, com.ibm.mqe.MQeFields)
// This rule allows queue transmission if current time is during the // cheap rate transmission period // If the current time is not during the cheap rate transmission period // then transmission is only allowed if the queue is high priority public boolean transmit(MQeQueueProxy queue) { // timeToTransmit() provides a time suitable for transmission at the // cheap rate hours. boolean ToTransmit = true; try { if (!timeToTransmit()) { // not in cheap rate period if (queue.getDefaultPriority() <= 4) { ToTransmit = false; } } } catch (Exception e) {} return ToTransmit; }
public void peerConnection(java.lang.String qmgrName)
This rule is called when the queue manager’s peer channel listener receives an incoming connection request.
This method is called when a queue manager’s peer listener detects an incoming connection request from another WebSphere MQ Everyplace queue manager. The connection must be made over an MQePeerChannel, or its descendant.
qmgrName
- A String containing the name of the WebSphere MQ Everyplace
queue manager that is requesting a connection.
none
public void peerConnection(String qmgrName) { // block any connection attempt from 'RogueQMgr' if (qmgrName.equals("RogueQMgr")) { System.out.println("Connection on this QMgr not allowed"); } }
|
Websphere MQ Everyplace | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |