SlideShare a Scribd company logo
1 of 47
Download to read offline
J SR-2 9 9
       Co n t e x t & De p e n d e n c y
                          Injec t ion
Max Rydahl Andersen
JBossian, Red Hat
27th. November



                                  1
Ro a d M a p




 Background
 Concepts
 Status




  2            M a x Ry d a h l A n d e r s e n
J av a EE 6

• The EE 6 web profile removes most of the “cruft” that
 has developed over the years
   • mainly totally useless stuff like web services, EJB 2 entity
      beans etc.
   • some useful stuff (e.g. JMS) is missing, but vendors can
      include it




  3                   M a x Ry d a h l A n d e r s e n
J av a EE 6

• EJB 3.1 - asynch, no-interface views, embeddable
• JPA 2.0 - typesafe criteria API, many more O/R mapping
 options
• JSF 2.0 - Ajax, easy component creation, bookmarkable
 URLs
• Bean Validation 1.0 - annotation-based validation API
• Servlet 3.0 - async support, better support for
 frameworks
• Standard global JNDI names
• Managed Beans

  4                 M a x Ry d a h l A n d e r s e n
Managed Beans

• Container-managed POJOs with minimal requirements
• support a set of basic services
  • resource injection
  • lifecycle callbacks
  • interceptors




  5                   M a x Ry d a h l A n d e r s e n
Managed Beans

• the foundation for all other component types in the
 platform
   • core services centralized under Managed Beans
• Other specifications will add support for additional
 services
   • remoting
   • instance pooling
   • web services




   6                    M a x Ry d a h l A n d e r s e n
Go a l s

• JSR-299 defines a unifying dependency injection and
 contextual lifecycle model for Java EE 6
   • a completely new, richer dependency management
       model
   • designed for use with stateful objects
   • integrates the “web” and “transactional” tiers
   • makes it much easier to build applications using JSF and
       EJB together
   • includes a complete SPI allowing third-party frameworks
       to integrate cleanly in the EE 6 environment



   7                    M a x Ry d a h l A n d e r s e n
Loose c oupling

• Events, interceptors and decorators enhance the loose-
 coupling that is inherent in this model:
   • event notifications decouple event producers from event
      consumers
   • interceptors decouple technical concerns from business
      logic
   • decorators allow business concerns to be
      compartmentalized




  8                  M a x Ry d a h l A n d e r s e n
Go i n g b e yo n d t h e s p e c

• Weld provides extra integrations
   • Tomcat/Jetty/Google App Engine support
   • Java SE support
   • OSGi containers
   • ???




   9                  M a x Ry d a h l A n d e r s e n
Go i n g b e yo n d t h e s p e c

• and features which can be used in any CDI
 environment
   • Seam2 bridge
   • Spring bridge
   • Wicket support
   • Logger
   • Prototype new ideas for the next version of the spec




   10                 M a x Ry d a h l A n d e r s e n
Se a m 3

• Use the CDI core
• Provide a development environment
  • JBoss Tools
  • Seam-gen (command line tool)




  11               M a x Ry d a h l A n d e r s e n
Se a m 3

• include a set of modules for any container which
 includes CDI
   • jBPM integration
   • Seam Security
   • Reporting (Excel/PDF)
   • Mail
   • etc.




  12                M a x Ry d a h l A n d e r s e n
Ro a d M a p




  Background
  Concepts
  Status




  13           M a x Ry d a h l A n d e r s e n
Es s e n t i a l i n g r e d i e n t s

• API types
• Qualifier annotations
• Scope
• Alternatives
• A name (optional)
• Interceptors and Decorators
• The implementation



    14                      M a x Ry d a h l A n d e r s e n
Si m p l e Ex a m p l e




public class Hello {                                     Any Managed Bean
   public String sayHello(String name) {
      return "hello" + name;                             can use these
   }                                                     services
}



@Stateless                                               So can EJBs
public class Hello {
   public String sayHello(String name) {
      return "hello" + name;
   }
}


   15                 M a x Ry d a h l A n d e r s e n
Si m p l e Ex a m p l e




public class Printer {                                   @Inject defines an
                                                         injection point. @Default
    @Inject Hello hello;                                 qualifier is assumed
    public void printHello() {
       System.out.println( hello.sayHello("world") );
    }
}




    16                M a x Ry d a h l A n d e r s e n
