Trying to find an approach to perform some regular house-keeping in a Worklight Server. Simplified scenario:
We have an adapter talking to a back-end system. When user authenticates with Worklight they create some credentials that are passed to the back-end on each service call. Those credentials can become stale if not used for a period of time. Hence what we want is a "heartbeat" for all active sessions. I have a singleton Java object in which I stash the credentials when the user authenticates, what I want to do is have some kind of background worker thread to iterate the list of credentials and make a heartbeat call to the server.
I end up with adapter methods like this
// in business service adapter
businessMethod(){
make service call using credentials from user's Worklight session
}
// in authentication adapter, normal adapter authentication methods and a heartbeat
authentication(){
get back-end credentials
store credentials in user's session
stash credentials in singleton
}
// how do we cal this heartbeat every x min
heartbeat(){
for each credential in singleton stash
make heartbeat call to server keeping credential alive
}
The question is: how do we trigger that heartbeat. I've tried using a Java TimerTask, which nearly works. I can arrange that the Java TimerTask will call my heartbeat. The problem is that when running under the TimerTask we don't have a normal Worklight Server environment, calls to WL.Server.invokeProcedure() throw exceptions, and thinking about this it's seems unlikely that I would have access to the normal Worklight APIs from effectively a foreign thread.
We are using Worklight 6.1, deploying on a WebSphere Liberty server. At present best I can think of is to write some external mini-application or shell script that periodically calls the heartbeat() method.
Any better suggestions?