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
  #41  
Old 05-15-2010, 04:12 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Also, why do I need to add the context name?

Code:
http://harris:8080/YOUR_CONTEXT_NAME/SagePodcastRecorder?name=Sean
When I access bmt I just enter:

Code:
http://harris:8080/bmt
__________________

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
  #42  
Old 05-15-2010, 05:25 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Sean - I was wondering why your .xml was so much different from the other example context xml's I've seen.
Probably because I didn't know what i was doing While I know a fair bit about web applications, I didn't have much experience with Jetty.

Quote:
I copied your bmt xml (below) and it still does not work. The only difference is now if I enter http://harris:8080/sagepodcastrecorder I get a "Hello World!" message in the browser.

I thought there might be a difference between SagePodcastRecorder and sagepodcastrecorder so I tried every combination of sagepodcastrecorder/sagepodcastrecorder I could think of.
The complete path to the servlet needs to include the context path and the servlet path.. ie, if your servlet is SagePodcastRecorder and your context is sagepodcastrecorder, then the url is...

Code:
http://harris:8080/sagepodcastrecorder/SagePodcastRecorder?name=sean
case matters


Quote:
Originally Posted by tmiranda View Post
Also, why do I need to add the context name?
Think of a context name as a namespace. A web application server may host many different "applications" each with one of more servlets. Without the context, I may have a servlet called "status" and you might have a servlet called "status", and one would overwrite the the other.


Quote:
When I access bmt I just enter:

Code:
http://harris:8080/bmt
That's because bmt has many servlets under the "bmt" context. In the web.xml for bmt, I've specified a number of "index" pages, so when you enter /bmt in the browser, it actually serves up /bmt/index.html. This has nothing to do with servlets, all web servers do this. In the the web.xml you can specify a servlet as the index page as well, so that when you enter /sagepodcastrecorder (ie, just the context), it serves us /sagepodcastrecorder/SagePodcatRecorder
Reply With Quote
  #43  
Old 05-15-2010, 07:03 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Sean,

I tried this, and other variations of upper and lowercase. Nothing worked.

Code:
http://harris:8080/sagepodcastrecorder/SagePodcastRecorder?name=Sean
Screenshot atatched.
Attached Images
File Type: jpg 404.jpg (60.3 KB, 176 views)
__________________

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
  #44  
Old 05-16-2010, 05:37 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Tom, I've attached a sample web app, with context xml and source. You should be able to unzip this in the root of your sagetv home, and then hit the following url

Code:
http://localhost:8080/testweb/TestServlet?name=tom
/testweb is the webapp context as defined in the jetty/contexts/TestWeb.xml context file. /TestServlet is the servlet path as defined in the WEB-INF/web.xml.

TextWeb.xml (fragment)
Code:
<Set name="contextPath">/testweb</Set>
web.xml (fragment)
Code:
  <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
  </servlet-mapping>
When defining a servlet in the web.xml, it's the <url-pattern> that triggers the servlet.

Hope this helps to bring you a little closer.
Attached Files
File Type: zip TestWeb.zip (3.1 KB, 157 views)
Reply With Quote
  #45  
Old 05-16-2010, 07:06 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Sean,

I REALLY appreciate all of your help on this. You are certainly going "above and beyond" the call of duty...

Your test works perfectly. I think my problem lies in "web.xml". I have no "web.xml" and your code does not have one either, so I'm sure I'm missing the boat somewhere. Your zip file has TestWeb.war and TestWeb.xml. Where is "web.xml"?

I see a web.xml for bmt that is under ../jetty/webapps/bmt/webapp/WEB-INF but I do not see one for TestWeb.

Is "web.xml" something that is inside of the .war file? I'm starting to think I need to add this code someplace in the IDE and have it packaged in the .war.

I NetBeans I see two files under WebPages/WEB-INF. One is "beans.xml" and one is "sun-web.xml". sun-web.xml also shows up under the jetty folder where I have deployed my webapp.

In the IDE, under WEB-INF I see the option to add: HTMP, Web Service, Web Client, JSP, Servlet, and lots of other options. Of course "Servlet" catches my eye. Also in the IDE I see the option to add "servlet" so I think I am on to something here.

I'll get back to you once I sort things out a little further, but I am very hopeful right now.

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
  #46  
Old 05-16-2010, 07:29 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Sean,

I REALLY appreciate all of your help on this. You are certainly going "above and beyond" the call of duty...

Your test works perfectly. I think my problem lies in "web.xml". I have no "web.xml" and your code does not have one either, so I'm sure I'm missing the boat somewhere. Your zip file has TestWeb.war and TestWeb.xml. Where is "web.xml"?

I see a web.xml for bmt that is under ../jetty/webapps/bmt/webapp/WEB-INF but I do not see one for TestWeb.

Is "web.xml" something that is inside of the .war file? I'm starting to think I need to add this code someplace in the IDE and have it packaged in the .war.

