Advanced Java Spring Questions & Answers on “Getting Started with OSGi”.
1. OSGi—which was formerly known as the:-
a) Open Services Gateway initiative
b) Open Source Gateway initiative
c) Open Services Gateway initialisation
d) None of the mentioned
Answer: a
Clarification: OSGi—which was formerly known as the Open Services Gateway initiative, though the name’s obsolete now—has its roots in the embedded space, where dynamic service provisioning is far more important than it is in the gridiron world of enterprise applications.
2. OSGi provides a layer on top of the JVM’s default class loader.
a) True
b) False
Answer: a
Clarification: The deployment unit for OSGi is a bundle, which is essentially a JAR with an augmented MANIFEST.MF.
3. On top of Spring Dynamic Modules, SpringSource built SpringSource dm Server, which is a server wired from top to bottom with OSGi and Spring.
a) True
b) False
Answer: a
Clarification: SpringSource dm Server supports dynamic deployment, enhanced tooling, HTTP, and native .war deployment.
4. OSGi is a framework.
a) True
b) False
Answer: b
Clarification: OSGi is a specification, not a framework. There are many implementations of the specification, just as there are many implementations of the Java EE specification.
5. User component models are:-
a) OSGi
b) Spring
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: OSGi is not a user component model, like Spring or EJB 3. Instead, it sits below your components, providing life-cycle management for Java classes.
6. In OSGi, anything used by something else is a state.
a) True
b) False
Answer: b
Clarification: In OSGi, anything used by something else is a service. “Service” doesn’t imply any concrete inheritance.
7. “Service” doesn’t imply any:-
a) RPC
b) inheritance
c) transactional qualities
d) all of the mentioned
Answer: d
Clarification: “Service” doesn’t imply any concrete inheritance; it doesn’t imply transactional qualities, and it doesn’t imply RPC. It’s merely a class on whose concrete, black-box functionality and interface your class relies.
8. OSGi bundles are simply standard .jar files with customized MANIFESTs that OSGi consumes at runtime.
a) True
b) False
Answer: a
Clarification: The plug-in wraps the bnd command line tool.
9. Tool which dynamically interrogates classes for their imports and generates OSGi–compliant entries.
a) pnd
b) jndi
c) bnd
d) none of the mentioned
Answer: c
Clarification: We repeat it here mainly for illustrative purposes.
10. The plug-in produces OSGi–compliant bundles that work in any container.
a) True
b) False
Answer: c
Clarification: To read more on the plug-in itself, see http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html.
11. The Bundle-Activator directive describes to the OSGi environment, which class implements :-
a) BundleActivator
b) BundleActivate
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: The Bundle-Activator directive describes to the OSGi environment, which class implements BundleActivator, and should be consulted when life cycle events occur.
12. When the bundle begins to load and start, it calls the start method of the:-
a) BundleActivator
b) Activator
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: When the bundle begins to load and start, it calls the start method of the Activator.
13. To start using Spring to smooth over some of the minutiae of resource acquisition and to help build more reliable systems in an OSGi environment.
a) Spring DM server
b) Spring Dynamic Modules
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Use Spring Dynamic Modules to provide the integration. Spring Dynamic Modules is a framework on top of OSGi that works with any OSGi environment.
14. Spring Dynamic Modules scans our deployed bundles and loads an ApplicationContext (actually, the specific type of the ApplicationContext is OsgiBundleXmlApplicationContext) into memory based on an event, or a trigger.
a) True
b) False
Answer: a
Clarification: There are two ways to trigger this behavior. The first is to explicitly specify in the META-INF/MANIFEST.MF file the attribute Spring-Context, which allows you to override the default location it consults. Otherwise, by default, Spring Dynamic Modules will look for the XML file in the META-INF/spring directory of a bundle.
15. You’ll split your OSGi–specific Spring configuration and your plain-vanilla Spring configuration into:-
a) modulename-context.xml
b) modulename-osgi-context.xml
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: Typically, you’ll split your OSGi–specific Spring configuration and your plain-vanilla Spring configuration into two different files, of the form: modulename-context.xml and modulename-osgi-context.xml.
To practice advanced questions on all areas of Java Spring,