openwebbeans/web beans
TRANSCRIPT
Apache Incubator OpenWebBeans
Gurkan Erdogdu
Conny Lundgren
Matthias Wessendorf
Kevan Miller
Apache Incubator
Free and Open Source
What is OpenWebBeans
Implementation of the JSR-299 WebBeans
Incubated in the Apache Software Foundation
http://incubator.apache.org/openwebbeans
http://incubator.apache.org
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
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
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
Web Bean Definition
API Types
Binding types
Scopes
Deployment types
Names
StereoTypes
Specialization
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)
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
Binding Types
Seperates implementations from each other
Annotation driven
Annotated with @BindingType
Example, 2 binding types
@BindingType
public @interface CreditCardPayment
@BindingType
public @interface DebitCardPayment
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
}
Scopes
RequestScoped
SessionScoped
ApplicationScoped
ConversationScoped
DependentScoped
Or your defined scope, annotated @ScopeType
@ScopeType
Public @interface MyScope{}
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?
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
StereoTypes
Like class inheritance
No repeat yourself
Just inherit model
Inherit annotations
Annotated with @StereoType
@StereoType
@RequestScoped
@Production
@Named
public @interface MyStereoType
StereoType
Easily create web bean annotations
EXAMPLE : MyNewBean inherits from stereotypes.
@MyStereoType
public class MyNewBean{}
Inherit :ScopeType, DeploymentType and Default Named indicator from MyStereoType
Specialization
Related with web beans resolution semantic
Clear in the next slides
Normally injection service resolves web beans with
API type
Binding Type
Precedence
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{}
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
Resolutions
Resolution By Name
Name
Precedence of the DeploymentType
Resolution By Type
API Type
BindingType
Precedence of the DeploymentType
Injected Fields
Inject fields of the web beans
Public class MyBean
{
@Logger Log logger; Inject for me after creation
}
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;
}
Constructor Initializer
Inject into web beans constructor
@Production
@RequestScoped
public class PaymentProcessor
{
Inject into the my constructor while creating
public PaymentProcessor(@CreditCard Ipayment payment)
{
}
}
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;}
EL Resolution
EL Resolution
Welcome Page, gets user name and password from the @CurrentUser
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
Interceptors
Interceptor with @InterceptorBindingType
@InterceptorBindingType
Public @interface Transactional{} Interceptor
@Transactional Class level
Public class Payment{
@Transactional Method level
public void payment(){}
}
Interceptors
Business Level Interceptors
Business method invocation
Life Cycle Interceptors
Web Bean life cycle
@PostConstruct
@PreDestroy
@PrePassivate
@PreActivate
Interceptor Example
@Transactional
public class MyTransactionInterceptor
{
@AroundInvoke called just before my business method
public void invoke(InvocationContext context)
{
}
}
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
{
}
}
Events
Loosely Coupled Interaction
Events
Event type
Event binding type
Observers
Observable annotation
Transactional observers
Observers
public class PaymentObserver implements Observer
{
public void notify(PaymentDoneEvent event)
{
}
}
Events
@Observes annotation, observes given event type
public class PaymentDoneBean
{
public void afterPayment(@Observes PaymentDoneEvent event)
{
}
}
Events
Fire events via Manager API
public void pay()
{
manager.fireEvent(new PaymentDoneEvent(user))
}
Event
@Observable annotation
Register observers via event
Custom web bean with Event API
Fire events via event
public class LoginBean
{
private @Observable Event event; Runtime provided Event bean
public void afterLoggedIn()
{
LoggedInEvent loggedIn = new LoggedInEvent("Gurkan");
event.fire(loggedIn, anns); Fire event via Event
}
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
XML Configuration
Some third party class
Not able to annotate
Candidate for XML configuration
XML namespace for Java package
...
Java EE 6.0
JSR- 316
Easy management of the Enterprise Projects
Questions
QUESTIONS??
Thank you!
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamalla
Toinen jsennystaso
Kolmas jsennystaso
Neljs jsennystaso
Viides jsennystaso
Kuudes jsennystaso
Seitsems jsennystaso
Kahdeksas jsennystaso
Yhdekss jsennystaso