SageTV Community  

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

Notices

SageTV v7 Customizations This forums is for discussing and sharing user-created modifications for the SageTV version 7 application created by using the SageTV Studio or through the use of external plugins. Use this forum to discuss plugins for SageTV version 7 and newer.

Reply
 
Thread Tools Search this Thread Display Modes
  #41  
Old 06-02-2010, 05:08 PM
ranger ranger is offline
Sage Aficionado
 
Join Date: Nov 2003
Location: Virginia
Posts: 256
Thanks for adding the apps page.
Running the latest version and have 3 options on the "apps" page, bmt, sage, and sagex. BMT and sage work fine, but "sagex" produces the error below. I am not really sure what should be there, so it may be something I don't have fully installed / configured.

Code:
HTTP ERROR 404

Problem accessing /sagex/. Reason:

    No Sage Handler Specified.
Powered by Jetty://
Reply With Quote
  #42  
Old 06-02-2010, 06:13 PM
lotusvball's Avatar
lotusvball lotusvball is offline
Sage Aficionado
 
Join Date: Dec 2003
Location: PA
Posts: 482
Quote:
Originally Posted by jreichen View Post
Did you do this?
Nope.....
__________________
Intel Core Duo 2.5mhz, 2gb RAM
Windows Home Server, Sage 7 beta
2 Hauppauge PVR-250, 1 PVR-500 MCE
1 HDHomeRun
4TB Storage, GB Network
2 MVPs, 1 HD100 & 1 HD300
Reply With Quote
  #43  
Old 06-03-2010, 07:49 AM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Quote:
Originally Posted by ranger View Post
Thanks for adding the apps page.
Running the latest version and have 3 options on the "apps" page, bmt, sage, and sagex. BMT and sage work fine, but "sagex" produces the error below. I am not really sure what should be there, so it may be something I don't have fully installed / configured.

Code:
HTTP ERROR 404

Problem accessing /sagex/. Reason:

    No Sage Handler Specified.
Powered by Jetty://
That's what sagex returns if nothing more than the context path is specified in the url. Sagex is not really meant to be an end user app but I think it will return a help page if you add /api to the end of the URL.

The "apps" page doesn't know anything specific about webapps. Each app needs to be updated to tell it what page to go to. For example, the web ui needs to go to /sage/Home, not just /sage. I hope to get to that soon. I notified other developers of this requirement in the first post of this thread so other plugins should be adopting this as well.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #44  
Old 06-03-2010, 07:52 AM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Quote:
Originally Posted by lotusvball View Post
Nope.....
Try deleting the directories from /jetty/webapps while Sage is shut down. It should only need to be done once. After that Jetty 2.0.1 will be able to clean them up on its own.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #45  
Old 06-03-2010, 08:43 AM
lotusvball's Avatar
lotusvball lotusvball is offline
Sage Aficionado
 
Join Date: Dec 2003
Location: PA
Posts: 482
Quote:
Originally Posted by jreichen View Post
Try deleting the directories from /jetty/webapps while Sage is shut down. It should only need to be done once. After that Jetty 2.0.1 will be able to clean them up on its own.
Thanks, it worked. I had to wait a few minutes while it recreated the directories, but all is well now.
__________________
Intel Core Duo 2.5mhz, 2gb RAM
Windows Home Server, Sage 7 beta
2 Hauppauge PVR-250, 1 PVR-500 MCE
1 HDHomeRun
4TB Storage, GB Network
2 MVPs, 1 HD100 & 1 HD300
Reply With Quote
  #46  
Old 06-07-2010, 07:26 PM
peternm22 peternm22 is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 709
I was wondering if there was a way to have: http://<server>:<port> redirect to a certain Jetty app instead of a 404 page? So instead of typing http://<server>:<port>/sage/ , I could just type http://<server>:<port> and it would forward me to http://<server>:<port>/sage/.

The web interface is my most used Jetty app, so it would be handy to be automatically redirected there.

Thanks.
Reply With Quote
  #47  
Old 06-07-2010, 09:45 PM
robogeek robogeek is offline
Sage Expert
 
