OSGi DevCon 09 - Component Oriented Development in OSGi with DS, Spring and iPOJO

download OSGi DevCon 09 - Component Oriented Development in OSGi with DS, Spring and iPOJO

of 196

  • date post

    24-Jan-2015
  • Category

    Technology

  • view

    2.344
  • download

    3

Embed Size (px)

description

Tutorial on "Component Oriented Development in OSGi with DS, Spring and iPOJO" at OSGi DevCon 09 (EclipseCon 09) in Santa Clara on 2009-03-23.

Transcript of OSGi DevCon 09 - Component Oriented Development in OSGi with DS, Spring and iPOJO

  • 1. Component Oriented Development in OSGi withDeclarative Services, Spring Dynamic Modules andApache iPOJONeil Bartlett1Heiko Seeberger2 1 Weigle Wilczek UK 2 Weigle Wilczek GmbH March 24, 2009 c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 1 / 174

2. Part IIntroduction c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 2 / 174 3. The (Partial) Failure of Object OrientationContents The (Partial) Failure of Object Orientation 1What is a Component? 2Implementing Components 3Example Application 4 c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 3 / 174 4. The (Partial) Failure of Object OrientationThe (Partial) Failure of Object OrientedOne of the primary goals of object oriented programming (OOP) was,and still is, re-use.It has mostly failed in that goal. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 4 / 174 5. The (Partial) Failure of Object OrientationThe (Partial) Failure of Object OrientedOne of the primary goals of object oriented programming (OOP) was,and still is, re-use.It has mostly failed in that goal. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 4 / 174 6. The (Partial) Failure of Object OrientationThe (Partial) Failure of Object Oriented Peter Kriens Object Oriented technology was going to change the world. . . we would have all these objects in our library and building a new system would be a snap. Just get a few classes, bunch them together. . . and voila! c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 5 / 174 7. The (Partial) Failure of Object OrientationWhat Went Wrong??CouplingClasses can almost never be used in isolation they depend on otherclasses.Those classes depend on other packages, which depend on otherJARs. . . c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 6 / 174 8. The (Partial) Failure of Object OrientationWhat Went Wrong??CouplingClasses can almost never be used in isolation they depend on otherclasses.Those classes depend on other packages, which depend on otherJARs. . . c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 6 / 174 9. The (Partial) Failure of Object OrientationWhat Went Wrong??CouplingClasses can almost never be used in isolation they depend on otherclasses.Those classes depend on other packages, which depend on otherJARs. . . c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 6 / 174 10. The (Partial) Failure of Object OrientationWhat Went Wrong??Eventually just to use one small class we end up doing this: Maven c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 7 / 174 11. The (Partial) Failure of Object OrientationA Solution?Re-use of classes outside their original context is hard, so. . .Give up!Leave them where they are, and call over the network!This is sometimes called SOA. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 8 / 174 12. The (Partial) Failure of Object OrientationA Better SolutionComponent Oriented ProgrammingBuilds on OOP.OOP is not bad, its just not the whole answer. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 9 / 174 13. What is a Component?Contents The (Partial) Failure of Object Orientation 1What is a Component? 2Implementing Components 3Example Application 4 c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 10 / 174 14. What is a Component?Components But wait, what is a component, vs an object?Good question! Many attempts have been made to dene the term.The following is not a formal academic denition, just a workingdenition that we have found useful in practice. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 11 / 174 15. What is a Component?Components But wait, what is a component, vs an object?Good question! Many attempts have been made to dene the term.The following is not a formal academic denition, just a workingdenition that we have found useful in practice. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 11 / 174 16. What is a Component?The Most Common AnalogyLego? c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 12 / 174 17. What is a Component?Lego is a Poor AnalogyJust dead lumps of plastic.All look and act the same.Not even very re-usable (try using a Duplo block in a Lego Technicsmodel!). c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 13 / 174 18. What is a Component?A Better AnalogyBees/Animals c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 14 / 174 19. What is a Component?Components Are:. . .Active participants in the system.Aware of and adapt to their environment.May provide services to other components and use services from othercomponents.Have a life cycle. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 15 / 174 20. What is a Component?Components Are:. . .Active participants in the system.Aware of and adapt to their environment.May provide services to other components and use services from othercomponents.Have a life cycle. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 15 / 174 21. What is a Component?Components Are:. . .Active participants in the system.Aware of and adapt to their environment.May provide services to other components and use services from othercomponents.Have a life cycle. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 15 / 174 22. What is a Component?Components Are:. . .Active participants in the system.Aware of and adapt to their environment.May provide services to other components and use services from othercomponents.Have a life cycle. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 15 / 174 23. What is a Component?What Does the Environment Mean?Services provided by other components.Resource, devices, etc. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 16 / 174 24. What is a Component?AdaptationWhen the environment is good, the component ourishes.When the environment is harsh, the component survives.When very harsh, the component sleeps or dies. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 17 / 174 25. Implementing ComponentsContents The (Partial) Failure of Object Orientation 1What is a Component? 2Implementing Components 3Example Application 4 c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 18 / 174 26. Implementing ComponentsImplementing ComponentsOSGi is the perfect environment for implementing components.The module layer allow us to minimise our static dependencies.Fewer static dependencies means less stu that must be present forour component to work.Services allow our component to interact with other components. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 19 / 174 27. Implementing ComponentsImplementing Components POJOs Components should be implemented as POJOs (Plain Old Java Objects) glued together with OSGi services. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 20 / 174 28. Example ApplicationContents The (Partial) Failure of Object Orientation 1What is a Component? 2Implementing Components 3Example Application 4 c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 21 / 174 29. Example ApplicationThe Example ApplicationThe example is a simplistic contact manager application.Capable of displaying the content of multiple contact repositories.Each repository appears in its own tab.Repositories are implemented as OSGi services. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 22 / 174 30. Example ApplicationExample ArchitectureServices Diagramapp.ui.*0..1 0..Ncore.inmemory LogService 0..1 ContactRepository core.directory0..NContactRepositoryListener c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0.March 24, 2009 23 / 174 31. Example ApplicationThe Example ApplicationContact Repository Viewer c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 24 / 174 32. Example ApplicationRunning the Example Application First start Equinox using the Core launcher from Eclipses Run menu. Equinox Console osgi> install file : contacts_api . jar Bundle id is 3osgi> install file : swingui . jar Bundle id is 4osgi> start 4 The UI should now appear, but with no contact repository tabs. c 2009 Neil Bartlett & WeigleWilczek GmbH. Released under the Eclipse Public License v1.0. March 24, 2009 25 / 174 33. Example ApplicationInstalling a Basic Contact RepositoryEquinox Console osgi> install file : . . / ComponentsRaw /