Controlling Queues with RedwoodScript
When you have a lot of repetitive tasks to perform, it is often easier to use script. RedwoodScript allows you to control queues, and you can hold all queues, regardless of the total number, with a few lines of code. The following examples illustrate how you can use RedwoodScript to control queues. Redwood Software does not warrant that this is the most effective way to solve your problem. For more information on RedwoodScript, see the API documentation.
Example
Holding a queue
{
// get the queue GLOBAL.TR2_Queue
queue = jcsSession.getQueueByName("TR2_Queue");
// check to see if the queue is open
if (queue.isOpen())
{
//hold the queue
queue.hold();
jcsSession.persist();
}
}
Changing the State of a Queue
This is an example of how you can retrieve the status of a queue.
{
//get the queue RW_DEMO.TR2_Queue
Partition part = jcsSession.getPartitionByName("RW_DEMO");
Queue queue = jcsSession.getQueueByName(part, "TR2_Queue");
//check if the queue is open
if (queue.isOpen())
{
//queue is open
queue.hold();
jcsSession.persist();
}
else
{
//queue is held
queue.release();
jcsSession.persist();
}
}
Holding all Queues
You can hold all queues, except system queue. Retrieve the queues using executeObjectQuery.
{
String query = "select Queue.* from Queue where Name <> 'System'";
for (Queue queue : jcsSession.executeObjectQuery(Queue.TYPE, query))
{
if(queue.isOpen())
{
jcsOut.println("Holding queue " + queue.getName() + ", which has the status " + queue.getStatus() + ".");
queue.hold();
jcsSession.persist();
}
}
}
Adding a Process Server to a Queue
{
Queue queue = jcsSession.getQueueByName("TR1_Queue");
ProcessServer proc = jcsSession.getProcessServerByName("TR2_ProcessServer");
queue.createQueueProvider(proc);
jcsSession.persist();
}
List all Process Servers Serving a Queue
A queue provider is the link between a process server and a queue, to find all the process servers serving a queue, we need to list the queue providers.
{
Partition p = jcsSession.getPartitionByName("MyPart");
Queue queue = jcsSession.getQueueByName(p, "My_Queue");
for (QueueProvider provider : queue.getQueueProviders())
{
jcsOut.println(provider.getProcessServer().getName());
}
}
See Also
- RedwoodScript
- Creating a Queue
- Using Queues to Administer Process Execution
- Using Resources to distribute the load
- Privileges Required to use Queues
Redwood Script