Top Banner
Javier Morán Rúa <[email protected]> October 2012 LibrePlan architecture An overview
62
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Libreplan architecture

Javier Morán Rúa <[email protected]> October 2012

LibrePlan architecture An overview

Page 2: Libreplan architecture

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.

www.libreplan.com

Page 3: Libreplan architecture

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 systemwww.libreplan.com

Page 4: Libreplan architecture

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.

www.libreplan.com

Page 5: Libreplan architecture

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

www.libreplan.com

Page 6: Libreplan architecture

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.

www.libreplan.com

Page 7: Libreplan architecture

Layering pattern

● Downsides:

● Two much layers can harm performance.

● Desired encapsulation many times is imperfect.

Cascade changes.

www.libreplan.com

Page 8: Libreplan architecture

Layering pattern

● LibrePlan architecture uses the layering pattern.

● LibrePlan is a three layer (tier) application.

● Layer 0.

– Purpose = Persistence

– Components = Hibernate framework +

Repositories.

www.libreplan.com

Page 9: Libreplan architecture

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.

www.libreplan.com

Page 10: Libreplan architecture

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.

www.libreplan.com

Page 11: Libreplan architecture

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?

www.libreplan.com

Page 12: Libreplan architecture

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. www.libreplan.com

Page 13: Libreplan architecture

Client - server pattern

● LibrePlan server.

● Runs part of the ZK interface tier, the domain logic

and part of the persitence layer.

www.libreplan.com

Page 14: Libreplan architecture

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.

www.libreplan.com

Page 15: Libreplan architecture

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.

www.libreplan.com

Page 16: Libreplan architecture

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.

www.libreplan.com

Page 17: Libreplan architecture

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.www.libreplan.com

Page 18: Libreplan architecture

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.

www.libreplan.com

Page 19: Libreplan architecture

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).

www.libreplan.com

Page 20: Libreplan architecture

IoC pattern

● Techniques to implement Inversion of Control

● Factory method pattern (GoF).

www.libreplan.com

Page 21: Libreplan architecture

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.

www.libreplan.com

Page 22: Libreplan architecture

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 component's dependencies.

– An injector (aka container or provider)

www.libreplan.com

Page 23: Libreplan architecture

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.

www.libreplan.com

Page 24: Libreplan architecture

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)

www.libreplan.com

Page 25: Libreplan architecture

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.

www.libreplan.com

Page 26: Libreplan architecture

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.

www.libreplan.com

Page 27: Libreplan architecture

MVC pattern

● Controller Role. It takes the user input, manipulates

the model and causes the view to update accordingly.

www.libreplan.com

Page 28: Libreplan architecture

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

www.libreplan.com

Page 29: Libreplan architecture

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).

www.libreplan.com

Page 30: Libreplan architecture

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

www.libreplan.com

Page 31: Libreplan architecture

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

www.libreplan.com

Page 32: Libreplan architecture

ZK architecture

www.libreplan.com

Page 33: Libreplan architecture

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.

www.libreplan.com

Page 34: Libreplan architecture

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 componentwww.libreplan.com

Page 35: Libreplan architecture

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.

www.libreplan.com

Page 36: Libreplan architecture

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 application's user. Example:

Person, city, lottery ticket, etc.

www.libreplan.com

Page 37: Libreplan architecture

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.

www.libreplan.com

Page 38: Libreplan architecture

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.

www.libreplan.com

Page 39: Libreplan architecture

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.

www.libreplan.com

Page 40: Libreplan architecture

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.

www.libreplan.com

Page 41: Libreplan architecture

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)

www.libreplan.com

Page 42: Libreplan architecture

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.

www.libreplan.com

Page 43: Libreplan architecture

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.

www.libreplan.com

Page 44: Libreplan architecture

Layers data exchange

● Perils of using domain entities (Hibernate mapping

objects) as exchange data: Beware of the life cycle.

www.libreplan.com

Page 45: Libreplan architecture

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.

www.libreplan.com

Page 46: Libreplan architecture

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.www.libreplan.com

Page 47: Libreplan architecture

Conversations

● Conversations are designed in LibrePlan with the

pattern session-per-request-with-detached-objects.

www.libreplan.com

Page 48: Libreplan architecture

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.

www.libreplan.com

Page 49: Libreplan architecture

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.

www.libreplan.com

Page 50: Libreplan architecture

Conversations

● In LibrePlan session-per-request-with-detached

objects conversations:

● There is a convention for the conversations:

– prepareForOperation()

– confirmOperation()

www.libreplan.com

Page 51: Libreplan architecture

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.

www.libreplan.com

Page 52: Libreplan architecture

OCC Pattern

www.libreplan.com

Page 53: Libreplan architecture

OCC Pattern

● LibrePlan uses OCC.

● It is got help of Hibernate.

● A version field is used, which is incremented each

new update operation.

www.libreplan.com

Page 54: Libreplan architecture

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.

www.libreplan.com

Page 55: Libreplan architecture

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

www.libreplan.com

Page 56: Libreplan architecture

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.

www.libreplan.com

Page 57: Libreplan architecture

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.

www.libreplan.com

Page 58: Libreplan architecture

Aggregate Pattern

● Example of aggregate in LibrePlan

www.libreplan.com

Page 59: Libreplan architecture

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.

www.libreplan.com

Page 60: Libreplan architecture

Domain Model Validation

● Custom validation scheme:

www.libreplan.com

Page 61: Libreplan architecture

Domain Model Validation

● Domain Model Validation in entities: It consists of

implementing the validation logic inside domain model

entities.

www.libreplan.com

Page 62: Libreplan architecture

Domain Model Validation

● LibrePlan uses validation inside domain model

entities.

● LibrePlan uses Hibernate Validator to do this process

simpler.

www.libreplan.com