Open source enterprise frameworks
This presentation is the property of its rightful owner.
Sponsored Links
1 / 36

Open Source Enterprise Frameworks PowerPoint PPT Presentation


  • 85 Views
  • Uploaded on
  • Presentation posted in: General

Open Source Enterprise Frameworks. Spring Emerged as lightweight alternative to over-engineered “J2EE” Now suite of OSGi modules "Transparent" dependency injection and transaction management Ala carte services Hibernate ORM ("Object Relational Mapping" for RDBMS to Object mapping)‏

Download Presentation

Open Source Enterprise Frameworks

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Open source enterprise frameworks

Open Source Enterprise Frameworks

Spring

Emerged as lightweight alternative to over-engineered “J2EE”

Now suite of OSGi modules

"Transparent" dependency injection and transaction management

Ala carte services

Hibernate

ORM ("Object Relational Mapping" for RDBMS to Object mapping)‏

Robust, best-in-class product

Sophisticated optimization and customization (with learning curve)

Reverse engineering of legacy databases

SiteMesh

Like Struts Tiles, but easier to configure

Open Symphony is no more.. “You will now be redirected...”:


High level view of frameworks

High-Level View of Frameworks

Spring

  • Key design principles/implementation techniques totally "mainstream"

  • Configuring/using Spring still is not simple – Grails manages this...

    Hibernate

  • "Industrial strength"

  • Should compare against commercial products like Oracle

  • As subtle and complex as what it simplifies?-- Grails manages this...

    SiteMesh

  • Just infrastructure, transparently available to use


Where to download

Where to Download

Spring

http://www.springsource.com/download/community

Projects:

  • Spring Framework

  • Spring Grails

  • Spring Web Flow

    Hibernate

    http://www.hibernate.org/downloads

    SiteMesh

    https://github.com/sitemesh/sitemesh2


Spring strategic considerations

Spring: "Strategic" considerations

  • "The original" J2EE alternative

  • Enterprise apps need Lightweight Containers

  • Keeps on sprouting new modules (e.g., Batch, Web Flow, LDAP...)‏

  • OSGI-enabled Spring may be the “new” WJB4 …

  • SpringSource seems to be doing just fine

    • Groovy and Grails

    • SpringSourceToolsSuite

    • WaveMaker: “WYSIWYG Java studio”

    • vFabric tc Server: “Enterprise Tomcat server”

    • VMWare vFabric: “Develop virtual and cloud applications faster using the Spring framework; deploy to runtime optimized for Spring


Spring part of vmware http www vmware com products