Join Date: Apr 2003
Location: Appleton, WI USA
Posts: 568
Quote:
Originally Posted by peternm22 View Post
I was wondering if there was a way to have: http://<server>:<port> redirect to a certain Jetty app instead of a 404 page? So instead of typing http://<server>:<port>/sage/ , I could just type http://<server>:<port> and it would forward me to http://<server>:<port>/sage/.

The web interface is my most used Jetty app, so it would be handy to be automatically redirected there.

Thanks.
I think if you create an index.html with the following code:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>SageTV</title>
<meta http-equiv="REFRESH" content="0;url=http://<server>:<port>/sage/"></HEAD>
<BODY>
</BODY>
</HTML>
then replace <server>:<port> with your server web address and port number, and then drop the index.html file into the jetty\static directory, that should redirect to the SageTV web server page.
__________________
--Jason

Server Hardware: GIGABYTE GA-EP45-UD3R, Intel Q9550 CPU 2.83GHz, 11GB RAM, 1xHDHR, 1xHVR1600, 1xHVR2250
29TB Server Storage: 1TB SSD (OS), 1TB (data), 2x6TB+2x10TB (22TB FlexRaid storage pool), 2x2TB (recordings), 1x750GB (VMs).
Server Software: Win10 Pro x64 OS, SageTV 64bit v9.2.0.441, Java 1.8 u241, PlayOn, Comskip (Donator) v0.82.003, WampServer v2.5.
Clients: 3xHD300s, 2xHD100, 2xPlaceshifters
Reply With Quote
  #48  
Old 06-07-2010, 09:54 PM
peternm22 peternm22 is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 709
Thanks, I had no idea about the "static" directory option. I managed to fashion my own cumbersome solution though, I copied a web app and context file from another app. Then I put an index.html file in it with the refresh, and set the path to "/".... it works.

Your way is much much simpler though, and I've switched to it Thanks.
Reply With Quote
  #49  
Old 06-09-2010, 01:13 PM
kmp14 kmp14 is offline
Sage Aficionado
 
Join Date: May 2008
Location: Chicago, IL
Posts: 264
Help. I am stuck. I upgraded to the latest Sage 7. Jetty and the Sage Web UI still continued to work fine. I decided to then upgrade the Jetty to the latest via the Plugins feature in S7. It installed fine, and I am able to configure it on screen, but I cannot get to the site. I don't get a jetty error in the browser, instead, it looks like the site is not up at all.

I am not sure where to look to see if it is even really running. I do see a agex-api.log with the Warning that "NO Context Was Found".

Any tips to help me get the troubleshooting started would be appreciated!
__________________
HP m9040n Quad Core 2.4Ghz, Windows7 Ultimate, Ceton 4 tuner CableCard with SageDCT, 2 HDHomeRun QAM, Netgear 24 Port GiGE Switch, Linksys WRT600N Router, 3 HD200 Extenders, 2 SageTV Clients

Server: SageTV 7
Reply With Quote
  #50  
Old 06-09-2010, 10:55 PM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Are you able to go to http://<server>:<port>/apps?

Try turning on Sage's debug logging (in detailed setup) and increase Jetty's log level to VERBOSE (in the Jetty plugin config screen) and see if anything looks wrong. Post it here it you'd like me to review it.

Also you may have duplicate jar files if you weren't on Jetty 1.6 before installing 2.0 through the plugin manager. Please post a list of the files in your JARs folder.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #51  
Old 06-11-2010, 05:34 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Life and Death of a Servlet

John,

I'm working on a servlet that spawns a thread. I want to make sure the thread is stopped when the Servlet instance ends.

From the experiements I've done I think the servlet is instantized the first time it is needed (please correct me if I'm wrong) but I can't quite figure out when the instance ends. What are the guidelines for that? Does the instance live util Sage or Jetty stops or can the instance end before then? And more importantly, how can I catch the fact that the instance is ending so I can tell the spawned thread to stop?

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
  #52  
Old 06-11-2010, 10:16 PM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
There's a lot to cover so I'll try to keep this from getting too long and give you some pointers you can research.

Normal Java objects have no reliable way of knowing when they're being cleaned up. However, objects that implement the Servlet interface are a bit different. The Servlet interface has a destroy() method that is called by the Java web server when a servlet's lifecycle is ending. There's also an init() method for when it's being initialized. I'd recommend reading about servlet lifecycles.

