resetListeners: Clears messages caches associated with listeners

resetListenersR Documentation

Clears messages caches associated with listeners

Description

Listeners often cache the messages in some way. This causes the message cache to be cleared, and operation which is often useful before a rerun. The which argument is used to control which listeners should have their cache cleared.

Usage

resetListeners(x, which, app)
## S4 method for signature 'ListenerSet'
resetListeners(x, which, app)
## S4 method for signature 'NULL'
resetListeners(x, which, app)

Arguments

x

A ListenerSet object containing the listeners to be reset.

which

A character vector containing the names of the listeners to reset. The special keyword “ALL” means all listeners will be reset. The special keyword “Self” means that the cache associated with the listener set will be reset.

app

A global applicaiton identifier. The reset operation should only be applied to messages from this application.

Details

Each Listener object (including the listener set) has a $reset() method which empties the cache of messages. This method calls the $reset() method for each of the listeners named in which. The special keyword “ALL” is used to reset all listeners and the special keyword “Self” is used to refer to the ListenerSet object itself (which may have a database colleciton).

Value

The ListenerSet object is returned.

Author(s)

Russell Almond

See Also

ListenerSet, Listener

Examples


## Not run: ## Requires Mongo database set up.

data2json <- function(dat) {
  toJSON(sapply(dat,unboxer))
}

listeners <- list(
  cl = CaptureListener(name="cl"),
  upd = UpdateListener(name="upd",messSet="New Observables",
                         dburi="mongodb://localhost",dbname="test",
                         targetField="data",jsonEncode="data2json",
                         colname="Updated"),
  ups = UpsertListener(name="ups",sender="EIEvent",messSet="New Observables",
                         dburi="mongodb://localhost",dbname="test",
                         colname="Upserted", qfields=c("app","uid")),
  il = InjectionListener(name="il",sender="EIEvent",messSet="New Observables",
                         dburi="mongodb://localhost",dbname="test",
                         colname="Injected"),
  tl = TableListener(name="tl",
                   messSet="New Observables",
                   fieldlist=c(uid="character", context="character",
                               timestamp="character",
                               solvedtime="numeric",
                               trophy="ordered(none,silver,gold)"))
  )
  
lset <- ListenerSet$new(sender="Other",dburi="mongodb://localhost",
                colname="messages",dbname="test",listeners=listeners)

mess1 <- P4Message(app="default",uid="Phred",context="Down Hill",
                   sender="EIEvent",mess="New Observables",
                   details=list(trophy="gold",solvedtime=10))

resetListeners(lset,"ALL","default")
receiveMessage(lset,mess1)
## Check recieved messages.
stopifnot(lset$messdb()$count(buildJQuery(app="default"))==1L,
          length(listeners$cl$messages)==1L,
          listeners$upd$messdb()$count(buildJQuery(app="default"))==1L,
          listeners$ups$messdb()$count(buildJQuery(app="default"))==1L,
          listeners$il$messdb()$count(buildJQuery(app="default"))==1L,
          nrow(listeners$tl$returnDF())==1L)

resetListeners(lset,c("Self","cl","il","tl"),"default")
stopifnot(lset$messdb()$count(buildJQuery(app="default"))==0L,
          length(listeners$cl$messages)==0L,
          listeners$upd$messdb()$count(buildJQuery(app="default"))==1L,
          listeners$ups$messdb()$count(buildJQuery(app="default"))==1L,
          listeners$il$messdb()$count(buildJQuery(app="default"))==0L,
          nrow(listeners$tl$returnDF())==0L)

resetListeners(lset,"ALL","default")
stopifnot(lset$messdb()$count(buildJQuery(app="default"))==0L,
          length(listeners$cl$messages)==0L,
          listeners$upd$messdb()$count(buildJQuery(app="default"))==0L,
          listeners$ups$messdb()$count(buildJQuery(app="default"))==0L,
          listeners$il$messdb()$count(buildJQuery(app="default"))==0L,
          nrow(listeners$tl$returnDF())==0L)



## End(Not run)

ralmond/Proc4 documentation built on June 13, 2025, 7:13 a.m.