【发布时间】:2014-04-11 06:00:55
【问题描述】:
试图找到一种方法来在 Worklight Server 中执行一些常规的内务管理。简化场景:
我们有一个适配器与后端系统通信。当用户使用 Worklight 进行身份验证时,他们会创建一些凭证,这些凭证会在每次服务调用时传递到后端。如果一段时间不使用,这些凭据可能会变得陈旧。因此,我们想要的是所有活动会话的“心跳”。我有一个单例 Java 对象,当用户进行身份验证时我将凭据存储在其中,我想要做的是有某种后台工作线程来迭代凭据列表并对服务器进行心跳调用。
我最终得到了这样的适配器方法
// 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
}
问题是:我们如何触发心跳。我试过使用 Java TimerTask,它几乎可以工作。我可以安排 Java TimerTask 将调用我的心跳。问题是当在 TimerTask 下运行时,我们没有正常的 Worklight Server 环境,对 WL.Server.invokeProcedure() 的调用会引发异常,考虑到这一点,我似乎不太可能从实际上是一个外来线程。
我们使用 Worklight 6.1,部署在 WebSphere Liberty 服务器上。目前我能想到的最好的办法就是写一些外部的小程序或者shell脚本,定期调用heartbeat()方法。
有更好的建议吗?
【问题讨论】:
标签: ibm-mobilefirst worklight-server