Krzysztof said:
Could you point me to description how RMI RPC mechanism is realized
without reflection?
I don't have a technical description close at hand, but no reflection is
needed because the object types are well known at compile time and the
RMI server remote object, and stub object work together to sort things out.
And about plugin mechanism: Plugins to my application must implement
given interface and it must have entry in XML file. Then the
application can load them. What other plugin mechanism can you propose?
Now I noticed that Eclipse IDE have similar (bigger) plugin system.
Do please recognize that I rather specifically advised you against
reflective *method invocation*. Avoiding that morass is quite feasible
in a plugin system. You cannot get away from reflective object
instantiation if you do not know the actual class at compile time, but
that is more tractable ground.
A typical plugin framework works like this:
(1) the application specifies a Java interface that plugin classes must
implement.
(2) at runtime, the application instantiates specified plugins
reflectively, using a constructor of application-specified signature
(3) the application assigns the reference obtained in (2) to a variable
having the interface (1) as its declared type
(4) the application exercises the plugin's behaviors via normal Java
method invocation through the methods defined by the interface
I would appreciate help
Here is what I want to do:
There is server and many clients. Each connection between client and
server is made on SSL sockets. The goal is to write mechanism (develop
interfece) that other people can write their own modules (plugins)
using that interfece. That mechanism should allow modules to invoke
methods client -> server and server -> client asynchroniously to the
corresponding module on server/client side (which does something e.g.
access to database etc.) I implemented something like XML-RPC but with
difference that methods can be invoked on existing connection in both
directions. Of course each object on which methods can be called
remotly must be registered.
So this isn't just "like Remote Procedure Call"; you are planning a bona
fide RPC mechanism. I would recommend that you study existing RPC
mechanisms (Java RMI, Sun RPC), and also consider a web services
approach. Do note that supposedly you can use RMI over SSL connections;
the JSDK docs include a document entitled "Using a Custom RMI Socket
Factory" that might get you started if you wanted to consider just using
RMI instead of rolling your own.
The "classic" RPC approach uses a stub object on one end of a connection
to represent and interact with a real object on the other end. Two-way
interaction is possible. There might need to be a coordinator running
on one or both sides to establish a connection between the two, and one
or both might need to extend some specific class so as to obtain the
connection infrastructure. You might need to have an extra code
generator / compiler that you run after the Java compiler (ala the RMI
compiler, rmic). This is all very well if someone else builds it for
you, but it is a substantial and tricky undertaking for you to do
yourself, which leads me to...
Web services. This might just be the way to go. You can get free Java
web services stacks (Apache offers one) or purchase them from several
companies (IBM, I think Bea, probably Oracle). Web services is pretty
much just another flavor of RPC, and you could probably build on top of
that. Web services certainly works with SSL connections, and SOAP
didn't get its name (Simple Object Access Protocol) for nothing. Web
services can conduct extended sessions of two-way conversation, and
communication endpoints can be bound to specific objects if necessary.
(I speak somewhat by faith on that last point.)
But from your comments it sounds like you have something already that
either works or almost does. If that's true then I'm impressed. If the
last detail is to work out this method signature problem, and the XML
files are programmatically generated rather than human-generated, then
I'd say just put the declared types of the desired method's arguments
into the XML file and use them to select the correct method. Don't try
to infer from the arguments -- your code will be error-prone, if you
mange to get it working properly then it will be brittle.