简体   繁体   English

封装Java RMI远程方法

[英]Encapsulate Java RMI remote methods

I wanna do a service that distributs tasks amongst several servers, which execute those tasks. 我想提供一项在多个服务器之间分配任务的服务,这些服务器将执行这些任务。 To do that, I made use of the Java RMI technology and all works just fine, but it is a mess. 为此,我使用了Java RMI技术,并且一切都很好,但这很混乱。 I have a big class, which is mixed with remote methods which are called by the servers to post messages and client methods to schedule tasks to the service which are called by the client. 我有一个大类,其中混合了由服务器调用以发布消息的远程方法和由客户端方法将任务调度到服务的客户端方法,这些方法由客户端调用。

I am now trying to find a proper solution to encapsulate the remote methods from the business methods, but struggle as they are thighly coupled. 我现在正试图找到一种合适的解决方案,以将远程方法与业务方法封装在一起,但是由于它们之间的高度耦合而难以解决。 The message implementation (see the example class diagramm) interacts thightly with the private business methods. 消息实现(请参见示例类图)与私有业务方法紧密交互。 This might also include invoking events which the Client class subscribed. 这可能还包括调用Client类订阅的事件。 My first thought was the approach with a message handler. 我的第一个想法是使用消息处理程序的方法。 But how can the message handler still interact with private methods of the server and invoke events on the service. 但是消息处理程序如何仍能与服务器的私有方法交互并调用服务上的事件。

I like to ask you if you have any idea for my problem. 我想问你是否对我的问题有任何想法。 How can I encapsulte the remote interface and its methods from the non remote methods? 如何从非远程方法封装远程接口及其方法?

在此处输入图片说明

If I understand the problem correctly, you have a big class with three kinds of method:- 如果我对问题的理解正确,那么您可以通过以下三种方法来学习:

  1. Remote methods intended for use by the client, but not by the server; 旨在供客户端而非服务器使用的远程方法;
  2. Remote methods intended for use by the server, but not by the client; 供服务器而非客户端使用的远程方法; and
  3. Local methods not intended to be remote at all. 本地方法根本不会成为远程方法。

It seems to me that creating two remote interfaces (one for the client, one for the server) and implementing them both in the big class will do what you want. 在我看来,创建两个远程接口(一个用于客户端,一个用于服务器)并在大型类中实现它们都可以满足您的要求。 The client will only see one interface and the methods in it; 客户端只会看到一个接口及其中的方法。 similarly for the task server. 对于任务服务器也是如此。

Is that enough encapsulation? 足够的封装吗? Or did you mean something more? 还是您意思更多?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM