I have a perl program writing to a flat file and a java file reading from it. At some point of time the perl program should send a signal to the java program and the java on reading it should perform certain action on the flat file.
I dont want to execute the java program from perl. i want to send a signal from perl to an already running java app. The java app has to do some signal handling and take action according to that. Is it possible?
Again, I'm not sure of the 'Perl interacting with Java' capabilities, but is there a common protocol they can talk over? e.g. RMI? Web Services? Heck even get Perl to Touch a File and the Java program has a thread which detects the file time stamp changing?
Could you please let me know something about how to handle signals in java and if perl signals can be handled as well. I tried searching but couldnt get much information. Could you please provide some pointers.
mayank gupta wrote:Could you please let me know something about how to handle signals in java and if perl signals can be handled as well. I tried searching but couldnt get much information. Could you please provide some pointers.
You can't handle signals in 100% Java; the standard libraries have no signal-related capabilities at all. You might be able to use native code to handle signals, especially if you write main() in C and create a JVM from your C code. Even there, though, the JVM library does some signal handling itself (mostly just crash-protection) and your added handlers may either break things or not work properly.
Instead of using signals, let the Java program create a ServerSocket to listen on a well-known port; create a Thread dedicated to listening on that socket, in a loop. Then let that thread handle a simple command language. It's a simple matter, then, for your Perl program to connect to that socket and send the desired command(s).
Thank you for the suggestion. Is there any other way in which I can let the java program be informed when another program(perl) is renaming a file. I am not too sure about socket programming in java so it would be really nice if we could come up with something else.