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
  #1461  
Old 02-09-2014, 10:13 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Don't think so. That should about do it.
__________________
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
  #1462  
Old 02-09-2014, 11:20 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
When I tried to run sagegroovy on the new PC I get a Java error but the Groovy Console starts and it looks like I am able to run code, including Java code.

Here is the error:

Code:
java.utils.prefs.WindowsPreferences <init>
WARNING:  Could not open/create prefs root node Software\Javasoft\Prefs at root 0x80000002.  Windows RegCreateKeyEx(...) returned error code 5.
This error is fixed by creating the Reg key "HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs" but it doesn't seem to be causing an issues when you have it.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1463  
Old 02-10-2014, 08:39 AM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Is that the Oracle JVM installed? I've never seen that before, but definitely isn't caused by anything in the SageGroovy code.
__________________
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
  #1464  
Old 02-10-2014, 11:31 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I have just installed the basic java from the Oracle web site - this is a new PC so it hasn't had too much software installed. The OS is Win7 Pro x64 - when I Google this it seems to be very prevalent on 64 bit installs so maybe it related to that. It may also be related to not running Sagegroovy as an administrator, although the account is an administrator account. But adding this reg key solves the problem.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1465  
Old 02-17-2014, 11:33 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Quote:
Originally Posted by phelme View Post
Argh. 3 days after I leave on a snowboard trip, the H2 database engine once again fills up "sagetv/.lobs.db" with 65 GB's of temp file crap and my server crashes.

Has anyone tried a H2 jar file later than 1.2.145 that possibly fixes this?

If not, anyone ever create a script that monitors the lobs directory for excess usage, shuts down Sage, cleans the directory and restarts Sage?
I just noticed that I was running out of space on my server and it was the lobs.db issue. This has happened to me at least twice over a few years.

I wrote a vb script to email me a daily hard drive report - this is run once a day from Task Scheduler on my SageTV server. The email looks like this if all is well:
Code:
Subject: Daily Hard Drive Report - all is well

Hard drive report for CARNOUSTIE

C: drive 42.561 GB free of 119.240 GB
The threshold for this report is: 15 GB
lobs folder size is: 0.013 GB
If there is an issue the subject line changes to: *******HARD DRIVE ALERT**********

This is a vbscript code and it calls on another routine to send an email via my gmail account (if anyone wants that script then let me know):
Code:
    Dim fso, drv, bytesPerGB, freeGB, totalGB, s
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set WshNetwork = CreateObject("WScript.Network")
	    s = ""
    bytesPerGB = 1024 * 1024 * 1024
	ComputerName = WshNetwork.ComputerName
	
	LowDriveThreshold=15
	LobsFolderName="C:\Program Files\SageTV\SageTV\.lobs.db"
	Set LobsFold=fso.GetFolder(LobsFolderName)
	LobsSize=FormatNumber(LobsFold.Size/bytesPerGB,3)
	Drive="c:\"


    Set drv = fso.GetDrive(fso.GetDriveName(Drive))

    s = s & drv.Path & " drive "

    if drv.IsReady Then
         freeGB = drv.FreeSpace / bytesPerGB
         totalGB = drv.TotalSize / bytesPerGB

         s = s & FormatNumber(freeGB, 3) + " GB free of "
         s = s & FormatNumber(totalGB, 3) + " GB"
    Else
         s = s & "Not Ready"
    End If

If freeGB < LowDriveThreshold then 
	Subject="*******HARD DRIVE ALERT**********"
Else
	Subject="Daily Hard Drive Report - all is well"
End If
'Subject="Hard Drive Report"
Body="Hard drive report for "+ComputerName+vbCRLF+vbCRLF+s+vbCRLF+"The threshold for this report is: "+Cstr(LowDriveThreshold)+" GB" +vbCRLF
Body = Body + "lobs folder size is: "+Cstr(LobsSize)+" GB"
Recipient="bill.gates@microsoft.com"
Script = "gmail.vbs"

