Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: Java code called on completion?

  1. #1
    Join Date
    Apr 2007
    Posts
    2,010

    Default Java code called on completion?

    Hi,

    I call java code from javascript in my transformation, running in the platform.

    What I want to do is run some end clean up / logout code once the transformation has finished.

    Will the code discussed here apply:

    http://www.exampledepot.com/egs/java.lang/ExitHook.html

    Or when you're in the platform does it not shutdown as such?

    Essentially what i'm doing is batching up updates in the java code. So; I need a way to do a final persist at the end to ensure the final incomplete batch gets added too. I _could_ presumably call a kind of finish job from my kettle job I guess, but what if the job itself crashes or aborts abnormally? I'd still lose the batch so far...

    Thanks,
    Dan

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    I don't think you use the exithook in a safe way. And even if it would, problem is still the same... what would happen if someone killed your JVM right before it wants to execute its exithooks?

    Extra job, and changing your procedure in such a way you get more guaranteed "closure".

    Regards,
    Sven

  3. #3
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    Ok, thats fine - I'm not (yet) a java dev by trade so just checking

    I understand if the VM dies i'm screwed anyway! but actually in this case the job will just pick up the ones which havent moved across on the next schedule anyway.

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    You can always add a TransListener to Trans in the recent versions (3.1 and up IIRC):

    At the moment this interface is rather simple:

    Code:
    public interface TransListener {
        public void transFinished(Trans trans);
    }
    Matt

  5. #5
    DEinspanjer Guest

    Default

    I'll also throw in one other suggestion. You say that you are currently invoking Java code within a Javascript Step in your transformation. You could try creating a new script tab in the JS step, right click on the tab and set it as an End Script. The script in that tab will then be executed after the JS step receives the last row from it's input step. This might be an easy way for you to do some cleanup/commit type stuff.

    Keep in mind that you'll have to test this out to decide if it works in all cases for you. The above problems of bad crashes and such hold true.

  6. #6
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    That works great - the end script thing, i didnt even know this was there!

    So; My only other question, is how do you create a new row in javascript in an end script? it seems there's no row to clone, so how do you create a blank one?

    Thanks!
    Dan

  7. #7
    DEinspanjer Guest

    Default

    Do a search in the forums for a post I made regarding "unique rows". I attached an example that has a javascript step that creates rows at the end.

  8. #8
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    Brilliant thanks, for others ref that post is here

    http://forums.pentaho.org/showthread...ht=unique+rows

    And the code is as simple as:

    newRow = [null,null,null]
    newRow[1] = xx

    etc...

    Hurrah, thanks VERY much!!!

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.