简体   繁体   中英

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. 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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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