I NetBeans I see two files under WebPages/WEB-INF. One is "beans.xml" and one is "sun-web.xml". sun-web.xml also shows up under the jetty folder where I have deployed my webapp.

In the IDE, under WEB-INF I see the option to add: HTMP, Web Service, Web Client, JSP, Servlet, and lots of other options. Of course "Servlet" catches my eye. Also in the IDE I see the option to add "servlet" so I think I am on to something here.

I'll get back to you once I sort things out a little further, but I am very hopeful right now.

Tom
Tom, really, this hasn't taken more than 15mins of my time At the risk of starting an IDE flame war, I think your issue is more netbeans related than anything. The web project that I sent you (less the context xml) was created in less than a minute.

Because you opted to use the sun glassfish project, it's a j2ee application server, which is basically an app server on steroids, that is used in the "enterprise" (ee == enterprise edition). j2ee servers deal primarily with "ear" files which is another package format that can contain serveral war files. Typically enterprise servers (glassfish, websphere, weblogic), etc all have their own extensions to the web.xml, that are not recognized by simple app servers like Jetty and Tomcat.

What I would do, is stop using glassfish (uninstall it). Install the tomcat server (either download it, or install it as a plugin). If you stick with tomcat or jetty, then I'll think that you'll have more luck with you simply web apps. Then when you create a new "web project", it will create just a standard app server server project without any proprietary extensions. Also, when you create a new servlet (File -> New...) it should automatically wire the web.xml for you, ie, you don't need to manually edit this file. That's how eclipse does it, and I assume somewhere in netbeans, it works the same way.

btw, war file are just zip files and so you can check my .war file, and you'll see that I have an web.xml in the WEB-INF/ dir of the .war
Reply With Quote
  #47  
Old 05-16-2010, 10:21 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Sean,

Yup, it's NetBeans related. I was choosing "Web App" instead of "Servlet". I'm about to try it again...

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
  #48  
Old 05-16-2010, 10:45 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Success at last! It was NetBeans related. This AM I actually downloaded and installed Tomcat. The final piece of the puzzle was to choose the right type of project AND I had to use the context.xml that was generated by NetBeans. The context.xml looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/SagePodcastRecorder"/>
__________________

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
  #49  
Old 05-17-2010, 05:26 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Another question. In an earlier post it was stated that the servlet processing is synchronous and each time the servlet is called a new thread is created. I get that. What is the best way to keep static data that needs to be saved for subsequent processing?

Here is what I have in mind for the servlet. Downloading a podcast takes time so of course I do not want to make the requester wait for completion. When the requester makes a request I just want to queue it, spawn a thread to handle the download (hopefully that can be done in a servlet) and return to the requester right away. So far so good.

If a request is made to download a podcast while one is already downloading, I want to queue that up until the first podcast has downloaded. What is the best way to store the queue (and any other data that needs to be saved because it pertains to all podcast downloads, not just the current one.)
__________________

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
  #50  
Old 05-17-2010, 05:43 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Another question. In an earlier post it was stated that the servlet processing is synchronous and each time the servlet is called a new thread is created. I get that. What is the best way to keep static data that needs to be saved for subsequent processing?
I'd use a static member of the servlet class, or create manager that returns a single instance of itself (singleton pattern).

Quote:
Here is what I have in mind for the servlet. Downloading a podcast takes time so of course I do not want to make the requester wait for completion. When the requester makes a request I just want to queue it, spawn a thread to handle the download (hopefully that can be done in a servlet) and return to the requester right away. So far so good.
You can launch a thread from within a servlet.

Quote:
If a request is made to download a podcast while one is already downloading, I want to queue that up until the first podcast has downloaded. What is the best way to store the queue (and any other data that needs to be saved because it pertains to all podcast downloads, not just the current one.)
I did something similar to this in the bmt web for scanning media files. In my case I have something called a "Tracker" that takes a command and executes it in a background thread but it returns a unique id that can be used to track the item. On subsequent calls, I pass the token from the tracker back to the tracker for status updates.

