To Tatiana
PROJECT
REMOTE SERVICES IN OSGI FRAMEWORK USING RMI CONNECTION
Introduction
OSGi Service Platform Specification defines a container that supports and manages the all life cycle of specific Java application modules called bundles. Knopflerfish framework (KFF), Equinox/Eclipse framework and Oscar framework are a well known implementations of the OSGi Platform. The OSGi bundle can creates and runs services that are registered on the framework context and are became visible and accessible for the rest bundles of the framework.
Project Goal
The project goal is a creating a tool that allows bundles to watch and use a services running on remote OSGi framework by means of Java Remote Method Invocation (RMI). KFF has a SOAP connectivity kit for this but RMI approach has some advantages: simpler implementation, higher performance and easy using (you stay in Java standard environment only).
Architecture
The RMI connection between two remote frameworks is supported by two bundles:
RMIGate on server-side framework and RMIEntrant on client-side framework. Service intended to be remote and running on server-side framework is registered on this framework context. The service is also registered on remote framework by means of RMIGate connected to client framework RMIEntrant object. This service has to implement Remote interface (from RMI package) for that. After remote service was registered on client-side framework then other bundles of client framework can use the remote service in the same way as other local services and RMI nature of the service is hided for calling bundles. The component diagram fig. 1 represents the main objects participated in communication between two OSGi frameworks. 1. Server-side framework has followed components:
Fig. 1. Component diagram.
2. Client-side framework has followed components :
Suppose that both frameworks have an installed and started
HTTP Server bundle. RMI Gate Bundle has to be installed and started first on server framework. The Bundle instantiates RMI Gate , Service Tracker with RMIServiceTrackerCustomizer and HTTP downloader objects, starts local RMI registry and registers RMI Gate object on this. HTTP downloader registers its context (code base for RMI Class Loader) on HTTP Server service. ServiceTracker keeps references to started RMI services. After that RMI Entrant bundle can be started on client framework. RMI Entrant adds itself to RMI Gate and then RMI ServiceTrackerCustomizer of RMI Gate invokes RMI Entrant and registers all servers� RMI services. RMI Entrant in its turn registers ones on Bundle context of client framework. Now any bundles from client framework can access remote RMI services from server framework. Detailed description of the bundles code presents below. Implementation
The new developed rmi package resides in com.ak.osgi.service package. It consists of:
Fig. 2. Package diagram
Class diagrams do not need a match of comments. Ones can help to understand source code of the bundles
Fig. 3. RMI Gate class diagram
Fig. 4. RMI Entrant class diagram
The next sequence diagrams show the flow of operations and messages between the bundles.
Fig. 5. RMI Gate bundle Sequence diagram
Fig. 6. RMI Entrant bundle Sequence diagram
Let�s talk a few words about
rmiregistry . You do not need to run rmiregistry before starting of RMI Gate bundle. The bundle will try to run rmiregistry if the bundle could not detect it. But if you'd like run rmiregistry yourself it is OK - RMI Gate bundle detects it and will use already running instance of rmiregistry . Building and Deployment
The bundles are developed and built by Eclipse. Below you can find description of Eclipse project for RMI Gate and RMI Entrant bundles. Project name is 'RMI_Framework'. Project consists of two folders
Entrant and Gate with a few files and subfolders.
Fig. 7. Project folders
Let's look at manifest file for Gate bundle:
Manifest-Version: 1.0 The all entries of the file are usual except 'DynamicImport-Package'. The entry define a list of packages that will be scanned by package administrator of OSGi framework in run-time when class of this packages need to be loaded. Reason for this feature is : Gate bundle can not know when it starts what rmi services will register on framework after that. So Gate bundle have to have ability dynamically find and load classes of rmi services from other bundle that installed and started after RMIGate . If rmi services classes reside in com.ak.osgi.service.rmi.serviceimpl packages (which were defined for dynamic import) they are always visible for Gate bundle .Building of bundle jars:
Bundles are built by running Ant files build.xml. Build files for all project bundle have the same structure. It consists of a few targets :
Installation steps:
Samples
Now it is time to test connection between client and server framework. Eclipse project named 'RMI_services' represents two demo RMI services and bundle that calls the services. Services 'Demo1' and 'Demo2' are running on server framework and bundle 'caller' is running on client framework. Install and start 'Demo1' and 'Demo2' bundles on server-side framework. Start 'RMI_Gate' bundle or refresh its packages if it is already running. After that install 'Caller' bundle on client framework and start RMI_Entrant if not yet. Now start 'Caller' bundle and get in output window a response from remote services 'Demo1' and 'Demo2'
RMI Gateway bundle
RMI Gateway is a simple combination of RMI Gate and RMI Entrant. After RMI starts it create two objects RMIGate and RMIClient. RMIGate is waiting for incomming connections one or more remote client framework and RMIClient is trying to connect to remote framework as a client. Symmetrical RMI Gateway makes easer of configuration and maintenance of remote framework's connection. More detail description is comming in next project.
Equinox deployment of RMI Gateway
Equinox deployment of RMI Gateway bundle little bit differ from above KFF. First the system and bundle properties resides in %INSTALL-DIR%/eclipse/plugins/configuration/config.ini. For example deployment of client requires following properties :
For server deployment : To run Equinox framework execute this script : Before install and run RMIGateway bundle you have to install the folowing bundles: Oscar deployment of RMI Gateway
The system properties resides in %INSTALL-DIR%/lib/system.properties and bundle properties in %INSTALL-DIR%/lib/bundle.properties. For example deployment of client requires following properties :
-- system.properties : -- bundle.properties : For server deployment : -- system.properties : -- bundle.properties : To run Oscar framework execute this script : Before install and run RMIGateway bundle you have to install the folowing bundles: Downloads
Do not forget to change configuration properties files of the downloaded jars (see installation instructions above). Better way is set this properties as system (using -D... or props.args)
Conclusion
Future enhancement of RMI bundles :
4 January 2006 (rev. 28 March 2006)
|