Is there a way of controlling the order in which OSGi bundles inside a fuse esb fabric feature are loaded so that later bundles are dependent on the complete loading of earlier ones? For example, in the following feature, I want the simple-client module to only start up once the previous bundles have fully loaded:
<features name="simple-service-features">
<feature>
<bundle>mvn:com.company/simple-datasource/0.0.0</bundle>
<bundle>mvn:com.company/simple-model/0.0.0</bundle>
<bundle>mvn:com.company/simple-service/0.0.0</bundle
<bundle>mvn:com.company/simple-client/0.0.0</bundle>
</feature>
</features>
You can use the attribute start-level of bundle tag in the features.xml to sequence the OSGI bundles start.
A start level is associated with every bundle. The start level is a positive integer value that controls the order in which bundles are activated/started. Bundles with a low start level are started before bundles with a high start level. Hence, bundles with the start level, 1, are started first and bundles belonging to the kernel tend to have lower start levels, because they provide the prerequisites for running most other bundles.
Related
To get started with OSGi, thought of asking this since this become unclear to me.
If you have runtime code change as a requirement, OSGi is probably the only possible way to achieve this using Java.
from https://mondula.com/2016/01/11/osgi-benefits-and-drawbacks/
How the runtime flexibility is maintained in OSGi technically?
This is a large question that would be impractical to fully answer here. The following is a simplified overview.
OSGi allocates a Java ClassLoader for each resolved bundle. When a bundle is updated, OSGi first sends a stop signal to the bundle, allowing it to release resources and prepare to be garbage collected.
The new bundle is then re-resolved against its requirements, which may have changed compared to the previous version. Assuming the new version still resolves (i.e. its requirements are still satisfied) then OSGi allocates a new ClassLoader, uses that to load the classes in the bundle, and if the bundle has an activator and was in ACTIVE state before the update, sends a start signal to the newly loaded activator.
I am developing a composite feature for Karaf (i.e. a feature that includes other features as nested elements). I want to write out configuration files for the nested features and then from the outer scope (i.e. the feature that I am writing), I want to restart the bundles included in the nested features.
How do I query a feature for all of its bundles at runtime from another bundle.
How do I dynamically restart a bundle from another bundle ?
For all two operations you need instance of org.osgi.framework.BundleContext - you can get one in your bundle activator.
To query features (and their dependent features and their bundles) you need access to Karaf's org.apache.karaf.features.FeaturesService OSGi service - for example using BundleContext's getServiceReference() method.
To get any bundle (to be able to restart it) you can get one knowing it's ID: BundleContext.getBundle("ID")
I have two bundles:
bundleName.2.0.0.324999.jar
bundleName.2.0.0-SNAPSHOT.jar
When I am trying to install them in Apache Felix console, the one which I am trying to install gets the priority.
So my question is, how does it decides the priority then?
You can install both of these bundles at the same time if you like. OSGi does not have a concept of "priority" between bundles.
I am trying to understand the capabilities of Fabric8's container management.
I just want to clarify weather the following scenario can be achieved by using Fabric8 in JBossFuse.
I have created simple 2 bundles (tick, tock bundles inspired by the : http://kevinboone.net/osgitest.html).
Simply Tick bundle is exporting a package and Tock bundle is importing it. In another words, Tock Bundle depends on the Tick Bundle.
These 2 bundles are working perfectly when deployed in a single container (say in a one child container in JBoossFuse).
Then I have created a cluster by using the fabric8 and added its containers to the Fabric Ensemble as well.
And I have created 2 profiles. TickProfile contains the Tick bundle and Tock profile contains the Tock bundle.
I have deployed above 2 profiles in 2 different containers as follows,
Then it is not working properly because Tock bundle cannot resolve its dependency of Tick Bundle which is exposed by Tick Bundle (because those bundles are in two different containers).
I thought this is possible with fabric8 but it seems it cannot.
It would be really appreciated if someone can tell me whether there is any way of achieving this.
Thanks.
No this is not possible. Package export and import on OSGi level is bounded to the JVM. This means bundles in different JVMs will not be able to import each others classes.
The only OSGi concept that supports clustering are Services. The OSGi specification calls that Remote Services.
See: https://wiki.eclipse.org/Tutorial:_Building_your_first_OSGi_Remote_Service
Eclipse implementation: https://wiki.eclipse.org/OSGi_Remote_Services_and_ECF
Apache implementation: http://cxf.apache.org/distributed-osgi.html
I have quite a sophisticated OSGi application which uses Declarative Services and was designed to be deployed in Equinox. Now the task is to make this application be deployable in WAS 8.
The first try was quite pragmatic: I have deployed an EAR which has started basically the same Equinox and after some WAS class loading policy tweaks it has worked.
Now I want to go further: get rid of the Equinox runtime and deploy my bundles "natively" in WAS 8. So I have composed an EBA, consisting out of my business bundles, their dependencies and Equinox DS runtime. The EBA is deployed as an asset and integrated into a BLA. The application has even started and runs but the components are not initialized.
The point is that one has to start equinox.ds in front of the own business bundles (UPDATE: not a must, s. discussion below) in order to make DS do its job. But how do I tell the bundles which is to be started first within the deployed EBA? I need some analog of Equinox' config.ini file.
I know I can rewire my components with natively supported Blueprint, but frankly this is the last thing I'd like to do. It should be possible to make Equinox DS work, shouldn't it?
Another question is: how to get the OSGi console for one's own application deployed under WAS 8? I want to control my bundles but seems that there is no way to do it from the Management Console.
UPDATE
Thanks to BJ and Neil (s. discussion below), the question takes down to "How do I start a specific bundle in my own OSGi application deployed in WAS 8.0?"
To answer the OSGi console part of your question, a normal OSGi console won't work because the OSGi applications are managed in nested frameworks. WebSphere provides its own console which can navigate the nested applications: http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.osgi.nd.multiplatform.doc%2Ftopics%2Fta_admin_runtime_console.html