OpenWebBeans/Web Beans

  • 11,010 views
Uploaded on

Related with introduction to OpenWebBeans and WebBeans

Related with introduction to OpenWebBeans and WebBeans

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
11,010
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
116
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Apache Incubator OpenWebBeans
    • Gurkan Erdogdu
    • Conny Lundgren
    • Matthias Wessendorf
    • Kevan Miller
    • Apache Incubator
    • Free and Open Source
  • 2. What is OpenWebBeans
    • Implementation of the JSR-299 WebBeans
    • Incubated in the Apache Software Foundation
    • http://incubator.apache.org/openwebbeans
    • http://incubator.apache.org
  • 3. What is a WebBeans?
    • Dependency injection service between Java EE components
      • EJB Components
      • Servlet Components
      • Java Beans Components
    • Easy use of EJB 3.1 components as first class managed bean in the JSF environment
    • Type-safe API deployment
    • Interceptors and Decorators
  • 4. Continue...
    • Loosely coupled components with powerful Event and Observer mechanism
    • Context management
      • Conversation context ?
    • Lifecycle management
      • Manages all of the Java EE components lifecycles
    • Extensible
      • Easily extensible with Manager runtime
  • 5. Web Bean Definition
    • Simple Web Beans
      • No action is required
      • Every Java Beans is a simpe web bean
    • Enterprise Web Beans
      • EJB session beans
    • Producer Methods
    • JMS Endpoints
  • 6. Web Bean Definition
    • API Types
    • Binding types
    • Scopes
    • Deployment types
    • Names
    • StereoTypes
    • Specialization
  • 7. API Type
    • Simple Web Bean
      • public class Bean implements IBean{}
      • Class, super class and interfaces, directly or indirectly
      • Above : Bean, IBean, Object
    • EJB Components
      • @Stateless
      • class PaymentProcessorImpl implements PaymentProcessor { ... }
      • LocalInterfaces
      • Above : Local interfaces (PaymentProcessor)
  • 8. API Type continue
    • Producer Methods
      • public Product getProduct(){}
      • Return type, super class, interfaces directly or indirectly
      • Above : Product, Object
    • JMS End points
      • Queue : Queue, QueueConnection, QueueSession and QueueSender + Object
      • Topic : Topic, TopicConnection, TopicSession and TopicPublisher + Object
  • 9. Binding Types
    • Seperates implementations from each other
    • Annotation driven
    • Annotated with @BindingType
    • Example, 2 binding types
      • @BindingType
      • public @interface CreditCardPayment
      • @BindingType
      • public @interface DebitCardPayment
  • 10. Binding Types
    • One interface, two implementation, dependency injection, just BindingType ?
    • Seperation with @BindingType, HOW?
      • public class PaymentProcessor{
      • Ipayment payment; -> Which payment type?
      • }
      • public class PaymentProcessor{
      • @CreditCardPayment IPayment payment; -> Credit Card
      • }
      • public class PaymentProcessor{
      • @DebitCardPayment IPayment payment; -> Debit Card
      • }
  • 11. Scopes
    • RequestScoped
    • SessionScoped
    • ApplicationScoped
    • ConversationScoped
    • DependentScoped
    • Or your defined scope, annotated @ScopeType
      • @ScopeType
      • Public @interface MyScope{}
  • 12. Deployment Types
    • Cleanly seperate your beans at run time
    • Test environment enabled Web Beans or Production ready web beans
    • Easy test your beans
    • Example:
      • @Production -> Use in my production run time
      • public class PaymentProcessor implement Processor { }
      • @Test -> Use in my test run time
      • public class TestProcessor implement Processor { }
      • Injection : Processor instance ??? -> which bean it selects?
  • 13. Name
    • Web Beans has name
      • @Named annotation
      • @Named(value=”actual name”)
    • Default Name, if no value is provided
      • Class Name -> public class PaymentProcessor
      • Name : paymentProcessor
      • Method name -> Products getProducts()
      • Name : products
    • No name is no @Named annotation
  • 14. StereoTypes
    • Like class inheritance
    • No repeat yourself
    • Just inherit model
    • Inherit annotations
    • Annotated with @StereoType
      • @StereoType
      • @RequestScoped
      • @Production
      • @Named
      • public @interface MyStereoType
  • 15. StereoType
    • Easily create web bean annotations
      • EXAMPLE : MyNewBean inherits from stereotypes.
      • @MyStereoType
      • public class MyNewBean{}
      • Inherit :ScopeType, DeploymentType and Default Named indicator from MyStereoType
  • 16. Specialization
    • Related with web beans resolution semantic
    • Clear in the next slides
    • Normally injection service resolves web beans with
      • API type
      • Binding Type
      • Precedence
  • 17. Specialization
    • Lets say two DeploymentType
    • Type1 and Type2 and Type1 precedence > Type2
    • Normally we want Production
      • @BindingType1
      • @Type1
      • Public class Production{}
      • @BindingType2 @BindingType1
      • @Type2
      • Public class Mock{}
  • 18. Specialization
      • public class PaymentProcessor
      • {
      • @BindingType2 @BindingType1 IPayment payment; -> we want Production??
      • }
      • But gets Mock??? Why? Resolution rules?
      • If we want always selectinh Production type web beans without Binding Type, then @Specializes rescue
      • @Specializes
      • public class Production extends Mock{} -> Inhertis all BindingTypes of Mock., now, @BindingType2 Ipayment payment selects Production
  • 19. Resolutions
    • Resolution By Name
      • Name
      • Precedence of the DeploymentType
    • Resolution By Type
      • API Type
      • BindingType
      • Precedence of the DeploymentType
  • 20. Injected Fields
    • Inject fields of the web beans
      • Public class MyBean
      • {
      • @Logger Log logger; -> Inject for me after creation
      • }
  • 21. Initializer Methods
    • Initializer Methods of the web bean
      • @Production
      • Public class PaymentProcessor
      • {
      • Ipayment payment;
      • @Initialize
      • public void createPaymentProcessor(@CreditCard IPayment processor) -> Inject for me after creation
        • this.payment = processor;
      • }
  • 22. Constructor Initializer
      • Inject into web beans constructor
      • @Production
      • @RequestScoped
      • public class PaymentProcessor
      • {
      • -> Inject into the my constructor while creating
        • public PaymentProcessor(@CreditCard Ipayment payment)
        • {
        • }
      • }
  • 23. EL Resolution
    • EL Resolution
      • Resolve by name
      • Use in JSF or JSP page
      • @RequestScoped
      • @Named
      • public class LoginBean
        • @Produces @SessionScoped @LoggedInUser @Named(value="currentUser")
      • public User getLoggedInUser()
      • { return this.user ; }
      • public void login() { User user = new User(); this.user = user;}
  • 24. EL Resolution
      • <h:inputText id=&quot;userName&quot; value=&quot;#{loginBean.userName}&quot;></h:inputText>
      • <h:inputText id=&quot;password&quot; value=&quot;#{loginBean.password}&quot;></h:inputText>
      • <h:commandButton action=&quot;#{loginBean.login}&quot; value=&quot;Login&quot;></h:commandButton>
  • 25. EL Resolution
    • Welcome Page, gets user name and password from the @CurrentUser
      • <div align=&quot;right&quot;>
      • <h:commandLink value=&quot;Logout&quot; action=&quot;#{logoutBean.logout}&quot;></h:commandLink>
      • </div>
      • <div>
      • <h:outputText value=&quot;Merhaba #{currentUser.userName} #{currentUser.password}&quot;></h:outputText>
      • </div>
  • 26. LifeCycle of WebBeans
    • Create
    • Inject fields
    • Initialize Methods
    • Life cycle annotations, @PostConstruct, @PreDestroy
    • Interceptors for orthogonal processes
    • Decorators for business processes
    • Common annotations, @EJB
    • Destroy
  • 27. Interceptors
    • Interceptor with @InterceptorBindingType
      • @InterceptorBindingType
      • Public @interface Transactional{} -> Interceptor
      • @Transactional -> Class level
      • Public class Payment{
      • @Transactional -> Method level
        • public void payment(){}
      • }
  • 28. Interceptors
    • Business Level Interceptors
      • Business method invocation
    • Life Cycle Interceptors
      • Web Bean life cycle
      • @PostConstruct
      • @PreDestroy
      • @PrePassivate
      • @PreActivate
  • 29. Interceptor Example
      • @Transactional
      • public class MyTransactionInterceptor
      • {
      • @AroundInvoke -> called just before my business method
      • public void invoke(InvocationContext context)
        • {
        • }
      • }
  • 30. Decorators
    • For specific business method
    • Can be abstract
    • Example:
      • @Decorator
      • public class MyDecorator implement Ipayment
      • { @Decorates @CreditCard IPayment payment; -> Specific web bean
      • public void pay() -> Specific business method
        • {
        • }
      • }
  • 31. Events
    • Loosely Coupled Interaction
      • Events
        • Event type
        • Event binding type
      • Observers
      • Observable annotation
      • Transactional observers
  • 32. Observers
      • public class PaymentObserver implements Observer<PaymentDoneEvent>
      • {
      • public void notify(PaymentDoneEvent event)
        • {
        • }
      • }
  • 33. Events
    • @Observes annotation, observes given event type
      • public class PaymentDoneBean
      • {
      • public void afterPayment(@Observes PaymentDoneEvent event)
        • {
        • }
      • }
  • 34. Events
    • Fire events via Manager API
      • public void pay()
      • {
      • manager.fireEvent(new PaymentDoneEvent(user))
      • }
  • 35. Event
    • @Observable annotation
    • Register observers via event
    • Custom web bean with Event API
    • Fire events via event
      • public class LoginBean
      • {
      • private @Observable Event<LoggedInEvent> event; -> Runtime provided Event bean
      • public void afterLoggedIn()
      • {
        • LoggedInEvent loggedIn = new LoggedInEvent(&quot;Gurkan&quot;);
        • event.fire(loggedIn, anns); -> Fire event via Event
        • }
  • 36. Scope and Contexts
    • Active Scope
      • Active context with respect to the current thread
    • Passive Scope
      • Passive context with respect to the current thread
      • ContextNotActiveException if access
    • Context passivation
      • Passivation in passivated type context. Save its context info into the disk
  • 37. XML Configuration
    • Some third party class
      • Not able to annotate
      • Candidate for XML configuration
    • XML namespace for Java package
      • <WebBeans xmlns=&quot;urn:java:javax.webbeans&quot;
      • xmlns:myapp=&quot;urn:java:com.mydomain.myapp&quot;>
      • ...
      • </WebBeans>
  • 38. Java EE 6.0
      • JSR- 316
      • Easy management of the Enterprise Projects
  • 39. Questions
    • QUESTIONS??
    • Thank you!