ListenerConstructors {Proc4}R Documentation

Constructors for Listener Classes

Description

These functions create objects of class CaptureListener, UpdateListener, UpsertListener, InjectionListener, and TableListener.

Usage

CaptureListener(messages = list(), ...) 
InjectionListener(sender = "sender", dbname = "test",
    dburi = "mongodb://localhost", 
    messSet = character(), colname = "Messages", ...)
UpdateListener(dbname = "test", dburi = "mongodb://localhost",
    messSet = character(), colname = "Messages", targetField = "data",
    qfields = c("app", "uid"), jsonEncoder = "unparseData", ...)
UpsertListener(sender = "sender", dbname = "test",
    dburi = "mongodb://localhost", 
    messSet = character(), colname = "Messages",
    qfields = c("app", "uid"), ...)
TableListener(name = "ppData",
    fieldlist = c(uid = "character", context = "character"), 
    messSet = character(), ...)

Arguments

messages

A list into which to add the messages.

sender

A character value used as the sender field of the message.

dbname

A character value giving the name of the database in which to put the message. See mongo.

dburi

A character vector giving the URI for the database. See mongo.

messSet

A character vector giving the message values of the messages that will be processed. Messages whose mess value are not in this list will be ignored by this listener.

colname

The name of the database column into which the messages will be sent. See mongo.

targetField

The name of the field that will be modified in the database by the UpdateListener.

jsonEncoder

A function that will be used to encode the data object as JSON before it is set. See UpdateListener.

qfields

The fields that will be used as a key when trying to find matching messages in the database for the UpsertListener.

name

An 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 TableListener.

...

Other arguments passed to the constructor.

Details

The functions are as follows:

CaptureListener

Creates an object of class CaptureListener which stores the messages in a list.

InjectionListener

Creates an object of class InjectionListener which inserts the message into the designated database.

UpdateListener

Creates an object of class UpdateListener which updates the designated field.

UpsertListener

Creates an object of class UpsertListener which insert or replaces the message in the designated collection.

TableListener

Creates an object of class TableListener which adds details from message to rows of a data frame.

See the class descriptions for more information.

Value

An object of the virtual class Listener.

Author(s)

Russell Almond

References

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

See Also

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

Examples


cl <- CaptureListener()

il <- InjectionListener(sender="EI_app",
            dbname="EARecords",dburi="mongodb://localhost",
            colname="EvidenceSets",messSet="New Observables")

upsl <- UpsertListener(sender="EI_app",
            dbname="EARecords",dburi="mongodb://localhost",
            colname="LatestEvidence",messSet="New Observables",
            qfields=c("app","uid"))

trophy2json <- function(dat) {
  paste('{', '"trophyHall"', ':','[',
        paste(
            paste('{"',names(dat$trophyHall),'":"',dat$trophyHall,'"}',
                  sep=""), collapse=", "), '],',
        '"bankBalance"', ':', dat$bankBalance, '}')
}
ul <- UpdateListener(dbname="Proc4",dburi="mongodb://localhost",
            colname="Players",targetField="data",
            messSet=c("Money Earned","Money Spent"),
            jsonEncoder="trophy2json")

tabMaker <- TableListener(name="Trophy Table",
                   messSet="New Observables",
                   fieldlist=c(uid="character", context="character",
                               timestamp="character",
                               solvedtime="numeric",
                               trophy="ordered(none,silver,gold)"))


[Package Proc4 version 0.4-6 Index]