List of Listings

Chapter 1. OSGi revealed

Listing 1.1. Example of the limitations of Java’s object-orientated encapsulation

Listing 1.2. Basic greeting implementation

Listing 1.3. Extended greeting implementation

Listing 1.4. OSGi bundle activator for our greeting implementation

Listing 1.5. Implementation of the Greeting interface

Listing 1.6. OSGi bundle activator with service registration

Listing 1.7. OSGi bundle activator with service discovery

Chapter 2. Mastering modularity

Listing 2.1. Contents of existing paint program’s JAR file

Listing 2.2. Existing PaintFrame.main() method implementation

Listing 2.3. New launcher for smaller paint program configuration

Chapter 3. Learning lifecycle

Listing 3.1. Simple shell bundle activator

Listing 3.2. BundleContext methods related to lifecycle management

Listing 3.3. Bundle interface methods related to lifecycle management

Listing 3.4. Bundle configuration by example

Listing 3.5. Bundle install command

Listing 3.6. Bundle start command

Listing 3.7. Bundle stop command

Listing 3.8. Bundle update command

Listing 3.9. Bundle uninstall command

Listing 3.10. Bundle information example

Listing 3.11. Bundle persistent storage example

Listing 3.12. Bundle and framework event listener example

Listing 3.13. Example of how a bundle can stop itself

Listing 3.14. BundleTracker class declaration and constructor

Listing 3.15. Opening and using a BundleTracker

Listing 3.16. Disposing of a BundleTracker

Listing 3.17. Processing shapes in ShapeTracker

Listing 3.18. DefaultShape example

Listing 3.19. Bundle resolve command

Listing 3.20. Bundle refresh command

Chapter 4. Studying services

Listing 4.1. BundleContext methods related to services

Listing 4.2. OSGi Log Service

Listing 4.3. Broken lookup example—service instance stored in a field

Listing 4.4. Broken lookup example—service is only discovered on startup

Listing 4.5. Broken lookup example—testing the discovered Log Service

Listing 4.6. Broken lookup example—potential race condition

Listing 4.7. Correct lookup example

Listing 4.8. Broken listener example—caching the latest service instance

Listing 4.9. Broken listener example—existing services aren’t seen

Listing 4.10. Correct listener example—keeping track of active Log Services

Listing 4.11. Correct listener example—sending pseudo-registration events

Listing 4.12. Correct listener example—using the listener to get the best Log Service

Listing 4.13. Standard tracker example

Listing 4.14. Customized tracker example—decorated Log Service

Listing 4.15. Publishing a shape service

Listing 4.16. Sending shape events from ServiceTracker methods

Chapter 5. Delving deeper into modularity

Listing 5.1. Simple proxy logger using optional import

Listing 5.2. Bundle activator creating the proxy logger

Listing 5.3. Simple proxy logger using dynamic import

Listing 5.4. Method used to inject shapes into PaintFrame object

Listing 5.5. Original circle bundle activator with hardcoded name

Listing 5.6. Modified circle bundle activator with ResourceBundle name lookup

Chapter 6. Moving toward bundles

Listing 6.1. Default jEdit build target

Listing 6.2. jEdit mega bundle manifest

Listing 6.3. Bundle activator to manage the jeditresource handler

Listing 6.4. Using the extender pattern to install jEdit plugins

Listing 6.5. Using bnd to print imported and exported packages

Chapter 7. Testing applications

Listing 7.1. Broken service lookup containing a race condition

Listing 7.2. Simple container test

Listing 7.3. Using Pax Exam to run tests on an OSGi framework

Listing 7.4. Using Pax Exam to run tests on multiple frameworks

Listing 7.5. Basic configure-then-start integration test

Listing 7.6. Configuring the upgrade management test

Chapter 8. Debugging applications

Listing 8.1. Implementing the setColor() method for the triangle shape

Listing 8.2. Fixing the setColor() method

Listing 8.3. Audited spoke implementation

Listing 8.4. Audited spoke implementation with TCCL

Listing 8.5. Setting and resetting the TCCL

Listing 8.6. Leaky bundle activator

Listing 8.7. Delegating service proxy

Chapter 9. Managing bundles

