Ask Your Question
0

How do I write state in one evaluator and read it in another?

asked 2018-03-16 10:34:45 -0600

metadaddy gravatar image

I need to be able to set some state in one evaluator, and then retrieve it later in another. The state variable is scoped to the individual evaluator, so that doesn't work.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-03-16 10:52:54 -0600

metadaddy gravatar image

There are a couple of ways of doing this:

  1. You can write state to disk in one evaluator, and read it in another. This has the advantage of being persistent, and, if you write to the SDC_RESOURCES directory, you can easily read the state with ${runtime:loadResource(filename, false)}

  2. There's an "unofficial" global thread-safe map you can access via DataCollectorServices.instance().get("key") and DataCollectorServices.instance().put("key", value). To avoid conflicts with anything stored by the system I'd recommend using some kind of prefix for your keys. Note that this state is not persistent from between pipeline restarts. Note - this mechanism is NOT a public API. It's unsupported, and could cease to function from one version to the next. Use at your own risk!

edit flag offensive delete link more
1

answered 2018-03-19 09:11:22 -0600

bob gravatar image

updated 2018-03-19 09:15:04 -0600

A third suggestion would be to use a relational (or NoSQL) database to store the stage's state data. INSERT from the first stage, pass the information's key in a field in the record. SELECT from the other stage, optionally DELETE the record. This may be slightly more performant than option 1 - no file handling, and you can persist the connection by setting up the database connection in the Script's Init routine. Also, the data will be persistent through Data Collector restarts which will solve the problem @metadaddy mentions in option 2.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-16 10:34:45 -0600

Seen: 93 times

Last updated: Mar 19