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());
}
}