Co n s t r u c t o r i n j e c t i o n



                                                                  Mark the constructor to be
public class Printer {                                            called by the container
   private Hello hello;                                           @Inject
      @Inject
      public Printer(Hello hello) { this.hello=hello; }

      public void printHello() {
         System.out.println( hello.sayHello("world") );
      }
}


                                                                   Constructors are injected by
                                                                   default; @Default is the
                                                                   default qualifier
        17                     M a x Ry d a h l A n d e r s e n
We b B e a n N a m e s




@Named("hello")
public class Hello {
                                          By default not
   public String sayHello(String name) { available through EL.
      return "hello" + name;
   }
}                                  If no name is specified, then
                                                         a default name is used. Both
                                                         these Managed Beans have
@Named                                                   the same name
public class Hello {
   public String sayHello(String name) {
       return "hello" + name;
   }
}
   18                 M a x Ry d a h l A n d e r s e n
J SF Pa g e




<h:commandButton value=“Say Hello”
                 action=“#{hello.sayHello}”/>


                                                        Calling an action on a
                                                        bean through EL




   19                M a x Ry d a h l A n d e r s e n
Qu a l i f i e r




   A qualifier is an annotation that lets a client choose
  between multiple implementations of an API at runtime




    20               M a x Ry d a h l A n d e r s e n
De f i n e a q u a l i f i e r




@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
@Qualifier
public @interface Casual {}                                   Creating a qualifer
                                                              is really easy!




    21                     M a x Ry d a h l A n d e r s e n
Using a qualifier




@Casual
                                                         We also specify the
public class Hi extends Hello {
   public String sayHello(String name) {
                                                         @Casual qualifier. If
      return "hi" + name;                                no qualifer is specified
   }                                                     on a bean, @Default
}                                                        is assumed




    22                M a x Ry d a h l A n d e r s e n
Using a qualifier




                                                         Here we inject the Hello
                                                         bean, and require an
public class Printer {                                   implementation which is
   @Inject @Casual Hello hello;                          qualified by @Casual
   public void printHello() {
      System.out.println( hello.sayHello("JBoss") );
   }
}




    23                M a x Ry d a h l A n d e r s e n
A l t e r n at i ve s

• An alternative bean is one which must be specifically
 enabled for a particular deployment
    • It replaces the managed or session bean for which it is
         an alternative
    • May also completely replace it
           • all producers and observers defined on original bean are
            disabled for this deployment)
    • Alternatives enabled in XML deployment descriptor




    24                       M a x Ry d a h l A n d e r s e n
De f i n i n g a n a l t e r n at i ve




@Alternative                                                 Same API, different
public class Hola extends Hello {                            implementation

    public String sayHello(String name) {
       return "hola " + name;
    }

}




    25                    M a x Ry d a h l A n d e r s e n
En a b l i n g a n a l t e r n at i ve




<beans>
  <alternatives>
    <class>com.acme.Hola</class>
    <sterotype>com.acme.SouthernEuropean</stereotype>
  </alternatives>
</beans>



                                             Can also define a sterotype as
                                             an alternatives. Any
                                             stereotyped beans will be an
                                             alternative
    26                    M a x Ry d a h l A n d e r s e n
St e r e o t y p e s

• We have common architectural “patterns” in our
 application, with recurring roles
    • Capture the roles using stereotypes




   27                  M a x Ry d a h l A n d e r s e n
St e r e o t y p e s

• A stereotype encapsulates any combination of:
    • a default scope, and
    • a set of interceptor bindings.
• A stereotype may also specify that:
    • all beans with the stereotype have defaulted bean EL
        names
    • all beans with the stereotype are alternatives




   28                   M a x Ry d a h l A n d e r s e n
Cr e at i n g a s t e r e o t y p e




@RequestScoped                                                Scope
@Named
@Alternative
@Stereotype                                                 Has a defaulted name
@Retention(RUNTIME)
@Target(TYPE)
public @interface AlternativeAction{}
                                                            All stereotyped beans
                                                            become alternatives




    29                   M a x Ry d a h l A n d e r s e n
Using a st ereot ype




@AlternativeAction
public class Hello {
   public String sayHello(String name) {
      return "hi " + name;
   }
}




    30                M a x Ry d a h l A n d e r s e n
Sc o p e s a n d Co n t ex t s

