RMI on-the-fly
Exposing methods within an RMI-server is a common requirement in distributed applications. Each method requires a definition in an interface extending Remote (for use by the clients) and an implementation extending UnicastRemoteObject implementing this interface (for the server side). Usually, the implementation simply invokes the original method to be exposed.However, larger applications with lots of methods make this a tedious and error-prone process. Fortunately, wurblets can do that automatically!
Analyze and Generate
A wurblet requires access to a method's signature so that it can create the necessary RMI code. This is accomplished in two steps:- An annotation on the method gathers the signature information.
- The wurblet takes this information to generate the appropriate source code.
The original method with the added annotation @Analyze and the wurblet RemoteMethod looks like this:
The generated interface code:
The generated implementation code:
Notes
- Both, the @Analyze annotation and the RemoteMethod wurblet are part of the Tentackle framework.
- In fact, the wurblet will also generate code that allows a transparent usage of the method, no matter whether it's remote or local. It also has detailed knowledge of how to deal with certain java types, like database objects, collections, etc...
- Furthermore, the wurblet will not only generate the methods but also create the RMI-classes, if they do not exist already.
