buildListener | R Documentation |
This is used in configuration, it will build a listener from a JSON description of the listener. The “name” and “type” fields are required. The other fields should match the arguments for the constructor, with the exceptions noted below:
buildListener(specs, app, dburi, defaultDB="Proc4",
ssl_options=mongolite::ssl_options(),
noMongo = !missing(dburi) && length(dburi) > 0L && nchar(dburi) > 0L)
specs |
A named list (from the JSON) containing the instructions for building the listener. |
app |
A character value that will get substituted for the string “<app>” in the “name” and “sender” fields. |
dburi |
If a database is used for this listener, then this is the uri for the connection. Note that this is specified in the code and not in the JSON. |
defaultDB |
The name of the database with which the Listener will interact,
only used if no |
ssl_options |
Options used for an SSL connection to the database.
|
noMongo |
A logical value. If true, then the connection to the Mongo database will not be made, and CRUD operations will basically become no-ops. |
The input to this function is a list that comes from JSON (or some
other input method that returns a named list). The specs$type
field should be the name of a Listener
class. This
means that specs$type
is the name of a constructor function,
and the rest of the spec
argument are the arguments.
Currently, the following fields are used.
The name of the listener, required. The string
“<app>” is substituted for app
.
Required, the name of the constructor for the desired class. The function will generate an error if this does not correspond to the name of a class.
A string insterted into logged messages. The string
“<app>” is substituted for app
.
The name of the database in which the messages will be
recorded. If not present, then the defaultdb
will be used.
The name of the database collection in which the messages will be recorded.
A character vector giving the names of the messages the listener will pay attention to. Note that this maps to the field “messSet” in the listener object.
Used in the UpdateListener
and UpsertListener
to indicate the field to be
modified.
The name of a function used to encode the field
value to be modified as JSON. See stats2json
.
A character vector giving the names of the fields
used as the key for finding the message to replace. Usually
should contain c("uid","app")
.
This should be a named character vector (or list)
whose names indicate the names of the observables/statistics to
collect, and whose values are the types. See
TableListener
; this field maps to the
“fieldlist” field of that class.
Other fields in specs
are ignored.
An object of the virtual class Listener
(i.e., something
for which isListener
should return true.
The field name “messages” maps to the internal field
messSet
. The field name “fields” maps to the internal
field fieldlist
.
Russell Almond
Listener
, fromJSON
jspecs <- '[
{
"name":"ppLS<app>",
"type":"TableListener",
"messages":["Coins Earned","Coins Spent", "LS Watched"],
"fields":{
"uid":"character",
"context":"character",
"timestamp":"character",
"currentMoney":"numeric",
"appId":"numeric",
"mess":"character",
"money":"numeric",
"onWhat":"character",
"LS_duration":"difftime",
"learningSupportType":"character"
}
},
{
"name":"ToEA",
"type":"InjectionListener",
"dbname":"EARecords",
"colname":"EvidenceSets",
"messages":["New Observables"]
},
{
"name":"PPPersistantData",
"type":"UpdateListener",
"dbname":"Proc4",
"colname":"Players",
"targetField":"data",
"jsonEncoder":"trophy2json",
"messages":["Money Earned", "Money Spent"]
}
]'
speclist <- jsonlite::fromJSON(jspecs,FALSE)
l1 <- buildListener(speclist[[1]],"test",mongo::makeDBuri())
l2 <- buildListener(speclist[[2]],"test",mongo::makeDBuri())
l3 <- buildListener(speclist[[3]],"test",mongo::makeDBuri())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.