Spring: part of VMware (http://www.vmware.com/products/)


Spring key design approaches features

Spring: Key Design Approaches/Features

  • POJOs rule! Even EJB3 is built around POJOs.

  • DI (Dependency Injection) instead of Service Locator ("Lookup")‏

  • "Convention, not configuration"

  • Mechanisms/conventions should not dominate coding efforts

  • Java code annotations can replace external XML

  • Declarative services, like transactions

  • "Modular" functionality; as in real OSGi

  • Don't reinvent, provide adapters to reuse "best-of-breed" available solutions

  • Enable pluggability at core subsystem level (for example, view layer) as well as for add-on features like security

  • Support for testing throughout the development life cycle is crucial


Spring 3 0 not xml

Spring 3.0 (NOT xml...)‏

  • Supports specs Java SE 5 and above; Servlet 2.4 and above

  • Annotations not XML!

    • Annotation-based components:

      • @Value expressions, referring todynamic #{…} expressions or static ${…} placeholders

    • "Meta-Annotations":

      • custom @MyService annotation for @Service, @Scope("request") and @Transactional(readOnly=true)‏

    • Standardized dependency injection annotations:

      • @inject, @Autowired, ...

    • Declarative model validation based on constraint annotations

      • @NotNull, @Min(1), ...

    • Enhanced binding and annotation-driven formatting

      • @DateTimeFormat, ...


Spring 3 0 spel portlets oxm etc

Spring 3.0: SpEL, Portlets, OXM, etc.

  • Spring expression language (SpEL): likeUnified EL ( JSTL Expression Language)‏

  • REST support

    • URI variable extraction through @PathVariable parameters

    • RestTemplate for Client-side REST support

  • Portlet 2.0 support

    • @ActionMapping, @RenderMapping, @ResourceMapping, @EventMapping, ...

  • Object/XML Mapping (OXM)‏

    • From Spring Web Services

    • Support for JAXB 2, Castor, etc.

  • Enhanced scheduling capabilities

    • TaskScheduler and Trigger mechanisms

    • @Async and @Scheduled annotations now. T

    • Supports both native and server-managedthread pools


Spring3

Spring3

Spring expression language (SpEL):

@Component

public class CountryAwareLogic {

...

@Autowired

public void setCountry(

@Value("#{systemProperties.country}") String country) {

this.country=country;

}

}


Spring31

Spring3

Excellent support for REST by annotatiions

@RequestMapping(value = "/reward/{id}", method = GET)‏

public Reward show(@PathVariable("id") long id) {

return rewardsAdminService.findReward(id);

}

Support for "web conversations"

Should be more like what Seam offers

Incorporated current Spring Web Flowproject which continue to add more extensions


Spring3 changes

Spring3 Changes

Mostly backwards-compatiblewith Spring2/Spring 2.5

Deprecated (but still useable)‏

  • "Legacy" MVC Controllers like SimpleFormController

  • JUnit 3 Spring-customized test classes

    New coding should use instead

  • "Legacy" MVC Controllers like SimpleFormController

  • JUnit 4 Spring-customized test classes

    No singledistribution package "spring.jar:"

  • Modular jars were always an alternative

  • Deploy using Maven2, Ivy, or OSGi (somewhat "bleeding edge")‏


What does spring contribute to grails

What does Spring contribute to Grails?

  • Dependency Injection

    • (solving “wiring-at-startup”)

  • AOP (Aspect Oriented Programming)

    • for automating services

  • Spring MVC as Web framework


Simple example dependency injection

Simple example: Dependency Injection

(from http://martinfowler.com/articles/injection.html#InversionOfControl)

public interface MovieFinder {

List findAll();

}

class MovieLister { …

public Movie[] moviesDirectedBy(String arg) {

List allMovies = finder.findAll();

for (Iterator it = allMovies.iterator(); it.hasNext();) {

Movie movie = (Movie) it.next();

if (!movie.getDirector().equals(arg)) it.remove();

}

return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]);

}

private MovieFinder finder;

public MovieLister() {

finder = new ColonDelimitedMovieFinder("movies1.txt"); …

}


What is dependency injection

What is Dependency Injection?

"...For this new breed of containers the inversion is about how they lookup a plugin implementation. In my naive example the lister looked up the finder implementation by directly instantiating it. This stops the finder from being a plugin. The approach that these containers use is to ensure that any user of a plugin follows some convention that allows a separate assembler module to inject the implementation into the lister.

As a result I think we need a more specific name for this pattern.Inversion of Controlis too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection."

(from http://martinfowler.com/articles/injection.html#InversionOfControl)


References on dependency injection

References on Dependency Injection

"A beginners' guide to Dependency Injection":

http://www.theserverside.com/tt/articles/article.tss?l=IOCBeginners

"DI: What's all the hype (Green Paper)"

http://www.manning.com/prasanna/

Comparison of IOC (Inversion of Control) containers:

http://www.picocontainer.org/comparisons.html

Tutorials on Spring DI: http://learnspringframework.blogspot.com/2006/10/what-is-ioc.htmlhttp://edudev.hfoss.org/index.php/Spring_Framework_Part_I-The_Context


Other frameworks dependency injection inversion of control

Other frameworks: Dependency Injection/Inversion of Control

Guice

http://.code.google.com/p/google-guice

Picocontainer

http://www.picocontainer.org/introduction.html

code snippet showing use in web application:

http://www.picocontainer.org/web-frameworks.html

code snippet showing use from main:

http://www.picocontainer.org/component-configuration.html

http://nanocontainer.codehaus.org/

http://www.keelframework.org/index.shtml

http://hivemind.apache.org/


How does grails leverage spring for di 1

How does Grails leverage Spring for DI? (1)

NOT xml! Just regular Groovy script file that contains Spring DSL

… grails-app/conf/spring/resources.groovy example:

import org.springframework.jmx.support.MBeanServerFactoryBean

import org.springframework.jmx.export.MBeanExporter

import org.hibernate.jmx.StatisticsService

Beans = { ….

// Hibernate statistics collection.

hibernateStats(StatisticsService) {

statisticsEnabled = true

sessionFactory = ref("sessionFactory")

}

...


How does grails leverage spring for di 2

How does Grails leverage Spring for DI? (2)

… grails-app/conf/spring/resources.groovy example:

Beans = { …. (con.)

mbeanServer(MBeanServerFactoryBean) {

locateExistingServerIfPossible = true

}

exporter(MBeanExporter) {

server = mbeanServer

beans = ["org.hibernate:name=statistics": hibernateStats]

}

}

(from Smith and Ledbrook, Grails inAction)‏


Comparing spring xml vs grails for di 1

Comparing Spring xml vs. Grails for DI(1)

spring-app.xml:

<bean id=”somebean” class=”x.y.Ex”>

scope=”prototype”

autowire=”byType”

init-method=”init”

destroy-method=”finish” >

resources.groovy:

somebean(x.y.Ex) { b →

b.scope=”prototype”

b.autowire=”byType”

b.init-method=”init”

b.destroy-method=”finish”

}


Comparing spring xml vs grails for di 2

Comparing Spring xml vs. Grails for DI(2)

spring-app.xml:

<bean id=”somelist” class=”x.y.List”>

<property name=”items”>

<list>

<value>1</value>

<value>2</value>

<value>3</value>

</list>

</property>

</bean>

resources.groovy:

somelist(x.y.List) {

Items =[ 1, 2, 3 ]

}


Comparing spring xml vs grails for di 3

Comparing Spring xml vs. Grails for DI(3)

spring-app.xml:

<bean id=”beanWithStaticFactoryMethod” class=”x.y.ExSrF”>

factory-method=”create” />

<bean id=”beanWithFactoryMethod” class=”x.y.ExF”>

factory-bean=”someFactory”

factory-method=”create” />

resources.groovy:

beanWithStaticFactoryMethod(x.y.ExSrF) { b →

b.factory-method=”create”

}

beanWithFactoryMethod(someFactory:”create” )

(from Smith and Ledbrook, Grails inAction)‏


Spring xml can still help in grails for di 1

Spring xml can still help in Grails for DI(1)

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://

www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!-- more bean definitions go here... -->

<!-- Mail service -->

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">

<property name="host" value="smtp.mac.com"/>

<property name="port" value="587"/>

<property name="username" value="mikesalera"/>

<property name="password" value="**************************" /> ...


Spring xml can still help in grails for di 2

Spring xml can still help in Grails for DI(2)

...

<property name="javaMailProperties">

<props>

<!-- Use SMTP-AUTH to authenticate to SMTP server -->

<prop key="mail.debug">false</prop>

<prop key="mail.smtp.auth">true</prop>

<!-- Use TLS to encrypt communication with SMTP server -->

<prop key="mail.smtp.starttls.enable">true</prop>

</props>

</property>

</bean>

</beans>


What is aspect oriented programming

What is Aspect-Oriented Programming?

The "next buzzword" after "Objects" and "Components" and "SOA" and ...

A meta-framework for EJB- (or .NET-) like frameworks which provide infrastructure "services" to applications

"... clean modularization of crosscutting concerns, such as error checking and handling, synchronization, context-sensitive behavior, performance optimizations, monitoring and logging, debugging support, and multi-object protocols..." (from the AspectJ homepage)‏


What is aspect oriented programming1

What is Aspect-Oriented Programming?

Object Oriented Programming does NOT address "cross-cutting concerns"

  • Concerns which "cut across" object boundaries

  • Tend to be the responsbility of MANY classes,and must be handled the same way, in order to work correctly

  • Need "separation of concerns" to modularize these aspects

    Extrafunctional features should NOT be coded by applications programmers

  • Extrafunctionality tends to be omnipresent; maintenance burden

  • Infrastructure should be supplied by infrastructure experts

  • Applications programmers should code domain functionality

    How extrafunctionality gets"blended in" without hard-coding everywhere

  • Declarative, not imperative, specification of extrafunctionality

    • Think A + 5.2 = 100; not A = 100 - 5.2

    • "Policy versus mechanism"

    • Separated from code;

    • Reconfigurable for different environments or even dynamically

  • Automated "weaving" ‏at compile and/or run time


History of aop for java

"History" of AOP for Java

  • Original implementation in AspectJ only for fanatics

    • AspectJ introduced a "preprocessor" which augmented the standard Java language

    • After JDK 1.5 introduced annotations, AspectJ converted to use standard JDK annotations

  • AspectWerkz emerged as the "lightweight" alternative; later merged into AspectJ

  • JBoss-AOP is specific to JBOSS EJB3 application server

  • As AOP became more mainstream and numerous AOP alternatives emerged, AOP Alliance created a standard


Spring support for wider other aop

Spring Support for wider/other AOP

  • Spring is compliant with the AOP Alliance interface for around advice using method interception

  • "InjectedAspectJ aspects"

    • Spring can weave into an application's class files as they are being loaded into the Java virtual machine

    • called Load-Time Weaving (LTW)‏

    • see Spring Reference Doc. (Sec. 6.8.4 in Spring 2.5.5; Sec. 7.8 in Spring 3.0)‏


Aop basic concepts

AOP: Basic Concepts

  • Aspect: a crosscutting or extrafunctional concern (e.g., transaction management).

  • Join point: a recognizable point during the execution of a program, such as the execution of a method or the handling of an exception.

  • Advice: action taken by an aspect at a particular join point.

  • Pointcut: a set of join points; a language to describe matching join points.

  • Target object: object being advised by one or more aspects. Also referred to as the advised object.

  • AOP proxy: an object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on).

  • Weaving: linking aspects with other application types or objects to create an advised object.

  • Introduction: declaring additional methods or fields on behalf of a type.


Aop meter reading analogy sia 2 book

AOP: Meter reading analogy (SIA 2 book)‏

  • Aspect: meter reader's daily combination of what to do, where

  • Join point: which devices to read

  • Advice: recording the reading; re-marking the device

  • Pointcut: which premises to visit.

  • Introduction: ad hoc actions, based on phoning headquarters.

    But it's hard to get these to work in the real-world analogy, since they are implementation mechanisms.

  • Target object

  • AOP proxy

  • Weaving


Aop architecture

AOP Architecture

  • Low-level implementation layer

    • Mechanisms to implement weaving on the target platform

    • Environment-specific

  • Middle-level functionality layer

    • Declarative specification or meaning, plus

    • Mechanisms to implements these semantics

    • Bound to a particular environment

  • Application-level development layer

    • Language (UI/modeling tool?) to customize the specification

    • Other tools such as type-checking, trace/visualization tools, debuggers...


Aop concepts in spring

AOP Concepts in Spring

  • Aspect: POJOs; may implement Aspect interfaces or be annotated with @Aspect.

  • Join point: intercepting method execution.

  • Advice: method; may have reflection-like signature; Spring establishes a chain of interceptors around the join point.

  • Pointcut: AspectJ pointcut expression language by default; alsoJdkRegexp and Default Pointcuts.

  • Target object: an object which is wrapped by a runtime proxy.

  • AOP proxy :JDK dynamic proxy or a CGLIB proxy, implemented by Spring.

  • Weaving: performed at runtime during Spring container intialization.

  • Introduction: for example, Spring can introduce the IsModified interface to make a bean support a caching strategy.


Kinds of spring advice

Kinds of Spring Advice

  • Before

    • org.springframework.aop.MethodBeforeAdvice

  • After returning

    • org.springframework.aop.AfterReturningAdvice

  • After throwing

    • org.springframework.aop.AfterReturningAdvice

  • Around

    • org.aopalliance.intercept.MethodInterceptor

  • Introduction

    • org.springframework.aop.IntroductionInterceptor


Spring aop options

Spring AOP Options

  • "Classic" Spring AOP (ProxyFactoryBean/AutoProxyCreator)‏

    • all versions of Spring

    • can use table-like Java code, or code-like sections in Spring config

    • "Spring AOP Support/Classic Spring proxy-based AOP"

  • XML AOP (Auto Created Proxy)‏

    • Spring 2.x+ only

    • No footprint in POJO's

    • "Schema-based AOP Support/Pure POJO Aspects"

  • @AspectJ AOP (Auto Created Proxy)‏

    • Spring 2.x+ only

    • Advice, pointcuts are in Java annotations (includes needed)‏

    • "@AspectJ [email protected] annotation-driven aspects"


Classic proxy based spring aop mechanism

"Classic" Proxy-based Spring AOP Mechanism

  • During bean post processing phase of Spring setup, the ProxyFactory will create and hook in the Proxy

  • Core functionality applies Advice (regular Java code) at Pointcuts (specified methods) through intercepting when the advised class implements an interface

  • This works using the JDK Proxy mechanism, which intercepts interface methods)‏

  • The bean needs to be a ProxyFactory which hooks up the the "Advice" to the "Advised"

  • This can be done in code (which implies it can be done on-the-fly if desired) OR in Spring xml config


Implementation level spring aop alternatives 1

Implementation-Level Spring AOP Alternatives (1)‏

  • Mechanism: "traditional"JDK Proxyversus CGLIB proxies

  • What is the difference?

    • CGLIB dynamically generates bytecode for new subclass which overrides advised methods

    • Only CGLIB-generated proxies can provide exact type match to proxied object

    • CGLIB restrictions:

      • cannot override final methods

      • must configure added CGLIB jar file


Implementation level spring aop alternatives 2

Implementation-Level Spring AOP Alternatives (2)‏

  • Which is more efficient?

    • JDK Proxy intercepts every method, whether or not code needs injected; CGLIB will only override methods that need code injection

    • For CGLIB, constructor invoked twice: on both actual proxied object and an instance of generated subclass that implements the advice.

    • Both potentially optimizable by HotSpot JVM

  • Which will Spring choose?

    • JDK dynamic proxies are preferred if there's a choice

    • Spring 2.0: JDK Proxy for target objects that implement at least one interface; otherwise CGLIB


  • Login