BundleBee delegates calls the object methods to other nodes in the grid. Therefor it has to call these methods remotely which consequently is called 'remoting' then. This is done by intercepting the method call by means of bytecode manipulation at load-time (see Classloading/Aspectweaving).
The interceptor code does the following:
- find a node that can execute the bundle
- eventually let it download and install the bundle
- local: serialize all parameters
- local: http-POST the classname, methodname and serialized parameters to the remote nodes URL
- remote: read the classname
- remote: query OSGi for a service with that classname
- remote: deserialize the paramters with the classloader of the service
- remote: invoke the method from its name on the service object with the parameters
- remote: serialize the result and send it as a reponse
- local: deserialize the response with the classloader of the calling object
- local: return result
For this is the basic procedure, reality has to get along with a lot of corner cases (void, primitives, timeouts, exceptions....).
Currently BundleBee can only remote calls that are registered as 'services' on the remote side (and hence on the local side bc. the same bundles are used locally and remotely).
Remote call dispatching¶
The call is transferred by http and arrives at a servlet called
ServiceMethodCallServlet located in the
manager bundle. The bundle does the actual service lookup and call to the service object. Thinking of OSGi classloading rules, this sound problematic because the
manager bundle is generic and maintains no dependencies to the application bundles (see
The key is that
manager resolves services anonymously. This in fact is only possible because no
Import-Package for the desired service is actually declared by the
manager bundle. Due to this, all matching services can be found.
Side note: if a bundle defines
Import-Package for a service, it will only get the best matching (that is: highest version) service object.
Finding the correct service object¶
OSGi allows the same bundle to be installed on different version on a single node. Thus, a remote call has to exactly map versions on the local and remote side.