SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-02-2009, 08:56 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #2  
Old 10-03-2009, 02:49 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
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?
Forking is something you do in process (green) action chains, whereas attributes must be children of UI (blue) widgets. I'm not sure what it would mean to call Fork() in a blue UI chain (but probably nothing good). So the idea of declaring the attribute in the forked thread doesn't really make sense. Just find the nearest common ancestor that spans all references to it (forked or not) and put the declaration there. If it really needs to be global (i.e. visible to multiple menus), then make it global.

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.

Quote:
Originally Posted by tmiranda View Post
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?
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
Reply With Quote
  #3  
Old 10-03-2009, 03:57 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #4  
Old 10-03-2009, 12:24 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
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
Reply With Quote
  #5  
Old 10-03-2009, 01:23 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -6. The time now is 06:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.