1. Trang chủ
  2. » Công Nghệ Thông Tin

OSGi and Apache Felix 3.0 ppt

322 209 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 322
Dung lượng 15,7 MB

Nội dung

www.it-ebooks.info www.it-ebooks.info 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 transmied in any form or by any means, without the prior wrien permission of the publisher, except in the case of brief quotaons embedded in crical arcles or reviews. Every eort has been made in the preparaon of this book to ensure the accuracy of the informaon presented. However, the informaon 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 informaon about all of the companies and products menoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaon. First published: November 2010 Producon 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 (john.m.quick@gmail.com) www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Quick Intro to Felix and OSGi 7 What is OSGi? 8 The framework layout 10 The funconal 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 Funconal headers 17 Informaon headers 18 Start levels 18 The Start Level Service 18 The acve start level 18 Using start levels 20 Apache Felix and sub-projects 21 Summary 24 Chapter 2: Seng Up the Environment 25 Seng up the Felix framework 25 Checking that a JDK is installed 26 Download and unpack the Felix distribuon 27 Time for acon – downloading and installing Felix 27 What's in the box? 28 Time for acon – starng Felix 28 www.it-ebooks.info Table of Contents [ ii ] 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 execuon 36 Variable assignment and referencing 37 Value types 37 Object properes and operaons 38 Execuon quotes 38 Commands and scopes 39 felix scope commands 39 Lisng 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 er 61 www.it-ebooks.info Table of Contents [ iii ] The business logic er 62 The user interacon er 63 OSGi, Felix, and 65 Taking it step-by-step 65 Some convenons 67 Summary 69 Chapter 5: The Book Inventory Bundle 71 Set up the Book Inventory API Bundle project 72 Time for acon – seng up the project skeleton 72 Time for acon – creang the project POM 73 The Bundle identy 73 More on bundle versions 74 Dependencies 76 Customizing the build 77 Dening the distribuon parameters 78 The Book bean interface 79 The Book bean aributes 79 Time for acon – creang the Book bean interface 80 The Book Inventory interface 81 Time for acon – wring the BookInventory interface 82 Build and deploy the bundle 83 Time for acon – building and deploying the bundle 84 Let's implement those interfaces 85 Time for acon – creang the POM 85 Time for acon – implemenng a mutable book 87 Time for acon – implemenng the mock (memory-stored) Book Inventory 88 The factory method 88 Implemenng a mock getGoups() 89 Storing a book 89 Removing a stored book 90 Loading a stored book 90 Implemenng the book search 91 Wring the Bundle Acvator 94 Time for acon – add a dependency to the OSGi Core library 94 Time for acon – creang the Acvator 95 More on Bundle Contexts 96 Time for acon – declaring Bundle-Acvator 97 Build and deploy the bundle 97 Summary 98 www.it-ebooks.info Table of Contents [ iv ] Chapter 6: Using the OSGi Bundle Repository 99 OBR, the OSGi Bundle Repository 99 The repository XML Descriptor 101 Updang 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 Updang bundles in the repository 107 Installing the Book Inventory bundles to Felix 108 Time for acon – install the book inventory bundles 108 On dependency management 110 Summary 111 Chapter 7: The Bookshelf: First Stab 113 The Bookshelf Service bundle 113 Dene the main Bookshelf Service interfaces 115 Time for acon – wring the APIs 116 The Authencaon interface 116 The BookshelfService interface 116 Implemenng the service 119 Time for acon – wring BookshelfServiceImpl 119 Time for acon – implemenng the service acvator 122 Framework service lookup 123 Trying the BookshelfService 126 Time for acon – building the bundle 126 Time for acon – installing and tesng the service 126 Time for acon – fullling 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 acon – creang the Bookshelf Service TUI bundle 134 Implemenng a Gogo Shell Service command 135 Implemenng the book:search command 136 Time for acon – adding the required dependencies 136 Time for acon – wring the BookshelfServiceProxy 137 On Converters 141 www.it-ebooks.info Table of Contents [ v ] Time for acon – implemenng a bundle acvator 142 Time for acon – packaging and installing 143 Time for acon – trying out the book:search command 144 Time for acon – cleaning up the bookshelf-service acvator 146 Implemenng the book:add command 147 Time for acon – implemenng the book-add command 147 Updang an installed bundle 148 Trying the commands 151 Sourcing scripts 153 Time for acon – creang a book populaon script 153 Summary 156 Chapter 9: Improve the Bookshelf Service with iPOJO 157 What is Inversion of Control? 158 The Service Locator paern 159 The Dependency Injecon paern 159 The Whiteboard paern 161 The Extender Paern 161 The iPOJO Felix sub-project 162 Components and instances 163 iPOJO Maven plugin 164 The metadata le 164 Using the plugin 167 Injecng iPOJOs 168 Install the iPOJO service bundle 169 Let iPOJO register the inventory implementaon 169 Time for acon – creang the iPOJO metadata 170 Update the POM 170 Congure 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 acon – removing lookups in the service implementaon 175 Time for acon – wring the bookshelf service iPOJO conguraon 177 Update the POM 177 Deploy and check 179 iPOJO using annotaons 180 Overview 180 Beginner's annotaons 180 @Component 181 @Provides 181 www.it-ebooks.info Table of Contents [ vi ] @Requires 181 @ServiceProperty 182 @Property 182 @Instanate 182 Instanang annotated components 182 Update the text UI bundle 183 Time for acon – updang the BookshelfServiceProxyImpl 183 Time for acon – wring the iPOJO meta.xml 184 Time for acon – updang 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 Creang the log helper bundles 198 Time for acon – creang the bookshelf-log-api bundle 198 Time for acon – creang the log helper implementaon 199 Implemenng the BookshelfLogHelper service 200 Add logging to the bookshelf-service 201 Time for acon – updang the bundle POM 201 Time for acon – updang the bookshelf service logging calls 202 Time for acon – logging to BookshelfLogHelper 203 Update bookshelf-service-tui dependency 204 Trying it out 205 Using other Log Service implementaons 208 Summary 208 Chapter 11: How About a Graphical Interface? 209 The OSGi HTTP Service 209 Component structure 210 Registraon of servlets 211 iPOJO and the Whiteboard Extender 212 Hp Service implementaons 213 The Apache Felix Hp Service 213 Time for acon – installing the Apache Felix Hp Service 214 www.it-ebooks.info Table of Contents [ vii ] A simple bookshelf web applicaon 214 Time for acon – implemenng the servlet 215 The iPOJO conguraon 216 Implemenng the operaons 217 Time for acon – declaring the parameter constants 217 Time for acon – implemenng the operaons 218 Trying it out 224 Summary 226 Chapter 12: The Web Management Console 227 Geng started 228 Installing the Web Console 228 Time for acon – installing commons-leupload and commons-io 229 Time for acon – installing json 229 Time for acon – installing and starng the Web Console 231 A quick overview 231 Bundles 232 Log Service 233 OSGi Repository 234 Services 234 Shell 235 System Informaon 236 Apache Felix iPOJO WebConsole Plugin 236 Summary 238 Chapter 13: Improving the Graphics 239 OSGi Web Containers 240 Pax Web 240 Time for acon – installing the Pax Web bundles 241 Uninstall previous hp support 241 Install PAX Web bundles 242 Double-check the hp service implementaon 242 Our bookshelf-webapp 243 Time for acon – creang the bookshelf-webapp bundle 244 Web applicaon registraon 245 Time for acon – seng up the web applicaon bundle 245 Time for acon – specifying dependencies 246 Geng a service reference in JSP 247 Time for acon – wring the session bean 248 Complete the authencaon pages 249 www.it-ebooks.info [...]... Felix implementation and how it fits into the OSGi world www.it-ebooks.info Quick Intro to Felix and OSGi You will:  Take a quick overview of OSGi  Understand the OSGi service platform, its functional layers, and their interaction  Take a deep dive into OSGi bundles, their manifest headers  Understand how bundles are activated on an OSGi platform  Learn about bundle start levels and how they can be... complete and dynamic component model Wasn't that a complicated definition! So how would you really use it to practical modular applications? Let this book break down the seemingly overwhelming OSGi standards for you by explaining Apache Felix' s powerful architecture in a simple and easy-to-understand manner using Apache Felix framework to get you up and running sooner than you expect The OSGi standards... covers Chapter 1, Quick intro to OSGi and Felix gives an overview of OSGi and introduces Felix Chapter 2, Setting up the Environment walks the reader through the pre-requisites needed for developing as they read Chapter 3, Felix Gogo covers the Felix Gogo command-line shell and syntax Chapter 4, Let's Get Started: The Bookshelf Project sets the scope of work for the case study and describes the chapter-by-chapter... Smart Home, E-Health, and Mobile, to name just a few Apache Felix is one of the most famous implementations of the OSGi framework specification This book introduces OSGi on the simple and extensible Felix framework and guides the reader from the development environment setup to the troubleshooting of potential issues, walking them through the development of an OSGi- based application and explaining relevant... http://www .osgi. org/Markets/EHealth In short, the applications of OSGi are limitless and with a wide involvement from many disparate parties Do you think you can contributing? If yes, you can consider following one of the previous groups and contribute your experience! Let's take a look at the layout of an OSGi service platform and understand the way it works [] www.it-ebooks.info Quick Intro to Felix and OSGi. .. specifications Among the many adopters of OSGi as an application framework in the Open Source community are Knopflerfish, Equinox (Eclipse), and Felix We will be working with the Apache Felix OSGi service platform implementation The OSGi Service Platform's Core Specification documents the framework's expected behavior and also specifies the way its different parts interact, and react to external requests in... modular and extensible applications This book uses the Felix framework 3.0 as an OSGi service platform implementation, and covers its usage to a level where it makes you comfortable enough to write your own enterprise-level applications This book is aimed at Java developers looking to learn about writing reusable and network distributable software following the OSGi standards using the famous Felix framework... This book starts with an introduction to the OSGi Service Platform, its parts and its bundle structure It then walks the reader through the Felix framework's setup and their development environment It describes the Felix Framework and how to operate it using Gogo This book will teach you everything possible about the practical implementation of OSGi using the Felix Framework as a launch pad The book then... JSP Web Application Bundle and explaining Web Containers in the context of OSGi Chapter 14, Pitfalls and Troubleshooting includes a few tips on common issues faced when writing a bundle and describes a few means to troubleshoot them Appendix A, Eclipse, Maven, and Felix is an introduction to some of the productivity tools available for a Java developer in general and to an OSGi developer in specific... Intro to Felix and OSGi The optional OSGI- OPT/ directory can be used to store additional resources that are not needed for the proper functioning of the bundle: resources such as source code and additional documentation The framework may choose to throw this content away, if it needs to save storage space Another standard OSGi directory that can also be present in a bundle archive is the OSGI- INF/ . ] 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. C: Pop Quiz Answers 30 3 Chapter 1: Quick intro to Felix and OSGi 30 3 Chapter 2: Seng up the Environment 30 3 Chapter 3: Felix Gogo 30 4 Chapter 5: The Book

Ngày đăng: 24/03/2014, 01:21

TỪ KHÓA LIÊN QUAN

w