Set objshell = CreateObject("WScript.shell")
strCmd = Script &" "& Recipient &" """ &Subject&""" """  & Body &""""
result = objShell.Run( strCmd, 1, True)
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1466  
Old 02-22-2014, 11:12 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
@slugger - Where would you suggest I go to find more info regarding formatting for Groovlets? I have found that you can't just use your normal Groovy code as for some reason line breaks don't show up in web pages. So it appears that you have to use stuff like <p> on every line.

Where do I learn more about this? Or is there an easier way to do this, like dumping all of the output to a text file (or a large string) and then just outputting the text file to the web page?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1467  
Old 02-22-2014, 11:55 AM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Well the quickest way to get around this would be if it's just plain text you're always outputting then set the content type header in the response to text/plain. The "best" solution depends on what you're doing and how you're doing it.

For general Groovlet type stuff, just google J2EE servlets, which are the Java equivalent then from there focus on Groovlets to learn the "groovy shortcuts" available within Groovlets.

But if you have a groovy script that outputs plain text and you want the "poor man's way" to convert that to a groovlet for use in the webui, then just add a single line that sets the content type header and you should be good to go.

Create a test.groovy file in webserver/groovy/ on your system. Put this in it:

Code:
response.setHeader('Content-Type', 'text/plain')

100.times {
   println it
}
Run it once in your browser as is (/sage/test.groovy is the url) then comment out the first line and run it again. See the difference? Therefore, to easily "webify" a groovy script that just dumps output to stdout, all you probably need to do is just add that first line before any println statements are executed.

Now if you want the webui look & feel, menus, etc. along with the script's output, well then you need to wrap the output within the webui templates and that's a whole other direction requiring way more time and teaching than I have to give today. Though this should help you if you're trying to go in that direction.
__________________
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...

Last edited by Slugger; 02-22-2014 at 11:59 AM.
Reply With Quote
  #1468  
Old 02-22-2014, 01:06 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Some weird stuff going on... I am getting different behavior on IE11, IE10 and Chrome.

Initially when I tried to access test.groovy web page with the code above from a very new PC with win7x64 and IE11 it thinks you are trying to download a file and asks if you want to Open or Save test.groovy. If you say open then it gives you a text file opened in Notepad. It does not do that when you comment out the setHeader line. So something is f'ed up in IE11 or in my IE11 config for text/plain files

On another PC running IE10 and on Chrome on either PC I didn't have these issues and I am getting the expected output - number 1-100 either on one line or separate lines.

When I change the content type to text/html I don't get the dialog in IE11 but I do get everything on one line in all browser, IE10,11 and Chrome.

Weird...
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1469  
Old 02-22-2014, 03:10 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
When I change the content type to text/html I don't get the dialog in IE11 but I do get everything on one line in all browser, IE10,11 and Chrome.

Weird...
It's not weird, it's IE! (I should probably trademark that!)

Yes, that's weird, most browsers don't download text/plain, they just display it in the browser. IE11 is the exception if that's the default or some setting's been changed to cause it. I mean the other fix, which is a little less ideal is to:

Code:
response.setHeader('Content-Type', 'text/html') // This is the default so is redundant in this case; only set if not using text/html

println '<html><head><title>Test Page</title></head><body><pre>'

100.times { println it }

println '</pre></body></html>'
That should get you the same result as text/plain, just way more overhead. And then if you were going to produce html output then don't do it by hand, use the Groovy MarkupBuilder class, unless it's a really small page you're building then MarkupBuilder might be overkill, though always safer.
__________________
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...

Last edited by Slugger; 02-22-2014 at 03:12 PM.
Reply With Quote
  #1470  
Old 02-22-2014, 10:45 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I just got around to applying your updates of the web UI and SJQ web UI from a few weeks ago and I am having a problem.

When I click on any of the SJQ menu items in the Web UI I get a 404 Not found error such as:
Problem accessing /sage/sjq4.groovy. Reason: NOT_FOUND

But it looks like the file it should be accessing is /sage/sjq/sjq4.groovy

Any reason why I would be getting this error?

I upgraded the Web UI, ignored the restart Sage as I then immediately updated the SJQ Web UI and then restarted the Sage service.

What do you mean in the description for the SJQ web UI where you say "Load it via the /sage/sjq/sjq4.groovy URI in your SageTV web UI"

And I don't see any of the JVM stuff. The webserver jar is dated Jan 27 and the footer reports version 2.42. The down arrows on the menu items have disappeared and I now see kind of a drop shadow effect.

Here are the files that I see in the webserver/groovy/sjq directory:
Code:
01/26/2014  05:47 PM             1,611 ajax.groovy
01/26/2014  06:07 PM             6,629 sjq4.groovy
01/15/2012  04:56 PM             4,000 sjq4_clients.gsp
01/15/2012  04:56 PM             1,019 sjq4_crontab.gsp
01/15/2012  04:56 PM             1,539 sjq4_c_mod.gsp
01/15/2012  04:56 PM             4,203 sjq4_c_task_edit.gsp
01/15/2012  04:56 PM             1,131 sjq4_events.gsp
01/15/2012  04:56 PM               287 sjq4_log.gsp
01/15/2012  04:56 PM               590 sjq4_menu.gsp
01/26/2014  05:51 PM             3,774 sjq4_queue.gsp
01/15/2012  04:56 PM             4,065 sjq4_view.gsp
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1471  
Old 02-22-2014, 11:14 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Sounds like your browser is caching the old files. Force a reload of the site via Shift+Refresh in Chrome/FF or Ctrl-Refresh (I think) in IE. Or go to your browser settings and clear your cache.

Might also be a plugin installation problem with the Sage core. Go to SageTV/jetty/webapps/nielm_sagewebserver/webapp/

In there is a file called ddmenu.txt. Have a look at it, you should see references to the new menu items (Restart Sage, Run GC, etc.). If not, the plugin didn't update properly, if so then it's a browser cache issue.
__________________
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
  #1472  
Old 02-23-2014, 11:02 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Frackin' caches! That was the problem.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1473  
Old 02-23-2014, 11:04 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
From within a Sage job that runs on my server I want to queue up a Sage Job on a remote client - is there any well to tell in Groovy if the client is alive before I try to submit the job? Within the Sage UI I can ping it or see the green circle, but how do I tell this from code?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1474  
Old 02-23-2014, 11:21 AM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
Originally Posted by wayner View Post
From within a Sage job that runs on my server I want to queue up a Sage Job on a remote client - is there any well to tell in Groovy if the client is alive before I try to submit the job? Within the Sage UI I can ping it or see the green circle, but how do I tell this from code?
You're going to have to experiment because I really barely remember how any of this code actually works, it just works in the background for me so I really haven't looked at it in 2+ years.

Anyway, the javadocs for the SJQv4 stuff are here:

http://sagetv-addons.sourceforge.net/javadocs/sjq/

And a quick browse of those found this, which is probably what you'll need:

http://sagetv-addons.sourceforge.net...shared.Client)

Although, you don't really need to verify if a client is alive before submitting a job. The queue will hold the job until a client capable of running it is available.
__________________
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
  #1475  
Old 02-23-2014, 11:54 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I just want to be safe to see if the client is alive as I look to do my encoding on my fastest PC.

Maybe I am dumb at reading documentation but why do I get "No such property ServerClient" with the following code:
Code:
import com.google.code.sagetvaddons.*
println ServerClient.getAllClients().toString()
Do I have the right prefix in ServerClient? If not how do I determine the prefix from the documentation page?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1476  
Old 02-23-2014, 01:30 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
Originally Posted by wayner View Post
I just want to be safe to see if the client is alive as I look to do my encoding on my fastest PC.

Maybe I am dumb at reading documentation but why do I get "No such property ServerClient" with the following code:
Code:
import com.google.code.sagetvaddons.*
println ServerClient.getAllClients().toString()
Do I have the right prefix in ServerClient? If not how do I determine the prefix from the documentation page?
com.google.code.sagetvaddons.sjq.network.ServerClient or replace ServerClient with a '*'. If you look at the top of the javadoc page for the class you're looking at, it'll show you the package hierarchy it belongs to, which is where I got that from. Also, a .* is not recursive in import statements.
__________________
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
  #1477  
Old 02-23-2014, 02:40 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Ok, this works:
Code:
import com.google.code.sagetvaddons.sjq.network.ServerClient
ServerClient clnt= new ServerClient()
clients= clnt.getAllClients()
println clients
clnt.close()
The result looks like this:
[Client[host=Carnoustie:23344,state=ONLINE,lastUpdate=2014-02-23 15:03:21.483], Client[host=192.168.1.95:23344,state=ONLINE,lastUpdate=2014-02-23 15:03:22.181], Client[host=192.168.1.93:23345,state=ONLINE,lastUpdate=2014-02-23 15:04:20.169]]

I guess I just now have to figure out how to work with these clients.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #1478  
Old 02-23-2014, 03:01 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
Originally Posted by wayner View Post
Ok, this works:
Code:
import com.google.code.sagetvaddons.sjq.network.ServerClient
ServerClient clnt= new ServerClient()
clients= clnt.getAllClients()
println clients
clnt.close()
The result looks like this:
[Client[host=Carnoustie:23344,state=ONLINE,lastUpdate=2014-02-23 15:03:21.483], Client[host=192.168.1.95:23344,state=ONLINE,lastUpdate=2014-02-23 15:03:22.181], Client[host=192.168.1.93:23345,state=ONLINE,lastUpdate=2014-02-23 15:04:20.169]]

I guess I just now have to figure out how to work with these clients.
It's all in the javadocs, right? Now you've pulled out all the registered Client instances so head over to the javadocs for Client and see what you can do with those and so on until you just know the api (for what you need to do). But remember, SJQ is Java and you're coding in Groovy, which really opens up a lot of "groovy" shortcuts here. I mean, you want to find if a specific client is online in Groovy? I don't even need to look at the api to pretty much guess what that code will look like:

Code:
import com.google.code.sagetvaddons.sjq.shared.*
import com.google.code.sagetvaddons.sjq.network.*

// Let's see if client '192.168.0.100:23344' is online
def svr = new ServerClient()
println svr.getAllClients().find { it.host == '192.168.0.100' && it.port == 23344 && it.state = Client.State.ONLINE }.size() == 1
svr.close()
That should print true or false.

** I don't need to look because I'm assuming my Client class is written in my standard fashion of getters and setters. Honestly, I actually did peek at the javadocs just to make sure my example is actually right, and it is.
__________________
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...

Last edited by Slugger; 02-23-2014 at 03:05 PM. Reason: Shame on me... always close the server connection! ;)
Reply With Quote
  #1479  
Old 02-23-2014, 03:48 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Metaprogramming

Like I said, groovy opens up so many cool little tricks. Now cool is subjective, and perhaps only the computer scientists/software engineers in the crowd will think this stuff is cool, but if nothing else it's powerful.

Take the example code in my last post. If what you're working on is somewhat large or you're going to need to determine if a client is online in many places in whatever you're working on then wouldn't it be nice if you could just ask a client if it's online instead of having to use that closure all over the place (or creating some function in your script that refactors the check)? The SJQv4 API doesn't provide these features (as the javadocs show), but with groovy you can dynamically extend an API at run time, even APIs for which you don't have the source code available! This is truly groovy!

Code:
import com.google.code.sagetvaddons.sjq.shared.*
import com.google.code.sagetvaddons.sjq.network.*

// Add some helpers to the SJQv4 API
ServerClient.metaClass.isClientRegisteredAndOnline = { String host, int port ->
    getAllClients().find { it.host == host && it.port == port && it.online } != null
}
Client.metaClass.isOnline { -> delegate.state == Client.State.ONLINE }
// Done metaprogramming -- GROOVY!!

def svr = new ServerClient()

// So now to find out if a specific server is online, it's simple
svr.isClientRegisteredAndOnline('sagetv2', 23345)

// Now Client instances all have a boolean property to determine if they're online
svr.getAllClients().each {
    println "$it.host:$it.port is ${it.online ? '' : 'not'}online!"
}

svr.close()
With those 4 lines of code at the beginning, I added new functions to the SJQv4 API at runtime, which can make my groovy code more compact, cleaner and easier to maintain. Again, I added methods to the SJQv4 API without having access to the actual source code!!
__________________
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
  #1480  
Old 02-23-2014, 04:00 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Thanks Slugger, I am/was an engineer so I find this stuff cool. But I am away in Whister for a week so I wouldn't get a chance to delve into it any further for a few days.

The reason for doing this is to have file pre-processed on my server and the. Legit hand heavier encoding tasks off to a faster CPU that can use QuickSync for encoding to mp4. My newest CPU with QuickSync is 10X faster and the encoding.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
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: MizookLCD (Alternate SageTV LCDSmartie Plugin) cslatt SageTV Customizations 48 06-11-2012 10:44 AM
SJQv4: Technology Preview Slugger SageTV v7 Customizations 39 12-17-2010 01:17 PM
SageTV Plugin Developers: Any way to see stats for your plugin? mkanet SageTV Software 4 12-12-2010 10:33 PM
MediaPlayer Plugin/STV Import: Winamp Media Player Plugin deria SageTV Customizations 447 12-11-2010 07:38 PM
SJQv4: Design Discussion Slugger SageTV v7 Customizations 26 10-18-2010 08:22 AM


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


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