1、SOAP/RPC风格的Webservice(通过XFire),Hessian, PHPRPC都需要Servlet模型的支持,但是Play!不支持Servlet(或许有变通的方法?),所以,还是使用RMI这种技术
2、Play!的Model类,不是纯的POJO,继承了JPASupport,作为远程对象传递时,可能会产生
这样的错误,因此,要定义 POJO的VO/DTO对象,做为远程传递对象
3、VO对象,因为要通过RMI传递,必须要实现Serializable接口,并且最好在类中指定serialVersionUID,象这样
4、通过Spring封装并提供RMI的服务。需要自定义一个job,随Play!启动而启动,初始化RMI服务,象这样
5、RMI实现类,无法象Play!的Controller类一样,直接调用Model对象,Guillaume Bort的解释是
需要使用以下的变通方法
2、Play!的Model类,不是纯的POJO,继承了JPASupport,作为远程对象传递时,可能会产生
10:38:16,956 ERROR ~ failed to lazily initialize a collection of role: models.User.posts, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: models.User.posts, no session or session was closed这样的错误,因此,要定义 POJO的VO/DTO对象,做为远程传递对象
3、VO对象,因为要通过RMI传递,必须要实现Serializable接口,并且最好在类中指定serialVersionUID,象这样
private static final long serialVersionUID = 1L; 可以避免Server和Client之间同种对象版本不一样的错误4、通过Spring封装并提供RMI的服务。需要自定义一个job,随Play!启动而启动,初始化RMI服务,象这样
//注册RMI
play.modules.spring.Spring.getBean("postServiceRmi");5、RMI实现类,无法象Play!的Controller类一样,直接调用Model对象,Guillaume Bort的解释是
“I think that the RMI server call your code in a non managed thread.
You need to wrap your code in a play.Invoker.Invocation object. “需要使用以下的变通方法
So it is almost the same code than Jobs. Btw you could directly use jobs:
public class RetrievePostsByUserJob extends Job<List<PostVO>> {
private Long id;
public RetrievePostsByUserJob(Long id) {
this.id = id;
}
public List<PostVO> doJobWithResult() {
... your code here
return list;
}
}
and then use the job in your RMI server:
public List<PostVO> getPostsByUserId(Long id) {
return new RetrievePostsByUserJob(id).now().get();
}
本文探讨了在Play框架中使用RMI技术的具体方法,包括解决Play框架不支持Servlet模型的问题、创建可序列化的VO对象以进行远程传递、利用Spring封装RMI服务以及在RMI实现类中调用Model对象的变通方案。
1480

被折叠的 条评论
为什么被折叠?