The servlet can be loaded either when the server starts or the first time it needs to handle a request. Check out the <load-at-startup> setting in web.xml.

AFAIK, in Jetty the servlet will be destroyed either when:
  1. The web application is stopped, uninstalled (context file is removed) or restarted (context file timestamp is updated).
  2. Jetty is shut down (which stops the web app)
  3. Sage is shut down (also stops the web app)
Be careful when stopping a thread, don't use the Thread object's stop() method as that's known to cause problems and has been deprecated. Basically you want to let the run() method exit normally in order to let the thread die. This is another area I'd suggest reading up on as I'm a little rusty on it. If you have further questions I'll try to answer them.

Use caution with threading in servlets. One instance of a servlet services all requests. Each request runs on a new thread (or a reused thread in a pool) so the use of instance variables is generally discouraged but can be used if locking or synchronization is used correctly.

Jason
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #53  
Old 06-12-2010, 04:01 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Jason,

I understood it all up to this point:

Quote:
Originally Posted by jreichen View Post
One instance of a servlet services all requests. Each request runs on a new thread (or a reused thread in a pool) so the use of instance variables is generally discouraged but can be used if locking or synchronization is used correctly
Isn't an instance and a thread essentially the same thing: one instance = one thread?

You warn about threading in a servlet, how else do you get things done that take a long time (several minutes)? I did not see any other way other than to start a thread to handle the work so the servlet could go on it's way and handle the next request. if I do not start a thread the servlet would be unavailable for a long time.

Why are instance variables discouraged, I thought that would be a preferred way of doing things? Should I make all of the variables that I want to keep track of over the life of the servlet static?

I'm missing a key piece here for sure.

PS. Sorry for calling you John, I was thinking JRKiwi
__________________

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 06-12-2010, 09:21 AM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Quote:
Originally Posted by tmiranda View Post
Isn't an instance and a thread essentially the same thing: one instance = one thread?
They aren't the same. Java methods are reentrant, meaning more than one thread can execute in them at one time. Method parameters and variables that are defined in a method are both on the stack so they're not shared by multiple threads. Instance variables belong to the object so multiple threads may access them at the same time. Static variables belong to the class and can also be accessed by multiple threads at the same time. For example:
Code:
public class MyExample
{
    // this is available to any thread executing in
    // one of this object's methods
    private Object obj;

    // each thread executing within this method has
    // its own copy of s and methodObj
    public void myMethod(String s)
    {
        Object methodObj;
        // method logic...
    }
}
Quote:
Originally Posted by tmiranda View Post
You warn about threading in a servlet, how else do you get things done that take a long time (several minutes)? I did not see any other way other than to start a thread to handle the work so the servlet could go on it's way and handle the next request. if I do not start a thread the servlet would be unavailable for a long time.
Since multiple threads can execute in a method concurrently, one request will not block another - unless the server is using a thread pool and all threads are busy servicing client requests. For Sage webapps I don't worry about large numbers of simultaneous requests since that's not likely to happen. There might be a few at a time but not hundreds or thousands like large websites would have.

Quote:
Originally Posted by tmiranda View Post
Why are instance variables discouraged, I thought that would be a preferred way of doing things? Should I make all of the variables that I want to keep track of over the life of the servlet static?
It can be done if necessary but it's generally advised to avoid it if possible because multiple threads can access them at once and ensuring thread safety can be difficult. If possible use variables declared in the method rather than instance or static variables. If you need to save something across requests then you'll need to use some form of object sharing along with Java's synchronization or lock mechanisms to ensure thread safety. See the Java EE Tutorial for more info about sharing data.

As I'm sure you've noticed, threading can become quite a complex topic. I would start by writing your logic without creating your own threads. Let the web server do the hard work for you.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #55  
Old 06-12-2010, 09:34 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
OK, lots of things to think about.

You say to let the web server do the hard work and not mess with threads. I must be missing the big picture somewhere because the way I understand it in a servlet you HAVE to start a thread to do work that will take a long time because the servlet can only process one request at a time.