• Built-in scopes:
   • Any servlet - @ApplicationScoped,
        @RequestScoped, @SessionScoped
   • JSF requests - @ConversationScoped
   • Dependent scope (De fa u l t ): @Dependent
• Custom scopes
   • A scope type is an annotation, can write your own
        context implementation and scope type annotation




   31                   M a x Ry d a h l A n d e r s e n
Sc o p e s




@SessionScoped
public class Login {                                     Session scoped
   private User user;
   public void login() {
      user = ...;
   }
   public User getUser() { return user; }
}




    32                M a x Ry d a h l A n d e r s e n
Sc o p e s




public class Printer {
                                                            No coupling between
     @Inject Hello hello;                                   scope and use of
     @Inject Login login;                                   implementation
     public void printHello() {
        System.out.println(
           hello.sayHello( login.getUser().getName() ) );
     }
}




       33                M a x Ry d a h l A n d e r s e n
Pr o d u c e r m e t h o d s

• Producer methods allow control over the production of a
 bean where:
   • the objects to be injected are not managed instances
   • the concrete type of the objects to be injected may vary
        at runtime
   • the objects require some custom initialization that is not
        performed by the bean constructor




   34                   M a x Ry d a h l A n d e r s e n
Pr o d u c e r m e t h o d s




@SessionScoped
public class Login {
   private User user;
   public void login() {
      user = ...;
   }

    @Produces
    User getUser() { return user; }
}




    35                 M a x Ry d a h l A n d e r s e n
Pr o d u c e r m e t h o d s




public class Printer {
   @Inject Hello hello;
   @Inject User user;                      Much better, no
   public void hello() {                   dependency on
      System.out.println(                  Login!
         hello.sayHello( user.getName() ) );
   }
}




   36                  M a x Ry d a h l A n d e r s e n
Pr o d u c e r Fi e l d s

• Simpler alternative to Producer methods


                                                               Similar to
@SessionScoped                                                 outjection in
public class Login {
                                                               Seam
    @Produces @LoggedIn @RequestScoped
    private User user;

    public void login() {
       user = ...;
    }
}



    37                      M a x Ry d a h l A n d e r s e n
J av a EE Re s o u r c e s




public class PricesTopic {
   @Produces @Prices
   @Resource(name="java:global/env/jms/Prices")
   Topic pricesTopic;
}


public class UserDatabasePersistenceContext {
   @Produces @UserDatabase
   @PersistenceContext
   EntityManager userDatabase;
}

   38                M a x Ry d a h l A n d e r s e n
Eve n t s

• Event producers raise events that are then delivered to
 event observers by the Web Bean manager.
   • not only are event producers decoupled from observers;
        observers are completely decoupled from producers
   • observers can specify a combination of "selectors" to
        narrow the set of event notifications they will receive
   • observers can be notified immediately, or can specify that
        delivery of the event should be delayed until the end of
        the current transaction




   39                     M a x Ry d a h l A n d e r s e n
Ev e n t s                  Inject an instance of Event. Additional
                                qualifiers can be specified to narrow the
                                event consumers called. API type
                                specified as a parameter on Event


public class Hello {

     @Inject @Any Event<Greeting> greeting;

     public void sayHello(String name) {
        greeting.fire( new Greeting("hello " + name) );
     }

}

                                    “Fire” an event, the
                                    producer will be notified


       40               M a x Ry d a h l A n d e r s e n
Ev e n t s




                                                      Observer methods, take the API
public class Printer {                                type and additional qualifiers
     void onGreeting(@Observes Greeting greeting,
                     @Default User user) {
        System.out.println(user + “ says “ + greeting);
     }

}
                                                            Additional parameters can
                                                            be specified and will be
                                                            injected by the container

       41                M a x Ry d a h l A n d e r s e n
Ro a d M a p




  Background
  Concepts
  Status




  42           M a x Ry d a h l A n d e r s e n
J SR-2 9 9 : Co n t ex t s a n d De p e n d e n c y
I n j e c t i o n fo r J av a EE
• Proposed Final Draft 2 published
• Reference Manual being written now
   • http://www.seamframework.org/Weld
   • look for an update soon!
• Send feedback to jsr-299-comments@jcp.org




   43                 M a x Ry d a h l A n d e r s e n
We l d

• The Reference implementation
• Feature complete preview of PFD2. Download it, try it
 out, give feedback!
   • http://seamframework.org/Download
