ListenerSet-class | R Documentation |
"ListenerSet"
This is a “mix-in” class that adds a speaker protocol to an
object, which is complementary to the Listener
protocol. This object maintains a list of listeners. When the
notifyListeners
method is called, it notifies each of the
listeners by calling the receiveMessage
method on the
listener.
All reference classes extend and inherit methods from
"envRefClass"
. The class union
NullListenerSet
is either a ListenerSet
or NULL
.
signature(x = "ListenerSet")
: Returns true,
as the ListenerSet follows the listener protocol.
signature(x = "ListenerSet")
: A synonym
for notifyListeners
.
signature(sender = "ListenerSet")
: A synonym
for the notifyListeners
internal method.
The key to this class is the notifyListeners
method. This
method should receive as its argument a P4Message
object.
(The protocol is fairly robust to the type of message and the
type is not enforced. In fact, any object which has a
as.jlist
method should work.)
When the notifier is called it performs the following functions:
It saves the message to the collection represented by
messdb()
. If messdb()
is NULL
(dburi
is the empty string) then the messages is not saved.
It calls the receiveMessage
method on each of
the objects in the listener list.
It logs the messages sent using the
flog.logger
, in the "Proc4"
logger.
The sending of the messages is logged a the “INFO” level,
and the actual message at the “DEBUG” level.
In addition, the ListenerSet
maintains a named list of
Listener
objects (that is, objects that have a
receiveMessage
method). The methods addListener
and
removeListener
maintain this list.
sender
:Object of class character
:the name of
the source of the messages.
dburi
:Object of class character
: the URI for
the mongo
database. If null, then no
recording of messages to a database is done (except possibly in
the listeners).
dbname
:Object of class character
: the name of
the database in which messages should be logged.
colname
:Object of class character
: the name of
the collection in which messages should be logged.
listeners
:A named list
of
Listener
objects, that is objects for which
isListener
is true.
db
:Object of class MongoDB
which
is a handle
to the collection where messages are logged, or NULL
if the
log database has not been initialized. As the database may have
not been initialized, programs should call the messdb()
method which will open the database connection if it is not yet
open.
$notifyListeners(mess)
:This method calls
receiveMessage
on all of the listeners. See
Protocol section above.
$addListener(name, listener)
:This method addes a lsitener to the list.
$initialize(sender, dburi, listeners, colname, ...)
:This
creates the listener. Note, this does not initialize the database
collection. Call messdb()
to initialize the collection.
$removeListener(name)
:This removes a listener from the collection by its name.
$reset(app)
:Empties the database collection of messages with this app id.
signature()
: Returns the
mongo
database collection to which to log
messages. Creates the column if it has not been initialized.
signature()
: Returns the
mongo
database collection in which output files will be registered.
signature(name, filename, app, process,
type="data", doc="")
: Adds/updates a field in the database
collection of output files. This allows processes looking at the
database to find output summaries.
The notifyListeners
method uses the
flog.logger
protocol. In particular, it
logs sending the message at the “INFO” level, and the actual
message sent at the “DEBUG” level. In particular, setting
flog.threshold(DEBUG,name="Proc4")
will
turn on logging of the actual message and
flog.threshold(WARN,name="Proc4")
will
turn off logging of the message sent messages.
It is often useful to redirect the Proc4 logger to a log file. In
addition, changing the logging format to JSON, will allow the message
to be recovered. Thus, try
flog.layout(layout.json,name="Proc4"
to activate logging in JSON format.
Russell Almond
https://en.wikipedia.org/wiki/Observer_pattern
Listener
, receiveMessage
,
notifyListeners
,
flog.logger
,
mongo
, P4Message
Listener Classes.
CaptureListener
, UpdateListener
,
UpsertListener
, InjectionListener
,
TableListener
showClass("ListenerSet")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.