If the servlet is busy downloading a file for several minutes it will be unavailable to take new requests until the file download is completed. This is just does not seem right, what am I missing?
__________________

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 06-12-2010, 01:52 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
Originally Posted by tmiranda View Post
If the servlet is busy downloading a file for several minutes it will be unavailable to take new requests until the file download is completed. This is just does not seem right, what am I missing?
A servlet instance does not handle the incoming connections itself, instead there's usually a pool of socket listeners (or equivalents). These are the things that handle connections. Each incoming connection to Jetty that is destined for your servlet simply uses the single instance of your servlet object to process the request. This is why your servlet methods (doPost(), doGet(), etc.) all accept an HttpServletRequest and an HttpServletResponse as args - that's the encapsulation of the network "stuff" that's going on. And that's why your servlet instance can be accessed by multiple threads simultaneously. And it's also why if your servlet has instance or static vars then they must be synchronized.

The fact that a request is in your servlet will not block other requests from accessing your servlet - unless you synchronize - which is why it's very undesirable to synchronize in your servlet - it will kill the liveliness/concurrency of your web apps. With that said, in an environment like Jetty for SageTV, synchronization, though not desirable, probably isn't a big deal should your design call for it (because the max request load/max concurrent request load is so tiny - for most use cases).
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
Reply With Quote
  #57  
Old 06-12-2010, 02:44 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
OK, I was under the impression that there was NEVER more than one instance of the servlet. So I CAN have one instance of the servlet busy downloading a file and jetty will create another instance to handle any new request that come in while the file is downloading.

That actually makes my life a lot easier

Thank you Slugger and Jason.
__________________

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 06-12-2010, 02:59 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
OK, I was under the impression that there was NEVER more than one instance of the servlet. So I CAN have one instance of the servlet busy downloading a file and jetty will create another instance to handle any new request that come in while the file is downloading.
No, that's not what they're saying. Your servlet class will be instantiated just once. But that one instance can receive ansynchronous method calls from multiple threads to handle multiple asynchronous requests. The Request and Response objects will exist in multiple instances, but your servlet object will not.

That does not mean you need to create any additional threads; that's done automatically by Jetty. But you do need to be prepared to handle method calls from multiple threads in a thread-safe manner.
__________________
-- Greg
Reply With Quote
  #59  
Old 06-12-2010, 04:38 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
OK, so I'm back where I started. One instance that has to handle multiple requests, possibly more than one at a time.

Half my problem is that I do not know all of the correct Java/OO terminology.
__________________

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
  #60  
Old 06-12-2010, 10:18 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
To simplify:

Each request to Jetty generates a unique HttpServletRequest and HttpServletResponse object (how those are built, be it a pool, etc. is irrelevant). Those two objects are passed to your servlet in its own thread. So your servlet will be used in all active request threads simultaneously and there will only ever be exactly one instance of your servlet, which is shared among all active request threads. This is the reason why if your servlet has instance or static vars then they must be synchronized.

And synchronization is not ideal in web apps with high volumes of traffic because when you synchronize then (in a high level view) only one request can be serviced at a time - the others must wait their turn. However, as I said above, in our (jetty apps for SageTV) little universe you can basically ignore this design goal/issue because at its busiest you're probably talking 2-3 simultaneous connections at once, which is not going to cause any kind of issues unless you do some kind of long computation inside a synchronized() block.

To me, a servlet should return a response to the browser in sub-second time so synchronized() blocks of code are fine (I even do it in my SJQ code quite liberally to protect against simultaneous modification of the SJQ task queue by multiple task clients), but your servlet should complete and return the response as quickly as possible otherwise users get a sense that the web site is "hung", etc. Ultimately, I guess the lesson here is that J2EE app design and implementation requires a bit of planning. I think Jason mentioned reading up on the servlet lifecycle? Couldn't agree more. The more you understand about the details of a J2EE app, the easier it becomes to identify and solve these kinds of issues up front - before they become bigger problems.
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
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
Plugin: SageTV Web Interface V2 for Jetty jreichen SageTV Customizations 256 02-09-2014 08:05 AM
Plugin: Jetty Starter 1.6 jreichen SageTV Customizations 122 09-07-2012 06:48 PM
error message with web server plugin edgley SageTV Customizations 3 01-15-2006 11:32 AM
Sage Web Server and existing web server compatibilty? Brent94Z SageTV Customizations 6 01-18-2005 11:29 AM


All times are GMT -6. The time now is 11:20 AM.


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