Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Libreplan architecture


Published on

  • Be the first to comment

Libreplan architecture

  1. 1. LibrePlan architecture An overviewJavier Morán Rúa <> October 2012
  2. 2. Software architecture What is it ? The software architecture of a program or computing system is the structure or structures of the system,which comprise software elements, the externally visible properties of those elements, and the relationships among them.
  3. 3. Software architecture● Considerations about architecture: ● Impressive-sounding word. To talk about something is important. ● Many definitions. Not an agreement. ● Three key ideas: – High level design – Difficult to change – Many architectures in one system
  4. 4. Architectural patterns● Definition: Description of elements and relation types together with a set of constraints on how they may be used.● Some traits: ● They guide how to implement new features. ● They exhibit known quality attributes.
  5. 5. Layering pattern● Layering: It is a technique to deal with complexity.● Several layers of software (source code) like in a cake. ● Each layer rests on a lower layer. ● The lower layer is unaware of the upper layer
  6. 6. Layering pattern● Benefits: ● You can understand each layer in isolation. ● You can substitute each layer by an alternative implementation. ● They promote reuse. ● They minimize dependencies between structural parts.
  7. 7. Layering pattern● Downsides: ● Two much layers can harm performance. ● Desired encapsulation many times is imperfect. Cascade changes.
  8. 8. Layering pattern● LibrePlan architecture uses the layering pattern.● LibrePlan is a three layer (tier) application. ● Layer 0. – Purpose = Persistence – Components = Hibernate framework + Repositories.
  9. 9. Layering pattern● Layer 1. – Purpose = Domain logic – Components = Domain Entities, Behavioral classes, Conversational services● Layer 2. – Purpose = Interfaces (Human + Machine) – Components = ZK web pages, Web services.
  10. 10. Client - server pattern● Definition: A program is a client-server application if is a piece of software which runs split it two machines. – Client computer. It makes request to a remote server computer. – Server computer. It does the calculations asked by clients and answers them.
  11. 11. Client - server pattern● Some features: ● It implies the existence of a network. ● Client-server applications can be cross-platform. ● Some nodes can be clients and servers at the same time depending on the analyzed role. ● They are related with the layering. Where do you run the layers?
  12. 12. Client - server pattern● LibrePlan is a client-server application.● LibrePlan clients: ● User browser. – Example: Firefox, Google chrome. – Runs part of the interface tier. ● Outer WS client. Example: ERP importing into LibrePlan employees. ● LibrePlan WS client. Example: outsourcing module ● LibrePlan persistence tier. Its server is the RDMS.
  13. 13. Client - server pattern● LibrePlan server. ● Runs part of the ZK interface tier, the domain logic and part of the persitence layer.
  14. 14. Domain model pattern● What is the domain? Subject area to which the user applies the program. ● LibrePlan domain is project planning, monitoring and control.● In a few words: Build a model of the domain that both incorporates logic and data.● What implies? Inserting a whole layer of objects.
  15. 15. Domain model pattern● Alternative pattern (more frequently used): Transaction script.● It what does it consist of? It organizes business logic by procedures where each procedure handles a single request from the presentation.
  16. 16. Domain model pattern● Advantages: ● It allows logic reuse on large systems. Typical transaction script architectures promote duplication ● It allows to change easily the behavior of complex domains. It uses the power of the OO model to accomplish it. ● It can be used for knowledge crunching (analysis) with domain experts. Domain driven design.
  17. 17. Domain model pattern● Downsides: ● It requires effort. Assimilate the paradigm shift. ● It requires initially more effort to implement.● LibrePlan uses domain model pattern.● How is it implemented? ● Hibernate entities are related each other. ● They are POJOs. They can live outside the Hibernate session.
  18. 18. IoC pattern● Inversion of Control – Pattern of object-oriented programming where the object coupling is done at run time by an assembler object and is typically not known at compile time by static analysis.● How is done in traditional programming? ● The flow and the business logic is determined by objects that are statically assigned to one another.
  19. 19. IoC pattern● Benefits: ● Decouples the execution of some tasks from specific implementation. It allows to replace components. ● It allows to reuse components more easily (among different programs). ● It allows to focus the components in what they are designed for (cohesion).
  20. 20. IoC pattern● Techniques to implement Inversion of Control ● Factory method pattern (GoF).
  21. 21. IoC pattern● Using a Service Locator. – An object who knows how to get hold of all the possible services an application can need. – The client component makes explicit calls to the Service Locator● Using Dependency Injection.
  22. 22. DI pattern● Concept: Software design pattern where an element, the injector, places dependent elements to the destination according to the destination requirements.● Three elements: – A dependent consumer. – A declaration of a components dependencies. – An injector (aka container or provider)
  23. 23. DI pattern● Three types of DI: – Interface injection. The dependent component provides an interface that the consumer must implement in order to get the dependencies at run time. – Setter injection. The dependent consumer exposes a setter method that the injector uses. – Constructor injection. The dependencies are placed in the constructor of the dependent consumer.
  24. 24. IoC - DI LibrePlan● LibrePlan uses Inversion of Control.● LibrePlan implements Inversion of Control with the pattern Dependency Injection.● LibrePlan uses the Setter Dependency Injection Type.● LibrePlan uses Spring framework as injector (container)
  25. 25. IoC – DI LibrePlan● Spring Framework has about 20 modules. ● Core Container. ● Inside the Core Container the module for IoC and DI is the Core and Beans.● Where is it used IoC in LibrePlan architecture? ● Getting models from ZK page controllers. ● Getting repositories (DAO) from models.
  26. 26. MVC pattern● Model-View-Controller: It is a presentation pattern that consists of splitting the user interface interaction in three roles (Model, View and Controller)● Model Role. Non-visual object containing all the information and behavior from the application domain.● View Role. Represents the display of the model in the UI. Example: UI widgets or HTML. It only displays information.
  27. 27. MVC pattern● Controller Role. It takes the user input, manipulates the model and causes the view to update accordingly.
  28. 28. MVC pattern● Two separations: ● Presentation from the model ● Controller from the view● Reasons separation presentation from model: ● They are different concerns. ● Depending on context you can use model in different ways. ● Non visual objects are easier to test than visual ones
  29. 29. MVC pattern● Separation controller from the view: ● Less important separation. ● This separation is usually not done.● LibrePlan uses MVC pattern: ● It does not separate controller from view. Many times in the controller is rendered the view (HTML). ● View and the controller split: – Some part runs in the client browser (HTML + JS) – Other part runs in the server (Java objects).
  30. 30. MVC pattern● LibrePlan uses the MVC pattern ● The models are injected (DI) with the Spring container into the controllers. ● The models belong to the domain layer and are decoupled by DI from the presentation layer. ● The models are reused sometimes: – HTML view – Web Services
  31. 31. ZK architecture● Component based framework. ● It abstracts widgets that are reused in different web pages. Other: Tapestry, Wicket● Components have two representations: ● DOM in the browser. ● Java objects in the server (POJOs)● They are synchronized automatically by ZK
  32. 32. ZK architecture
  33. 33. ZK architecture● It is a RIA framework● Very productive. ● You do not need to program in JS. ● You have not to worry about AJAX for synchronization.● The best place to manage complex business logic is the server. With ZK you have the domain accessible from the presentation easily.
  34. 34. LibrePlan and ZK● LibrePlan uses ZK for the web interface.● LibrePlan uses the components of ZK CE.● LibrePlan has developed new ZK components mainly related with the Gantt chart. Examples: ● Task component. ● Dependency component ● Milestone component ● Timetracker component
  35. 35. Object relational mapping● Object relational mapping is a technique used for converting the data in a relational database to the object oriented paradigm.● Hibernate is Java ORM that is the de facto standard in the Java platform for persistence.● LibrePlan uses Hibernate as ORM in the persistence layer.
  36. 36. Layers data exchange● What is an entity? ● An entity is an object defined primarily by its identification. ● It is anything that has continuity through a life-cycle and distinction independent of the attributes that are important for the applications user. Example: Person, city, lottery ticket, etc.
  37. 37. Repository pattern● A repository represents all objects of a certain type as a conceptual set. ● Collection with a more elaborate querying capability.● Clients requests objects from the repository using query methods based on criteria specified by the client.● Repository retrieves the requested objects, encapsulating the machinery of database queries.
  38. 38. Repository pattern● LibrePlan uses the repository pattern. ● They are Java classes called XXXDAO ● They are implemented with Hibernate (HQL, Criteria API).● They are managed by DI with the Spring container. ● They are injected in the domain Model classes (used in the MVC presentation pattern) ● They are used also in the domain entities but cannot be injected there. They are got from a Registry where they are injected.
  39. 39. Repository pattern● In LibrePlan entities are loaded in memory by two ways: ● Using the repositories. ● By traversing the entity relationships. Two conditions: – Hibernate session has to be open. – Objects must be attached.
  40. 40. Layers data exchange● Bottom layers offer services to the upper layers by returning data.● There are two approaches to exchange data between subsystems: Use Data Transfer Objects or return the own data objects of the bottom layer.● Data Transfer Objects. ● They do not have behavior. ● Only getters and setters.
  41. 41. Layers data exchange● Data Transfer Objects: ● They are designed according to client needs. ● Usually aggregate data from several classes of the subsystem that is returning them.● Analyzing DTOs: ● They are expensive and time-consuming because of the translation code (in - out)
  42. 42. Layers data exchange● Analyzing DTOs: ● They are recommendable if the data objects of the service subsystem have inner dependencies. Most of all, for network communications. ● They are comfortable and easy to use by the clients because they are prepared for them.
  43. 43. Layers data exchange● LibrePlan use of DTOs in: ● Web services. They are easily converted in XML to be send in the web services body with JAXB (Java Architecture for XML Binding). ● Reports done with JasperReports. The reports require to receive DTOs because of the framework internals.● LibrePlan uses the domain objects (entities) as layer data exchange.
  44. 44. Layers data exchange● Perils of using domain entities (Hibernate mapping objects) as exchange data: Beware of the life cycle.
  45. 45. Layers data exchange● Perils of using domain entities (Hibernate mapping objects) as data exchange: Being aware of the graph depth of the objects retrieved. ● You cannot retrieve the full database (performance issues). ● The client has to know the extent of the graph retrieved. If not, LazyInitializationException maybe is thrown.
  46. 46. Conversations● LibrePlan is an stateful system. ● Stateless system. At any point the output only depends on the input. ● Stateful system. At a point in time the output depends on the input and internal state.● You cannot keep the transaction open between user interactions. ● They take a long time and consume resources. ● Maybe they do not finish.
  47. 47. Conversations● Conversations are designed in LibrePlan with the pattern session-per-request-with-detached-objects.
  48. 48. Conversations● Things to take into account with conversations with detached objects: ● Beware of reattaching objects on asking operations from the controller. ● Avoid having duplicated objects in the session.
  49. 49. Conversations● In LibrePlan session-per-request-with-detached objects conversations: ● They happen in the XXXModel objects. ● Model objects are injected by DI in the ZK UI controllers. ● They have prototype scope (not singleton). – The dependent object (XXXModel) is created by Spring before its injection.
  50. 50. Conversations● In LibrePlan session-per-request-with-detached objects conversations: ● There is a convention for the conversations: – prepareForOperation() – confirmOperation()
  51. 51. OCC Pattern● OCC (Optimistic Concurrency Control) is a pattern that assumes that everything will be OK and that conflicting data modifications are rare.● OCC raises an error only at the end of a unit of work, when data is written.● It sets the strategy: First commit wins.
  52. 52. OCC Pattern
  53. 53. OCC Pattern● LibrePlan uses OCC.● It is got help of Hibernate. ● A version field is used, which is incremented each new update operation.
  54. 54. Aggregate Pattern● Problem: In a complex domain it is difficult to guarantee the consistency of changes to objects with complex associations. ● Invariants needs to be maintained in a closed group of objects, not just discrete objects.● Use the aggregate pattern: An aggregate is a cluster of assocated objects that is treated as a unit for data change operations.
  55. 55. Aggregate Pattern● The definition of an aggregate implies: ● To define a boundary. – Defines what is inside the aggregate ● To define the root of the aggregate. – It is a simple specific entity contained in the aggregate
  56. 56. Aggregate Pattern● Rules of the pattern: ● The entities outside the aggregate only can hold references to the root aggregate. ● Objects inside the root aggregate can hold references to each other. ● Aggregates root can be got directly with repositories. All other objects must be found by traversal of associations.
  57. 57. Aggregate Pattern● Rules of the pattern: ● A delete operation must erase everything inside the aggregate.● LibrePlan uses Aggregate pattern. ● The XXXModel need to be aware of the aggregates.
  58. 58. Aggregate Pattern● Example of aggregate in LibrePlan
  59. 59. Domain Model Validation● Problem: Many applications implement validations in many layers. This has two drawbacks: ● Duplication. ● You may not be aware on the validation code you have implement if the application is large.
  60. 60. Domain Model Validation● Custom validation scheme:
  61. 61. Domain Model Validation● Domain Model Validation in entities: It consists of implementing the validation logic inside domain model entities.
  62. 62. Domain Model Validation● LibrePlan uses validation inside domain model entities.● LibrePlan uses Hibernate Validator to do this process simpler.