Controlling Queues with RedwoodScript

RedwoodScript lets you control Queues with a few lines of code.

Holding a Queue

Copy
{
  // 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.

Copy
{
  //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 the System Queue. This example retrieves Queues using executeObjectQuery.

Copy
{
  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 Job Server to a Queue

Copy
{
  Queue queue = jcsSession.getQueueByName("TR1_Queue");

  ProcessServer proc = jcsSession.getProcessServerByName("TR2_ProcessServer");

  queue.createQueueProvider(proc);

  jcsSession.persist();
}

List all Job Servers Serving a Queue

To find all the Job Servers serving a Queue, you must list the Queue Providers.

Copy
{
  Partition p = jcsSession.getPartitionByName("MyPart");
  Queue queue = jcsSession.getQueueByName(p, "My_Queue");
  for (QueueProvider provider : queue.getQueueProviders())
  {
    jcsOut.println(provider.getProcessServer().getName());
  }
}