Listing 9.1. Example of a managed service

Listing 9.2. ManagedServiceFactory example

Listing 9.3. ConfigurationAdmin service shell command

Listing 9.4. Implementing the cm list subcommand

Listing 9.5. Private method to initialize Configuration objects

Listing 9.6. Metatype Service shell command example

Chapter 10. Managing applications

Listing 10.1. Shape API bundle converted into OBR repository XML syntax

Listing 10.2. OBR repository shell command example

Listing 10.3. OBR resolver shell command example

Listing 10.4. Deployment Admin shell command example

Listing 10.5. Start Level Service shell commands example

Listing 10.6. Using the startlevel and bundlelevel commands

Chapter 11. Component models and frameworks

Listing 11.1. ServiceTracker handling one-to-one dependency on a service

Listing 11.2. Circle class used in the Declarative Services paint example

Listing 11.3. Declarative Services’ description of PaintFrame component

Listing 11.4. Metadata for WindowListener with optional LogService dependency

Listing 11.5. WindowListener with optional LogService dependency

Listing 11.6. Lifecycle-related code from Declarative Services PaintFrame class

Listing 11.7. Using a component factory

Chapter 12. Advanced component frameworks

Listing 12.1. Blueprint component definition for the circle component

Listing 12.2. Blueprint definition of the PaintFrame component

Listing 12.3. Callback methods used in the PaintFrame application

Listing 12.4. Converter class to coerce an Object to an AtomicReference

Listing 12.5. iPOJO declaration of circle component type using annotations

Listing 12.6. Bind and unbind methods for the iPOJO PaintFrame

Listing 12.7. Creating components using the component factory service

Listing 12.8. Creating components using Configuration Admin

Chapter 13. Launching and embedding an OSGi framework

Listing 13.1. Standard Bundle interface

Listing 13.2. Retrieving a FrameworkFactory service manually

Listing 13.3. Main class declaration for generic bundle launcher

Listing 13.4. Using a shutdown hook to cleanly stop the framework

Listing 13.5. Invoking the main class from the main bundle

Listing 13.6. Standalone paint program main() method

Listing 13.7. Creating the framework instance and deploying discovered bundles

Listing 13.8. Creating the paint frame and binding it to the framework instance

Chapter 14. Securing your applications

Listing 14.1. The ConditionalPermissionAdmin interface

Listing 14.2. Using the ConditionalPermissionUpdate to set permissions

Listing 14.3. Policy-file reader bundle activator start() method

Listing 14.4. BeforeDateCondition example

Listing 14.5. AskTheUser dialog box implementation

Listing 14.6. AskTheUserCondition implementation

Listing 14.7. AskTheUserCondition isSatisfied() method implementation

Chapter 15. Web applications and web services

Listing 15.1. ResourceBinder component class

Listing 15.2. Tracking HTTP resources in ResourceTracker

Listing 15.3. ProxyHttpContext for reading resources from a bundle

Listing 15.4. Binding servlets in the OSGi service registry using iPOJO

Listing 15.5. Binding servlets in the OSGi service registry using iPOJO

Listing 15.6. Binding servlets in the OSGi service registry using iPOJO

Listing 15.7. Binder to register JPS pages in the Pax Web WebContainer

Listing 15.8. Declarative Services component definition for JSP binder

Listing 15.9. Accessing the BundleContext from within a servlet

Listing 15.10. Reading stock prices from the StockProvider service

Listing 15.11. Reading stock prices from the StockProvider service

Listing 15.12. XML discovery file for the StockProvider service for Apache CXF

Listing 15.13. Constructing an exported service tracker

Listing 15.14. Dealing with new exported services

Listing 15.15. Checking if a service matches supported intents and configurations

Listing 15.16. Checking the exported interfaces of a service

Listing 15.17. RegistryWatcher helper addWatch() method

Listing 15.18. Registration callable

Listing 15.19. RegistryListener event handling

Listing 15.20. ListenerHook that tracks registered service listeners

Listing 15.21. Tracking the “remote” service

Appendix A. Building bundles

Listing A.1. Google-Guice maven-bundle-plugin configuration

Listing A.2. Embed-Dependency examples

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.41.148