TableListener-class {Proc4}R Documentation

Class "TableListener"

Description

A listener that captures data from a P4Message and puts it into a dataframe.

Details

This listener builds up a data frame with selected data from the messages. What data is captured is controlled by the fieldlist object. This is a named character vector whose names correspond to field names and whose values correspond to type names (see typeof. The type can also be one of the two special types, ordered or factor. The following is a summary of the most common types:

"numeric", "logical", "integer", "double":

These are numeric values.

"character":

These are character values. They are not converted to factors (see factor types below).

"list","raw", other values returned by typeof:

These are usuable, but should be used with caution because the output data frame may not be easy to export to other program.

"ordered(...)", "factor(...)":

These produce objects of type ordered and factor with the comma separated values between the parenthesis passed as the levels argument. For example, "ordered(Low,Medium,High)" will produces an ordered factor with three levels. (Note that levels should be in increasing order for ordered factors, but this doesn't matter for unordered factors.)

For most fields, the field name is matched to the corresponding element of the details of the messages. The exceptions are the names app, context, uid, mess, sender, timestamp, which return the value of the corresponding header fields of the message. Note that

Extends

This class implements the Listener interface.

All reference classes extend and inherit methods from "envRefClass".

Methods

isListener

signature(x = "TableListener"): TRUE

receiveMessage

signature(x = "TableListener"): If the message is in the messSet, it adds a row to its internal table using the fields specified in fieldlist. (See details.)

Fields

name:

Object of class character naming the listener.

fieldlist:

A named character vector giving the names and types of the columns of the output matrix. See details.

df:

Object of class data.frame this is the output data frame. Note that the first line is blank line. Use the function $returnDF() to get the valid rows.

messSet:

A vector of class character giving the name of messages which are sent to the database. Only messages for which mess(mess) is an element of messSet will be added to the table..

Class-Based Methods

receiveMessage(mess):

Processes the message argument.

initDF():

An internal function that sets up the first row of the table as a blank line of the proper types. Called by receiveMessage().

initialize(name, fieldlist, messSet, ...):

Initializes the fields.

returnDF():

Returns the part of the df which has data (e.g., omits first line which is used to set the types.)

Author(s)

Russell Almond, Lukas Liu, Nan Wang

References

This is an example of the observer design pattern. https://en.wikipedia.org/wiki/Observer_pattern.

See Also

Listener, P4Message, UpdateListener, InjectionListener, CaptureListener, UpsertListener, TableListener,

Examples



mess1 <- P4Message(app="default",uid="Phred",context="Down Hill",
                   sender="EIEvent",mess="New Observables",
                   details=list(trophy="gold",solvedtime=10))
tabMaker <- TableListener(name="Trophy Table",
                   messSet="New Observables",
                   fieldlist=c(uid="character", context="character",
                               timestamp="character",
                               solvedtime="numeric",
                               trophy="ordered(none,silver,gold)"))

receiveMessage(tabMaker,mess1)
tabMaker$returnDF()


[Package Proc4 version 0.4-6 Index]