Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

perl script sending signals to java

 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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.

Could you please suggest how is that possible.

Mayank.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I'm no Perl guru but can't you just get perl to execute 'java <arguments> <program>' on the 'command line'?
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Touching a File option i have tried and it doesnt fir my requirements. Do you have any idea about handling signals in java?
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can have a thread or say a quartz driven timer to simply check the name of the file every x seconds.
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used the non standard API for the time being (to handle the signals) rather than going through the pain of the Native code.

Thank You.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic