ebook img

OSGi and Apache Felix 3.0 Beginner's Guide PDF

322 Pages·2010·15.28 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview OSGi and Apache Felix 3.0 Beginner's Guide

OSGi and Apache Felix 3.0 Beginner’s Guide Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: November 2010 Production Reference: 1291010 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849511-38-4 www.packtpub.com Cover Image by John M. Quick ([email protected]) Table of Contents Preface 1 Chapter 1: Quick Intro to Felix and OSGi 7 What is OSGi? 8 The framework layout 10 The functional layers 10 The bundle lifecycle states 12 Bundle wiring 13 The shared service registry 14 Working with bundles 15 Anatomy of a bundle 15 The OSGi headers 16 Mandatory headers 16 Functional headers 17 Information headers 18 Start levels 18 The Start Level Service 18 The active start level 18 Using start levels 20 Apache Felix and sub-projects 21 Summary 24 Chapter 2: Setting Up the Environment 25 Setting up the Felix framework 25 Checking that a JDK is installed 26 Download and unpack the Felix distribution 27 Time for action – downloading and installing Felix 27 What's in the box? 28 Time for action – starting Felix 28 Table of Contents Maven2 and Felix 30 Installing Maven2 30 Life-cycles and phases 30 Maven plugins 32 The POM 32 The Felix Maven Plugins 32 Summary 33 Chapter 3: Felix Gogo 35 The Tiny Shell Language 36 Chained execution 36 Variable assignment and referencing 37 Value types 37 Object properties and operations 38 Execution quotes 38 Commands and scopes 39 felix scope commands 39 Listing installed bundles: lb 40 help 40 install 43 update 44 resolve 45 stop and start 45 uninstall 46 refresh 46 headers and inspect 47 which 49 log 50 cd and ls 50 frameworklevel and bundlelevel 52 gogo scope commands 54 echo 54 grep 54 cat 55 tac 56 set 57 Summary 58 Chapter 4: Let's Get Started: The Bookshelf Project 59 A simple Bookshelf project 60 The data inventory tier 61 [ ii ] Table of Contents The business logic tier 62 The user interaction tier 63 OSGi, Felix, and... 65 Taking it step-by-step 65 Some conventions 67 Summary 69 Chapter 5: The Book Inventory Bundle 71 Set up the Book Inventory API Bundle project 72 Time for action – setting up the project skeleton 72 Time for action – creating the project POM 73 The Bundle identity 73 More on bundle versions 74 Dependencies 76 Customizing the build 77 Defining the distribution parameters 78 The Book bean interface 79 The Book bean attributes 79 Time for action – creating the Book bean interface 80 The Book Inventory interface 81 Time for action – writing the BookInventory interface 82 Build and deploy the bundle 83 Time for action – building and deploying the bundle 84 Let's implement those interfaces 85 Time for action – creating the POM 85 Time for action – implementing a mutable book 87 Time for action – implementing the mock (memory-stored) Book Inventory 88 The factory method 88 Implementing a mock getGoups() 89 Storing a book 89 Removing a stored book 90 Loading a stored book 90 Implementing the book search 91 Writing the Bundle Activator 94 Time for action – add a dependency to the OSGi Core library 94 Time for action – creating the Activator 95 More on Bundle Contexts 96 Time for action – declaring Bundle-Activator 97 Build and deploy the bundle 97 Summary 98 [ iii ] Table of Contents Chapter 6: Using the OSGi Bundle Repository 99 OBR, the OSGi Bundle Repository 99 The repository XML Descriptor 101 Updating the OBR repository 103 Using the OBR scope commands 103 obr:repos 103 obr:list 104 obr:info 105 obr:deploy 106 obr:source and obr:javadoc 107 Updating bundles in the repository 107 Installing the Book Inventory bundles to Felix 108 Time for action – install the book inventory bundles 108 On dependency management 110 Summary 111 Chapter 7: The Bookshelf: First Stab 113 The Bookshelf Service bundle 113 Define the main Bookshelf Service interfaces 115 Time for action – writing the APIs 116 The Authentication interface 116 The BookshelfService interface 116 Implementing the service 119 Time for action – writing BookshelfServiceImpl 119 Time for action – implementing the service activator 122 Framework service lookup 123 Trying the BookshelfService 126 Time for action – building the bundle 126 Time for action – installing and testing the service 126 Time for action – fulfilling the missing dependency 129 On class visibility 131 Summary 132 Chapter 8: Adding a Command-Line Interface 133 The Apache Felix Gogo Shell Service 134 Time for action – creating the Bookshelf Service TUI bundle 134 Implementing a Gogo Shell Service command 135 Implementing the book:search command 136 Time for action – adding the required dependencies 136 Time for action – writing the BookshelfServiceProxy 137 On Converters 141 [ iv ] Table of Contents Time for action – implementing a bundle activator 142 Time for action – packaging and installing 143 Time for action – trying out the book:search command 144 Time for action – cleaning up the bookshelf-service activator 146 Implementing the book:add command 147 Time for action – implementing the book-add command 147 Updating an installed bundle 148 Trying the commands 151 Sourcing scripts 153 Time for action – creating a book population script 153 Summary 156 Chapter 9: Improve the Bookshelf Service with iPOJO 157 What is Inversion of Control? 158 The Service Locator pattern 159 The Dependency Injection pattern 159 The Whiteboard pattern 161 The Extender Pattern 161 The iPOJO Felix sub-project 162 Components and instances 163 iPOJO Maven plugin 164 The metadata file 164 Using the plugin 167 Injecting iPOJOs 168 Install the iPOJO service bundle 169 Let iPOJO register the inventory implementation 169 Time for action – creating the iPOJO metadata 170 Update the POM 170 Configure bundle for iPOJO 171 Build and test it 172 The Felix iPOJO Gogo Command bundle 173 ipojo scope commands usage 174 Migrate the bookshelf service 175 Time for action – removing lookups in the service implementation 175 Time for action – writing the bookshelf service iPOJO configuration 177 Update the POM 177 Deploy and check 179 iPOJO using annotations 180 Overview 180 Beginner's annotations 180 @Component 181 @Provides 181 [ v ] Table of Contents @Requires 181 @ServiceProperty 182 @Property 182 @Instantiate 182 Instantiating annotated components 182 Update the text UI bundle 183 Time for action – updating the BookshelfServiceProxyImpl 183 Time for action – writing the iPOJO meta.xml 184 Time for action – updating the POM 185 Summary 187 Chapter 10: Improving the Logging 189 On logging 189 Logging levels 190 Who's listening? 191 The OSGi Log Service 192 The Service end 193 Usage of the Log Service 194 The service provider end 195 Apache Felix Log Service 196 The log command 197 Creating the log helper bundles 198 Time for action – creating the bookshelf-log-api bundle 198 Time for action – creating the log helper implementation 199 Implementing the BookshelfLogHelper service 200 Add logging to the bookshelf-service 201 Time for action – updating the bundle POM 201 Time for action – updating the bookshelf service logging calls 202 Time for action – logging to BookshelfLogHelper 203 Update bookshelf-service-tui dependency 204 Trying it out 205 Using other Log Service implementations 208 Summary 208 Chapter 11: How About a Graphical Interface? 209 The OSGi HTTP Service 209 Component structure 210 Registration of servlets 211 iPOJO and the Whiteboard Extender 212 Http Service implementations 213 The Apache Felix Http Service 213 Time for action – installing the Apache Felix Http Service 214 [ vi ] Table of Contents A simple bookshelf web application 214 Time for action – implementing the servlet 215 The iPOJO configuration 216 Implementing the operations 217 Time for action – declaring the parameter constants 217 Time for action – implementing the operations 218 Trying it out 224 Summary 226 Chapter 12: The Web Management Console 227 Getting started 228 Installing the Web Console 228 Time for action – installing commons-fileupload and commons-io 229 Time for action – installing json 229 Time for action – installing and starting the Web Console 231 A quick overview 231 Bundles 232 Log Service 233 OSGi Repository 234 Services 234 Shell 235 System Information 236 Apache Felix iPOJO WebConsole Plugin 236 Summary 238 Chapter 13: Improving the Graphics 239 OSGi Web Containers 240 Pax Web 240 Time for action – installing the Pax Web bundles 241 Uninstall previous http support 241 Install PAX Web bundles 242 Double-check the http service implementation 242 Our bookshelf-webapp 243 Time for action – creating the bookshelf-webapp bundle 244 Web application registration 245 Time for action – setting up the web application bundle 245 Time for action – specifying dependencies 246 Getting a service reference in JSP 247 Time for action – writing the session bean 248 Complete the authentication pages 249 [ vii ]

Description:
This book is a step-by-step beginner's guide based on developing a case study (a book inventory) that walks the developer through the implementation while progressively explaining the surrounding concepts in context. Throughout the book, the author discusses software design concepts and introduces p
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.