A web server (Service object) is just one chunk of code in your program. There are no real limits on the other things that can be don in the same program. As mentioned, there are timer objects that can be used to trigger all sorts of events.
I currently have two servers running in tandem behind a load balancer. I use "watch files" to kill the process, update the jar, etc. No limits to the imagination to implement external control that way.
My server is launched by a looping script
#!/bin/bash
cd /usr/local/WebServer
rm -f STOPPED
while [ 1 -eq 1 ]; do
# check to end
if test -f off; then
echo Finished
touch STOPPED
rm -f off
exit 0
fi
# check for restart
if test -f drop; then
echo Restart
rm -f drop
sleep 10
fi
# check for update
if test -f BaseAppServer.jar; then
echo Update applied
fi
# check for update
if test -f BaseAppServer.jar; then
echo Update applied
rm -f server.bak
mv server.jar server.bak
mv BaseAppServer.jar server.jar
fi
# rotate console log
cd logs
rm -f console.log.7
mv console.log.6 console.log.7
mv console.log.5 console.log.6
mv console.log.4 console.log.5
mv console.log.3 console.log.4
mv console.log.2 console.log.3
mv console.log.1 console.log.2
mv console.log console.log.1
cd ..
#launch server
java `cat javaopts` -jar server.jar 1> logs/console.log 2>&1
done
And the java timer code is....
'
' No pipes so we use watch files for external control
'
Sub WFT_Tick
wft.Enabled = False
' look for watch files
If (File.Exists(var.Get("home"),"BaseAppServer.jar")) Then Fin
If (File.Exists(var.Get("home"),"off")) Then Fin
If (File.Exists(var.Get("home"),"drop")) Then Fin
If (File.Exists(var.Get("home"),"tick")) Then
Try
File.Delete(var.Get("home"),"tick")
Dim F As OutputStream = File.OpenOutput(var.Get("home"),"tock",False)
F.Close
Catch
Log("Tick/Tock file error")
End Try
End If
If DoCycle = 0 Then Fin ' Keep the code fresh and recycle app
DoCycle = DoCycle - 1
wft.Enabled = True
End Sub
public Sub Fin
var.Close
Log("")
ExitApplication
End Sub
So the functions I implement externally....
BaseAppServer.jar - I am upgrading the server and by dropping the new jar in the base directory, the shell script runs this one instead. It backs up the old file too.
off - trun the server off.
drop - just reload the server jar cold.
tick - creates a file called tock. It's used to test the server on being alive.
Like I said, you can use external files (this as a model) to do anything your imagination desires.