![]() |
|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||||
|
||||
Scope and java questions
What is the correct way to scope variables/attributes when you fork a thread and want to pass data back and forth between the forked thread and the rest of studio? Do I declare the attribute in the forked thread, in the menu that forks the thread or as a global variable?
And I also have a general java question. If I have extracted an element from a grouping at one point in an STV and at another point want to find out what key that element belonged to, how do I do that? Thanks, Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#2
|
||||
|
||||
Quote:
Note though that however you declare it, it's still up to you to synchronize access to it so that it doesn't get overwritten by another thread in the midst of some calculation that uses it. I'm not entirely sure I follow this (some sample code might help), but in general, Maps provide a one-way mapping from keys to values. Once you've pulled a value from a Map, information about the key you used to select that value is lost (unless you make an effort to keep track of it separately). You could search the Map for a key that yields a given value, but if the values are not unique, you may not get the same key back.
__________________
-- Greg |
#3
|
||||
|
||||
Greg,
Sorry I was not clear. I'm doing the fork() in a BeforeMenuLoad hook. The purpose of the forked thread is to build up some data that will be displayed on a menu. The data that is being built up is stored in a global variable, so I think I've got that covered. What I want to make sure of is that if the user navigates away from the menu that forked the thread the thread's (internal) variables will not be lost or changed. It will take a while (several minutes) to build up the data and I want to make sure the forked thread runs to completion. Right now I have not used the attribute widget to declare any variable internal to the forked thread. Is that OK or do I need to use an attribute widget someplace? Regarding the second item, bummer. I guess I'll have to keep track of it separately. What I'm doing is pulling values from a map and building a new map whose keys are the values from the first map. I found a point in the code where I'm working on the second map but need to know its original key from the first. Is there an easier way to do this? Ideally, I'd like a data structure that looks like this: key value data data value data data value data data Right now I've got two maps: one for key/value and another for value/data. In the code I need to find the "key" that goes with the "data". I hope that makes sense.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#4
|
||||
|
||||
Nothing goes away until the last reference to it goes away. As long as your forked thread remains alive, its variable context remains valid, all the way up to the root of the containing menu. So any implicitly defined variables (those without explicit Attribute widgets) in that thread will keep their values until the thread exits, as will any menu-defined attribute variables visible to that thread, even if the menu unloads.
I'm going to try rephrasing your second question like so: you have three kinds of items you're keeping track of; call them X, Y, and Z. You have a map from X to Y, and another map from Y to Z. For a given Z, you want to obtain the corresponding X. Is that right? Seems to me your best bet is to make a new data structure (it can be a simple array if you like) comprising an {X,Y,Z} triplet. So now you can replace your two maps X->Y and X->Z with new maps X->{X,Y,Z} and Y->{X,Y,Z}. (Or maybe you don't even need the second map anymore.) The value is each case is the {X,Y,Z} triplet, and that's what you pass around in your code, so you never have a naked Z in your hand without knowing which X or Y gave rise to it.
__________________
-- Greg |
#5
|
||||
|
||||
Your X,Y,Z example is exactly what I am trying to do. Thanks again for both pointers.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tables, Java - Java Not being Called for each TableComponent Cell | stuckless | SageTV Studio | 3 | 04-02-2008 03:03 PM |
Java Questions | TWCorpus | SageTV Customizations | 0 | 04-26-2006 03:34 PM |
Java very noob questions... | Bohica | SageTV Studio | 7 | 03-16-2006 07:45 PM |
Help finding attribute in scope | DwarF | SageTV Studio | 4 | 01-22-2006 11:33 PM |
Beta V1.2.2 Java java.lang Null Pointer Exception | hamptonhills | SageTV Beta Test Software | 1 | 03-27-2003 12:11 PM |