sunlabs.brazil.template
Class QueueTemplate

java.lang.Object
  |
  +--sunlabs.brazil.template.Template
        |
        +--sunlabs.brazil.template.QueueTemplate
All Implemented Interfaces:
TemplateInterface

public class QueueTemplate
extends Template

Template class for Managing simple Queues, allowing text communication among sessions. The "name" attribute names the Q. When enqueueing messages, "name" is a white space separated list of queue recipients. When Dequeueing Messages, "name" is the recipient Queue.

The following tags are recognized.


Nested Class Summary
static class QueueTemplate.Queue
          Create an object queue.
static class QueueTemplate.QueueItem
          A bag of items to keep on the Q.
 
Field Summary
static String Q_ID
           
 
Fields inherited from class sunlabs.brazil.template.Template
debug
 
Constructor Summary
QueueTemplate()
           
 
Method Summary
static QueueTemplate.QueueItem dequeue(String name, int timelimit)
          Program access to the Q.
static boolean enqueue(String to, String from, String message, String meta, boolean noCreate, boolean force)
          Allow another data to be enqueued from java code.
static QueueTemplate.Queue getQ(String name)
          Return a Q
 void tag_dequeue(RewriteContext hr)
          Remove an item from the queue, and generate the appropriate properties.
 void tag_enqueue(RewriteContext hr)
          Add a text message onto a named queue.
 void tag_queueinfo(RewriteContext hr)
          Return info about the Q, and optionally clear it.
 
Methods inherited from class sunlabs.brazil.template.Template
done, init
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Q_ID

public static final String Q_ID
See Also:
Constant Field Values
Constructor Detail

QueueTemplate

public QueueTemplate()
Method Detail

tag_enqueue

public void tag_enqueue(RewriteContext hr)
Add a text message onto a named queue. Attributes:
- name: the name of the queue (required)
- from: the sender name
- message: the text message
- meta: application specific meta-data
- nocreate: If set, The item will not be Queued if the Q for that recipient does not already exist.
- force: put to the queue even if its closed

The property "count" contains the number of recipients for which the message was successfully Queued. The property "error.name" will contain an error message if Queueing failed. In both cases, the template prefix will be prepended. It is not considered an error condition for a message not to be delivered to a non existent Queue if "nocreate" is set.


enqueue

public static boolean enqueue(String to,
                              String from,
                              String message,
                              String meta,
                              boolean noCreate,
                              boolean force)
Allow another data to be enqueued from java code.

Returns:
True, if the data was enqueued

tag_dequeue

public void tag_dequeue(RewriteContext hr)
Remove an item from the queue, and generate the appropriate properties. Attributes:
name
The name of the queue to examine
prepend
The prefix in the properties table to use to set the results. Defaults to our prefix.
timelimit
how long to wait for an item to appear, in sec. Defaults to 30.
If an item is retrieved, the following request properties are set (preceded by prepend):
message
Set The text of the next message in the queue.
age
Set how long the message has been q's (in seconds)
sent
Set the timestamp (in sec) of when the item was q'd.
items
Set the number of Q'd items.
from
Set the (unauthenticated) sender.
error
Something went wrong. Set an error message.
Note: this tag blocks until an item is received in the Queue (or a timelimit expires). As template processing is synchronized based on sessions, care should be taken to avoid blocking other (unrelated) session based requests while waiting on the queue.


dequeue

public static QueueTemplate.QueueItem dequeue(String name,
                                              int timelimit)
Program access to the Q.

Returns:
The Queue item, or Null if no item is available.

tag_queueinfo

public void tag_queueinfo(RewriteContext hr)
Return info about the Q, and optionally clear it. Attributes:
name
The name of the queue to examine
prepend
The prefix in the properties table to use to set the results. Defaults to our prefix.
clear
If set, then clear the queue
remove
If set, then remove the queue
closed=[true|false]
set the closed state of the Q
The following request properties are set (preceded by prepend):
lastIn
The timestamp (ms) of the last Q insert attempt.
lastOut
The timestamp (ms) of the last Q retrieval attempt.
size
The number of items in the Q.
count
The number of items inserted into the Q


getQ

public static QueueTemplate.Queue getQ(String name)
Return a Q


Version 2.1, Generated 12/30/04
Copyright (c) 2001-2004, Sun Microsystems.