• Working on second release candidate




   44                  M a x Ry d a h l A n d e r s e n
We l d

• Integrated into:
   • JBoss 5.1.0.GA and above (6.0.0.Beta1 coming soon)
   • GlassFish V3 (get a recent build)
• Available as an addon for:
   • Tomcat 6.0.x
   • Jetty 6.1.x
   • Java SE
   • Google App Engine



   45                M a x Ry d a h l A n d e r s e n
J B o s s CDI To o l s (Wo r k i n p r o g r e s s )

• Code completion for @Named components
• Validation of CDI constructs (”red squigly lines”)
   • Ambigious injection points
   • Non-matching injection
   •…
• CDI component explorer
• Show possible injection points for a given line
• Show matching event types
• Refactoring of EL result in updates to @Named
• ...
   46
Q& A




http://in.relation.to/Bloggers/Max


http://www.seamframework.org/Weld


http://jcp.org/en/jsr/detail?id=299




    47                 M a x Ry d a h l A n d e r s e n

More Related Content

What's hot

You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix itRafael Dohms
 
Introduction to Clean Code
Introduction to Clean CodeIntroduction to Clean Code
Introduction to Clean CodeJulio Martinez
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboardsDenis Ristic
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL ExplainMYXPLAIN
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Juriy Zaytsev
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsGuilherme Blanco
 
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorFedor Lavrentyev
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHPGuilherme Blanco
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 

What's hot (20)

You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Introduction to Clean Code
Introduction to Clean CodeIntroduction to Clean Code
Introduction to Clean Code
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL Explain
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
SOLID Ruby SOLID Rails
SOLID Ruby SOLID RailsSOLID Ruby SOLID Rails
SOLID Ruby SOLID Rails
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
 
Php 26
Php 26Php 26
Php 26
 
C# 7
C# 7C# 7
C# 7
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 

Viewers also liked

Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMJBug Italy
 
April 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesApril 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesJBug Italy
 
Intro JBug Milano - January 2012
Intro JBug Milano - January 2012Intro JBug Milano - January 2012
Intro JBug Milano - January 2012JBug Italy
 
October 2009 - JBoss Cloud
October 2009 - JBoss CloudOctober 2009 - JBoss Cloud
October 2009 - JBoss CloudJBug Italy
 
October 2009 - Open Meeting
October 2009 - Open MeetingOctober 2009 - Open Meeting
October 2009 - Open MeetingJBug Italy
 
Intro jbug milano_26_set2012
Intro jbug milano_26_set2012Intro jbug milano_26_set2012
Intro jbug milano_26_set2012JBug Italy
 
September 2010 - Arquillian
September 2010 - ArquillianSeptember 2010 - Arquillian
September 2010 - ArquillianJBug Italy
 
All the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSAll the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSJBug Italy
 

Viewers also liked (8)

Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGM
 
April 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesApril 2010 - JBoss Web Services
April 2010 - JBoss Web Services
 
Intro JBug Milano - January 2012
Intro JBug Milano - January 2012Intro JBug Milano - January 2012
Intro JBug Milano - January 2012
 
October 2009 - JBoss Cloud
October 2009 - JBoss CloudOctober 2009 - JBoss Cloud
October 2009 - JBoss Cloud
 
October 2009 - Open Meeting
October 2009 - Open MeetingOctober 2009 - Open Meeting
October 2009 - Open Meeting
 
Intro jbug milano_26_set2012
Intro jbug milano_26_set2012Intro jbug milano_26_set2012
Intro jbug milano_26_set2012
 
September 2010 - Arquillian
September 2010 - ArquillianSeptember 2010 - Arquillian
September 2010 - Arquillian
 
All the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSAll the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMS
 

