AnsweredAssumed Answered

JSCalculator - Global Namespacing issue

Question asked by hardihood07 on Jan 3, 2011
Latest reply on Jan 31, 2011 by Chris_Hackett
I have successfully created a generic javascript calculator which can implement various logics to compute different data for x number of metrics. But here are the issues that i have:

- Everything's cool as long as the collector and/or MoM where the calculator lives, is running. If the machine goes down, the calculator is reset and starts afresh. Which means the all previous calculated value is gone. For e.g if I am calculating total responses for a service for a day, accumulative and say at some time machine goes down, that calc and accumulated value is gone.

Possible solutions that I can think of:
1. Either do a historical query on the cutom metric once the machine is back up and get the last know value. I am not sure how to do a historical query using javascript calculator
2. Keep writing a flat file with the accumated values and read the value from there incase of failure. -- I dont want to go through this brute route.
3. Use the "cool Namespacing" feature of javascript and make two scripts talk with each other. And then use a calculator running somewhere else to generate the value in the global namespace object and use that value. I have been trying this one but to my shock, the namespacing thing works on the native mozilla rhino jsengine but not on Wily JS Engine. For e.g:
In file "a.js":
if(!myNS) { var myNS={}; }

myNS.prop = {
name: "stewie",
type: "funny"

In file "b.js"
if(!myNS) { var myNS={}; }

So when i load the above two scripts in the Rhino JSEngine (say rhino debugger) and do a print( in b.js, it prints "stewie".
But if I do the same thing in Wily, i mean copying above to scripts into the scripts folder and doing, its says " TypeError: Cannot read property "name" from undefined" :(

Perhaps I am doing something wrong.Any help will be appreciated.