It works something like this...
Tracker Servlet is called with an action to run
-- TrackerId = Tracker.getInstance().runAction(action);
-- return TrackerId to the caller (ie http client, in my case i returned xml or json since it's easy to parse)

Tracker Servlet is called with the TrackerId from the previous call
-- TrackableInfo = Tracker.getInstance().getInfo(TrackerId)
-- return TrackerableInfo as json or xml

As part of the Tracker code, I use a Timer to periodically clean out tasks where the TrackerInfo has indicated that it has completed... and a certain amount of time has elapsed since it has completed.
Reply With Quote
  #51  
Old 05-17-2010, 06:09 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Sean,

OK thanks.

When you say use a static member of the servlet class, do you mean I can create static data that does not go away as long as sage is running?
__________________

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
  #52  
Old 05-17-2010, 06:54 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Sean,

OK thanks.

When you say use a static member of the servlet class, do you mean I can create static data that does not go away as long as sage is running?
Code:
public class MyServlet extends HttpServlet {
    private static Map<String,Tracker> trackers = new HashMap<String,Tracker>();
}
The 'trackers' field in the MyServlet will ONLY ever be created once (when the class is created) and it will be alive until the jvm shuts down.

Servlets have their own lifecycle as well... there are methods called init() and destroy() that as called when the servlet is initialized (ie, only once) and when the servlet is destroyed.

For something like the tracker, you may want to consider using a TrackerManager that has the static reference to the class and NOT put the static reference inside the actual servlet class.

Code:
public class TrackerManager {
   private static final instance TrackerManager = new TrackerManager();
   public static TrackerManager getInstance() {
       return instance;
   }

   private Map<String,Tracker> trackers = new HashMap<String,Tracker>();
   ...
}
Since using static members insde the Servlet class is frowned upon. Servlets can be reloaded and when that happens a new classloader is created, so you'll lose the reference to the existing static member when the new Servlet is created. It also plays havoc with the garbage collection, since the servlet instances cannot be garbarge collected (easily).

Code:
public class MyServlet extends HttpServlet {
    public void doGet(...) {
        ...
    String trackerId = TrackerManager.getInstance().runAction(...);
    }
}
Hope this helps
Reply With Quote
  #53  
Old 05-17-2010, 08:17 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Trackers - More things to read up on...
__________________

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
  #54  
Old 05-17-2010, 08:24 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Trackers - More things to read up on...
Keep in mind when I say "Trackers"... that's not a core java thing... I just called it a "Tracker" in bmt... but I still had write the code for it.
Reply With Quote
  #55  
Old 05-17-2010, 10:48 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
I'd like to say I understand your code, but I don't. I need to chew on things to see if I can wrap my brain around it.

Thanks for the info and things to consider.
__________________

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
  #56  
Old 05-17-2010, 11:33 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
I'd like to say I understand your code, but I don't. I need to chew on things to see if I can wrap my brain around it.

Thanks for the info and things to consider.
Keep in mind my code (as linked) was just one file... there are 5-6 other files that make up a progress monitor/tracking system that's hybrid of the eclipse IProgressMonitor system with some tweaks. I wasn't writing a single purpose class/manager, so it takes advantage of java generics so that it can support various kinds of custom trackers, etc. All this will seem pretty overwhelming to a novice java developer, but will seem pretty trivial to a seasoned java developer

I'd start simple, build your own simple single purpose tracker, and then add/extend as you need. If my sample is confusing, then I'd pretend that you never saw it
Reply With Quote
  #57  
Old 05-18-2010, 07:05 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by stuckless View Post
The 'trackers' field in the MyServlet will ONLY ever be created once (when the class is created) and it will be alive until the jvm shuts down.

.... Servlets can be reloaded and when that happens a new classloader is created, so you'll lose the reference to the existing static member when the new Servlet is created.
Sean,

These two statements seem contradictory to me. Can you elaborate a little? My first thought is to go with what's easier for me to understand, and that's putting the private static in the "MyServlet" class. I just want to make sure the data really is static until the JVM (i.e. Sage) terminates.

Second,

Where is a good java developers community that is helpful to beginners. I am sure I'll have loads of java and NetBeans questions and I don't want to keep on bothering you here.

For example, I could not get NetBeans to build your example code. It complained about the generics on Map<> and HashMap<> saying that "source level 1.5" was needed. I tried putting the "- source 5" into the command line parameters area in NetBeans but that did not help. I had to build the code without the generics - which I'd rather not do. My thinking is the more checking the compiler can do for me the better
__________________

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
  #58  
Old 05-18-2010, 01:53 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Sean,

These two statements seem contradictory to me. Can you elaborate a little? My first thought is to go with what's easier for me to understand, and that's putting the private static in the "MyServlet" class. I just want to make sure the data really is static until the JVM (i.e. Sage) terminates.
For now use the static member of your class, if that's easier for you. You can always change it later.

Quote:
Second,

Where is a good java developers community that is helpful to beginners. I am sure I'll have loads of java and NetBeans questions and I don't want to keep on bothering you here.

For example, I could not get NetBeans to build your example code. It complained about the generics on Map<> and HashMap<> saying that "source level 1.5" was needed. I tried putting the "- source 5" into the command line parameters area in NetBeans but that did not help. I had to build the code without the generics - which I'd rather not do. My thinking is the more checking the compiler can do for me the better
I'm not sure. I tend to use google a lot. I type Java followed by the concept that I'm after.

BTW sorry for the brief replies, but I'm on an airplane on my way to google io.
Reply With Quote
  #59  
Old 05-18-2010, 03:21 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Thanks. No problem with the short replies either. I'm getting on an airplane tomorrow with the shiny new java programming book I just bought
__________________

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
Re: Replying to Announcement Threads MeInMaui SageTV Customizations 1 07-09-2009 10:49 PM
Number of threads? Stuntman SageTV Beta Test Software 8 11-24-2008 01:00 PM


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


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