Similar to InterceptorBindings({ Logged.class, Transactional.class})@Stereotype@Target({TYPE, METHOD, FIELD})@Retention(RUNTIME)public @interface Assistant {} 29 M a x Ry d a h l A n d e r s e n Us i n g a s t e r e o t y p e@Assistantpublic class HelpDesk { public void helpCustomer() { //... }}This bean will be:- Request scoped- Have the Logged and Transactional interceptors- Potentially have a default name 30 M a

Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Ray Ploski
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir DresherTamir Dresher
 
C# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesC# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesAbhishek Sur
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developementfrwebhelp
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformArun Gupta
 
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 EcosystemSpark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 EcosystemArun Gupta
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30myrajendra
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonCodemotion
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
H2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy WangH2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy WangSri Ambati
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...yazad dumasia
 

Similar to InterceptorBindings({ Logged.class, Transactional.class})@Stereotype@Target({TYPE, METHOD, FIELD})@Retention(RUNTIME)public @interface Assistant {} 29 M a x Ry d a h l A n d e r s e n Us i n g a s t e r e o t y p e@Assistantpublic class HelpDesk { public void helpCustomer() { //... }}This bean will be:- Request scoped- Have the Logged and Transactional interceptors- Potentially have a default name 30 M a (20)

Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Introduction To Web Beans
Introduction To Web BeansIntroduction To Web Beans
Introduction To Web Beans
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
C# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesC# 7.0 Hacks and Features
C# 7.0 Hacks and Features
 
C++primer
C++primerC++primer
C++primer
 
From Java to Python
From Java to PythonFrom Java to Python
From Java to Python
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 Platform
 
Introduction to CDI
Introduction to CDIIntroduction to CDI
Introduction to CDI
 
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 EcosystemSpark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
H2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy WangH2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy Wang
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 

More from JBug Italy

JBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBug Italy
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBossJBug Italy
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzJBug Italy
 
JBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBug Italy
 
JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 OverviewJBug Italy
 
JBoss AS7 Webservices
JBoss AS7 WebservicesJBoss AS7 Webservices
JBoss AS7 WebservicesJBug Italy
 
Intro JBug Milano - September 2011
Intro JBug Milano - September 2011Intro JBug Milano - September 2011
Intro JBug Milano - September 2011JBug Italy
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridJBug Italy
 
Drools Introduction
Drools IntroductionDrools Introduction
Drools IntroductionJBug Italy
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - GateinJBug Italy
 
May 2010 - Infinispan
May 2010 - InfinispanMay 2010 - Infinispan
May 2010 - InfinispanJBug Italy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
May 2010 - Drools flow
May 2010 - Drools flowMay 2010 - Drools flow
May 2010 - Drools flowJBug Italy
 
May 2010 - Hibernate search
May 2010 - Hibernate searchMay 2010 - Hibernate search
May 2010 - Hibernate searchJBug Italy
 
April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5JBug Italy
 
JavaDayIV - Leoncini Writing Restful Applications With Resteasy
JavaDayIV - Leoncini Writing Restful Applications With ResteasyJavaDayIV - Leoncini Writing Restful Applications With Resteasy
JavaDayIV - Leoncini Writing Restful Applications With ResteasyJBug Italy
 
November 2009 - Walking on thin ice… from SOA to EDA
November 2009 - Walking on thin ice… from SOA to EDANovember 2009 - Walking on thin ice… from SOA to EDA
November 2009 - Walking on thin ice… from SOA to EDAJBug Italy
 

More from JBug Italy (20)

JBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testing
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
AS7 and CLI
AS7 and CLIAS7 and CLI
AS7 and CLI
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
 
AS7
AS7AS7
AS7
 
JBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logic
 
JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 Overview
 
JBoss AS7 Webservices
JBoss AS7 WebservicesJBoss AS7 Webservices
JBoss AS7 Webservices
 
JBoss AS7
JBoss AS7JBoss AS7
JBoss AS7
 
Intro JBug Milano - September 2011
Intro JBug Milano - September 2011Intro JBug Milano - September 2011
Intro JBug Milano - September 2011
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data Grid
 
Drools Introduction
Drools IntroductionDrools Introduction
Drools Introduction
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - Gatein
 
May 2010 - Infinispan
May 2010 - InfinispanMay 2010 - Infinispan
May 2010 - Infinispan
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
May 2010 - Drools flow
May 2010 - Drools flowMay 2010 - Drools flow
May 2010 - Drools flow
 
May 2010 - Hibernate search
May 2010 - Hibernate searchMay 2010 - Hibernate search
May 2010 - Hibernate search
 
April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5
 
JavaDayIV - Leoncini Writing Restful Applications With Resteasy
JavaDayIV - Leoncini Writing Restful Applications With ResteasyJavaDayIV - Leoncini Writing Restful Applications With Resteasy
JavaDayIV - Leoncini Writing Restful Applications With Resteasy
 
November 2009 - Walking on thin ice… from SOA to EDA
November 2009 - Walking on thin ice… from SOA to EDANovember 2009 - Walking on thin ice… from SOA to EDA
November 2009 - Walking on thin ice… from SOA to EDA
 

Recently uploaded

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

InterceptorBindings({ Logged.class, Transactional.class})@Stereotype@Target({TYPE, METHOD, FIELD})@Retention(RUNTIME)public @interface Assistant {} 29 M a x Ry d a h l A n d e r s e n Us i n g a s t e r e o t y p e@Assistantpublic class HelpDesk { public void helpCustomer() { //... }}This bean will be:- Request scoped- Have the Logged and Transactional interceptors- Potentially have a default name 30 M a

  • 1. J SR-2 9 9 Co n t e x t & De p e n d e n c y Injec t ion Max Rydahl Andersen JBossian, Red Hat 27th. November 1
  • 2. Ro a d M a p Background Concepts Status 2 M a x Ry d a h l A n d e r s e n
  • 3. J av a EE 6 • The EE 6 web profile removes most of the “cruft” that has developed over the years • mainly totally useless stuff like web services, EJB 2 entity beans etc. • some useful stuff (e.g. JMS) is missing, but vendors can include it 3 M a x Ry d a h l A n d e r s e n
  • 4. J av a EE 6 • EJB 3.1 - asynch, no-interface views, embeddable • JPA 2.0 - typesafe criteria API, many more O/R mapping options • JSF 2.0 - Ajax, easy component creation, bookmarkable URLs • Bean Validation 1.0 - annotation-based validation API • Servlet 3.0 - async support, better support for frameworks • Standard global JNDI names • Managed Beans 4 M a x Ry d a h l A n d e r s e n
  • 5. Managed Beans • Container-managed POJOs with minimal requirements • support a set of basic services • resource injection • lifecycle callbacks • interceptors 5 M a x Ry d a h l A n d e r s e n
  • 6. Managed Beans • the foundation for all other component types in the platform • core services centralized under Managed Beans • Other specifications will add support for additional services • remoting • instance pooling • web services 6 M a x Ry d a h l A n d e r s e n
  • 7. Go a l s • JSR-299 defines a unifying dependency injection and contextual lifecycle model for Java EE 6 • a completely new, richer dependency management model • designed for use with stateful objects • integrates the “web” and “transactional” tiers • makes it much easier to build applications using JSF and EJB together • includes a complete SPI allowing third-party frameworks to integrate cleanly in the EE 6 environment 7 M a x Ry d a h l A n d e r s e n
  • 8. Loose c oupling • Events, interceptors and decorators enhance the loose- coupling that is inherent in this model: • event notifications decouple event producers from event consumers • interceptors decouple technical concerns from business logic • decorators allow business concerns to be compartmentalized 8 M a x Ry d a h l A n d e r s e n
  • 9. Go i n g b e yo n d t h e s p e c • Weld provides extra integrations • Tomcat/Jetty/Google App Engine support • Java SE support • OSGi containers • ??? 9 M a x Ry d a h l A n d e r s e n
  • 10. Go i n g b e yo n d t h e s p e c • and features which can be used in any CDI environment • Seam2 bridge • Spring bridge • Wicket support • Logger • Prototype new ideas for the next version of the spec 10 M a x Ry d a h l A n d e r s e n
  • 11. Se a m 3 • Use the CDI core • Provide a development environment • JBoss Tools • Seam-gen (command line tool) 11 M a x Ry d a h l A n d e r s e n
  • 12. Se a m 3 • include a set of modules for any container which includes CDI • jBPM integration • Seam Security • Reporting (Excel/PDF) • Mail • etc. 12 M a x Ry d a h l A n d e r s e n
  • 13. Ro a d M a p Background Concepts Status 13 M a x Ry d a h l A n d e r s e n
  • 14. Es s e n t i a l i n g r e d i e n t s • API types • Qualifier annotations • Scope • Alternatives • A name (optional) • Interceptors and Decorators • The implementation 14 M a x Ry d a h l A n d e r s e n
  • 15. Si m p l e Ex a m p l e public class Hello { Any Managed Bean public String sayHello(String name) { return "hello" + name; can use these } services } @Stateless So can EJBs public class Hello { public String sayHello(String name) { return "hello" + name; } } 15 M a x Ry d a h l A n d e r s e n
  • 16. Si m p l e Ex a m p l e public class Printer { @Inject defines an injection point. @Default @Inject Hello hello; qualifier is assumed public void printHello() { System.out.println( hello.sayHello("world") ); } } 16 M a x Ry d a h l A n d e r s e n
  • 17. Co n s t r u c t o r i n j e c t i o n Mark the constructor to be public class Printer { called by the container private Hello hello; @Inject @Inject public Printer(Hello hello) { this.hello=hello; } public void printHello() { System.out.println( hello.sayHello("world") ); } } Constructors are injected by default; @Default is the default qualifier 17 M a x Ry d a h l A n d e r s e n
  • 18. We b B e a n N a m e s @Named("hello") public class Hello { By default not public String sayHello(String name) { available through EL. return "hello" + name; } } If no name is specified, then a default name is used. Both these Managed Beans have @Named the same name public class Hello { public String sayHello(String name) { return "hello" + name; } } 18 M a x Ry d a h l A n d e r s e n
  • 19. J SF Pa g e <h:commandButton value=“Say Hello” action=“#{hello.sayHello}”/> Calling an action on a bean through EL 19 M a x Ry d a h l A n d e r s e n
  • 20. Qu a l i f i e r A qualifier is an annotation that lets a client choose between multiple implementations of an API at runtime 20 M a x Ry d a h l A n d e r s e n
  • 21. De f i n e a q u a l i f i e r @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) @Qualifier public @interface Casual {} Creating a qualifer is really easy! 21 M a x Ry d a h l A n d e r s e n
  • 22. Using a qualifier @Casual We also specify the public class Hi extends Hello { public String sayHello(String name) { @Casual qualifier. If return "hi" + name; no qualifer is specified } on a bean, @Default } is assumed 22 M a x Ry d a h l A n d e r s e n
  • 23. Using a qualifier Here we inject the Hello bean, and require an public class Printer { implementation which is @Inject @Casual Hello hello; qualified by @Casual public void printHello() { System.out.println( hello.sayHello("JBoss") ); } } 23 M a x Ry d a h l A n d e r s e n
  • 24. A l t e r n at i ve s • An alternative bean is one which must be specifically enabled for a particular deployment • It replaces the managed or session bean for which it is an alternative • May also completely replace it • all producers and observers defined on original bean are disabled for this deployment) • Alternatives enabled in XML deployment descriptor 24 M a x Ry d a h l A n d e r s e n
  • 25. De f i n i n g a n a l t e r n at i ve @Alternative Same API, different public class Hola extends Hello { implementation public String sayHello(String name) { return "hola " + name; } } 25 M a x Ry d a h l A n d e r s e n
  • 26. En a b l i n g a n a l t e r n at i ve <beans> <alternatives> <class>com.acme.Hola</class> <sterotype>com.acme.SouthernEuropean</stereotype> </alternatives> </beans> Can also define a sterotype as an alternatives. Any stereotyped beans will be an alternative 26 M a x Ry d a h l A n d e r s e n
  • 27. St e r e o t y p e s • We have common architectural “patterns” in our application, with recurring roles • Capture the roles using stereotypes 27 M a x Ry d a h l A n d e r s e n
  • 28. St e r e o t y p e s • A stereotype encapsulates any combination of: • a default scope, and • a set of interceptor bindings. • A stereotype may also specify that: • all beans with the stereotype have defaulted bean EL names • all beans with the stereotype are alternatives 28 M a x Ry d a h l A n d e r s e n
  • 29. Cr e at i n g a s t e r e o t y p e @RequestScoped Scope @Named @Alternative @Stereotype Has a defaulted name @Retention(RUNTIME) @Target(TYPE) public @interface AlternativeAction{} All stereotyped beans become alternatives 29 M a x Ry d a h l A n d e r s e n
  • 30. Using a st ereot ype @AlternativeAction public class Hello { public String sayHello(String name) { return "hi " + name; } } 30 M a x Ry d a h l A n d e r s e n
  • 31. Sc o p e s a n d Co n t ex t s • Built-in scopes: • Any servlet - @ApplicationScoped, @RequestScoped, @SessionScoped • JSF requests - @ConversationScoped • Dependent scope (De fa u l t ): @Dependent • Custom scopes • A scope type is an annotation, can write your own context implementation and scope type annotation 31 M a x Ry d a h l A n d e r s e n
  • 32. Sc o p e s @SessionScoped public class Login { Session scoped private User user; public void login() { user = ...; } public User getUser() { return user; } } 32 M a x Ry d a h l A n d e r s e n
  • 33. Sc o p e s public class Printer { No coupling between @Inject Hello hello; scope and use of @Inject Login login; implementation public void printHello() { System.out.println( hello.sayHello( login.getUser().getName() ) ); } } 33 M a x Ry d a h l A n d e r s e n
  • 34. Pr o d u c e r m e t h o d s • Producer methods allow control over the production of a bean where: • the objects to be injected are not managed instances • the concrete type of the objects to be injected may vary at runtime • the objects require some custom initialization that is not performed by the bean constructor 34 M a x Ry d a h l A n d e r s e n
  • 35. Pr o d u c e r m e t h o d s @SessionScoped public class Login { private User user; public void login() { user = ...; } @Produces User getUser() { return user; } } 35 M a x Ry d a h l A n d e r s e n
  • 36. Pr o d u c e r m e t h o d s public class Printer { @Inject Hello hello; @Inject User user; Much better, no public void hello() { dependency on System.out.println( Login! hello.sayHello( user.getName() ) ); } } 36 M a x Ry d a h l A n d e r s e n
  • 37. Pr o d u c e r Fi e l d s • Simpler alternative to Producer methods Similar to @SessionScoped outjection in public class Login { Seam @Produces @LoggedIn @RequestScoped private User user; public void login() { user = ...; } } 37 M a x Ry d a h l A n d e r s e n
  • 38. J av a EE Re s o u r c e s public class PricesTopic { @Produces @Prices @Resource(name="java:global/env/jms/Prices") Topic pricesTopic; } public class UserDatabasePersistenceContext { @Produces @UserDatabase @PersistenceContext EntityManager userDatabase; } 38 M a x Ry d a h l A n d e r s e n
  • 39. Eve n t s • Event producers raise events that are then delivered to event observers by the Web Bean manager. • not only are event producers decoupled from observers; observers are completely decoupled from producers • observers can specify a combination of "selectors" to narrow the set of event notifications they will receive • observers can be notified immediately, or can specify that delivery of the event should be delayed until the end of the current transaction 39 M a x Ry d a h l A n d e r s e n
  • 40. Ev e n t s Inject an instance of Event. Additional qualifiers can be specified to narrow the event consumers called. API type specified as a parameter on Event public class Hello { @Inject @Any Event<Greeting> greeting; public void sayHello(String name) { greeting.fire( new Greeting("hello " + name) ); } } “Fire” an event, the producer will be notified 40 M a x Ry d a h l A n d e r s e n
  • 41. Ev e n t s Observer methods, take the API public class Printer { type and additional qualifiers void onGreeting(@Observes Greeting greeting, @Default User user) { System.out.println(user + “ says “ + greeting); } } Additional parameters can be specified and will be injected by the container 41 M a x Ry d a h l A n d e r s e n
  • 42. Ro a d M a p Background Concepts Status 42 M a x Ry d a h l A n d e r s e n
  • 43. J SR-2 9 9 : Co n t ex t s a n d De p e n d e n c y I n j e c t i o n fo r J av a EE • Proposed Final Draft 2 published • Reference Manual being written now • http://www.seamframework.org/Weld • look for an update soon! • Send feedback to jsr-299-comments@jcp.org 43 M a x Ry d a h l A n d e r s e n
  • 44. We l d • The Reference implementation • Feature complete preview of PFD2. Download it, try it out, give feedback! • http://seamframework.org/Download • Working on second release candidate 44 M a x Ry d a h l A n d e r s e n
  • 45. We l d • Integrated into: • JBoss 5.1.0.GA and above (6.0.0.Beta1 coming soon) • GlassFish V3 (get a recent build) • Available as an addon for: • Tomcat 6.0.x • Jetty 6.1.x • Java SE • Google App Engine 45 M a x Ry d a h l A n d e r s e n
  • 46. J B o s s CDI To o l s (Wo r k i n p r o g r e s s ) • Code completion for @Named components • Validation of CDI constructs (”red squigly lines”) • Ambigious injection points • Non-matching injection •… • CDI component explorer • Show possible injection points for a given line • Show matching event types • Refactoring of EL result in updates to @Named • ... 46