Reputation: 14053
here's my problem. I have a server that is started inside Eclipse, so the process is always running until I kill it.
If I want to execute a clean shutdown, I can write "shutdown" directly in the eclipse console and press enter. I need a clean shutdown (and not just a taskkill) because the server is supposed to send a snmp trap before it closes.
What I want to know is, is it possible that the "shutdown" could be written in the console as an input directly from a java method (stopServer()
)?
This is for tests purpose and it has to be automated. And there is no possibility to write a script that would do that.
Thank you.
Upvotes: 0
Views: 502
Reputation: 11308
How about the stopServer()
method containing all the shutdown logic, and making the shutdown command just another way to call the stopServer()
method. That is way easier than sending the command to the console.
Upvotes: 0
Reputation: 7349
Is this a JavaEE server you're setting up and tearing down? If so have you looked into Cargo ? It has lots of functionality to setup, deploy, and tear down containers both in code (in your JUnit beforeClass/afterClass) and/or through a maven plugin as well.
Upvotes: 1
Reputation: 1569
Unless you are not sure that your server can read the input command why even bother doing it with the text command? The text command is only a human readable/interactive form of the functioncall right? Maybe I don't really get what you want, but to me it seems easier to just write a signalhandler that always does the clean shutdown.
If you really wanted to do it, you could probably do it by writing to STDIN though (basicly what the console does).
Upvotes: 1