Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

jnotify - fileCreated

Hallo all,
I finally managed to get jnotify working within TOS.
Now my problem is how to trigger a job that does the processing of the created file as tJava runs in an endless loop.
I do not want to stop tJava/jnotify as I would probabely loose one file.
Is there a posibility to call another TOS job from within tJava?
Any help very much appreciated.
kind regards
Hannes
----- Code within tJava (Test only) ---------------------------------------------------------------------------
// to add a watch :
String path = context.WatchPath;
int mask = JNotify.FILE_CREATED |
JNotify.FILE_DELETED |
JNotify.FILE_MODIFIED|
JNotify.FILE_RENAMED;
boolean watchSubtree = false;
int watchID = JNotify.addWatch(path, mask, watchSubtree, new JNotifyListener()
{
public void fileRenamed(int wd, String rootPath, String oldName, String newName)
{
System.out.println("JNotifyTest.fileRenamed() : wd #" + wd + " root = " + rootPath + ", " + oldName + " -> " + newName);
}
public void fileModified(int wd, String rootPath, String name)
{
System.out.println("JNotifyTest.fileModified() : wd #" + wd + " root = " + rootPath + ", " + name);
}
public void fileDeleted(int wd, String rootPath, String name)
{
System.out.println("JNotifyTest.fileDeleted() : wd #" + wd + " root = " + rootPath
+ ", " + name);
}
public void fileCreated(int wd, String rootPath, String name)
{
System.out.println("JNotifyTest.fileCreated() : wd #" + wd + " root = " + rootPath
+ ", " + name);
}
});

Thread.sleep(1000000);
// to remove watch:
boolean res = JNotify.removeWatch(watchID);
if (!res)
{
// invalid watch ID specified.
}
----end of Code -----------------------
Labels (3)
3 Replies
Anonymous
Not applicable
Author

Hello
Did you try to use tLoop or tInfiniteLoop to trigger the tJava ?
Best regards
Shong
Anonymous
Not applicable
Author

Hi Shong,
yes, a thought about this but thats not doing the job.
jnotify creats a listner which fires up when a new file is created in a specific directory and runs "public void fileCreated(int wd, String rootPath, String name)".
I am looking for a way to start the processing job of the newly created file without leaving tJava or more precise without interrupting the listener. - Kind of writing the filepath of the created file into a pipe which another asyncronously running job reads in.
Any idea how I can achive this?
Thanks in advance and kind regards
Hannes
Anonymous
Not applicable
Author

Hi Shong,
if you look at the code above, you can see that tJava runs in a very long Thread.sleep (in order not to waste processing power by polling the directory) while waiting for jnotify to signal the creation of a new file which happens to be in "public void fileCreated(int wd, String rootPath, String name)".
How can I interrupt the Thread.sleep from within "public void fileCreated" so that tJava ends normaly and continues with the next TOS module tFileInput?
Many thanks in advance for your support
Hannes