I’m reaching deep into the dusty vaults of my memory, but I think you can get the classname using:
ITM_Test2.state.class.name
But I’m not sure if that will give you the most specific class or just the class that the language thinks it is in the current context. It has been quite awhile since I’ve messed with reflection in Java (this is a Java thing, not a Rules DSL thing).
When you dumped the Item above it is clear that it is a NumberItem so I’m not sure if this will be all that informative.
If you log the state out using toString without trying to cast it, does it read correctly or generate an error?
logInfo("network", ITM_Test2.state.toString)
You could go to TRACE level logging. I’m not sure how to increase the logging in the Rules interpreter in a targeted way.
Perhaps it is a timing issue. The time required for the MySQL Persistence classes to create a connection to the MySQL server and authenticate may be just long enough that the rules start executing before restoreOnStartup finishes initializing the Items.
That doesn’t explain why the state isn’t NULL which is what I would expect.
You might consider using a tiered persistence approach like I describe here:
The tl;dr is use MapDB for restoreOnStartup, rrd4j for recent historical data, and something like MySQL or InfluxDB for charting and long term analysis data.