10-31-2012 06:44 AM
I have a class that have many configuration variables defined. These are set at runtime. Is it possible to save and retrieve the class in persistent storage? If yes, how?
Solved! Go to Solution.
10-31-2012 07:48 AM
10-31-2012 07:58 AM
To find related KB articles, including sample code, type "persistence" in the Search box. Here is one that I found.
10-31-2012 05:08 PM
I am using persistent storage for several purposes.
For some specific reasons I would like to store some config variables in a class and make it accessible from
2 different major tasks running. A background task and a GUI. If possible I would like this class to keep its values between restarts
I have made a few attempts with a test class like this:
public class StatConfigs implements Persistable
public int tester = 0;
Can not get a grip on it from my 2 tasks running.
Have searched this site for persistable class but not found much. Many articles on how to handle persistent storage yes, but I have no broblem with that.
Is it possible to access "tester" from two different (main) threads? Is the value of "tester" preserved
10-31-2012 05:32 PM
The situation you are trying to code for is easily handled using persistent store.
If you look at the way persistent store works, you basically store an Object in a persistent slot, which is identified by an ID - the ID is along value. So anyone who knows the ID can access the Object.
However to interpret the Object, they must have the exact class that was used when the Object was stored. In your case this is easy as your two 'Applications' will actually use the same class as they are actually just different entry points into the same set of code.
This requirement for the same class to be used, becomes a problem when you have two completely different applications using the same Persistent ID. In this situation, the two applications have to share a Library class that defines the persistent Object.
But back to your situation, what you are trying to do will work well with Persistent Store.
To give you more of feel for it, when your background application requests the persistent object, it will get a reference to an Object in flash memory. When your GUI application does the same thing, it will get a reference to the same Object. So they will definitely share the data and both see each other's updates.
Hope that clears this up for you.
10-31-2012 05:56 PM
The key to the problem is to use a Library in conjunction with a persistable class then. I already have the correct code in place to access a persistent storage in a controlled way from my two "apps"
10-31-2012 06:50 PM
Typically when I have a background task and a GUI, they are actually part of the same application and installed together. If you can do this, package them together and only have a single project, lie will be much similar. If you start looking at getting Libraries to access shared data, the packaging becomes significantly more complicated. Can you build these two together.
10-31-2012 07:08 PM
This is actually an upgrade of an existing application so the over all architecture is rather fixed. In an earlier relaease we actually had a libray but dropped it. I believe the solution actually will be done in 2 parts. Shared configs will be stored directly in persistent storage (As in the current production version). Another person is developing the GUI that has conf variables of a different type and since the GUI is the only user of these configs it will be implemented with a class. No need to share so the problem is simpler. Split the problem into 2 parts :-)