7. Java EE
”The industri standard for enterprise computing. JEE is
used for mission-critical, large-scale, multi-tiered,
scalable, reliable, and secure applications”
8. Java EE
A set of API
- JTA, JPA, JSF, EJB, JMS, JCA, Servlet, CDI, JAX-WS, JAX-RS…
Application Servers
- Oracle AS, IBM Websphere, Apache Geronimo, JBoss, Glassfish, JOnAS,
TomEE, Resin…
Used within
- Finance
- Telecom
- Manufacturing
- …
11. ”EJB/J2EE IS HEAVYWEIGHT”
EJB != heavyweight
- acctually its considered ultra-lean
- please tell if anyone know any other tech!
One jar file (java-ee-6.jar, 967 kB)
One single annotation
- @Stateless
Glassfish (55/200MB)
- restart in ~3 seconds
- hot deployment
- full OSGi support
12. Why Java EE
Hyper productive
- time-to-market
Maximize focus on Business functionality
- Inversion of control (DI)
- Decorators
- Aspects
- Schedulers
- Events
- Asyncronous calls
- …
Helps you with a lot of non-functional requirements
13. Why Java EE
Thread-safe
- every thread gets it own bean instance
Transaction management
- transaction are automatically started, commited or rollbacked
Pooling of Session beans
- prevent DDOS attacks
- scale up/down
Distributed components
- runs in a multi-tier architecture
- failover, scalability
14. Why Java EE
Deployment
- very few (if any) xzy.xml deployment desc.
- runs on several app servers and/or clouds
Elastic
15. Why Java EE
Ultra-lean
- what more can be removed?
16. EJB Component
public interface PaymentService {
public ProductReceipt pay(int productId);
}
@Stateless
public class PaymentEJB implements PaymentService {
public ProductReceipt pay(int productId){
//implementation goes here
}
}
EJB-annotation (convention over configuration)
Plain interface (not
required)
17. TDD and Java EE
Unit test
- POJO
Integration test
- embedded container
- arquillian
- pax exam
18. TDD and Java EE
EJBContainer container = EJBContainer.createEJBContainer();
Context ctx = container.getContext();
PaymentService service = (PaymentService) ctx
.lookup("java:global/classes/PaymentEJB");
Assert.assertNotNull(service);
19. Areas Not Covered by Java EE
Java lacks (real) modularity
- known problem since day 1
- many app servers builds on OSGi
- may change when Project Jigsaw is release (2013)
Service tracking
Criteria-based service selection
”Jar-hell”
- NoSuchMethodException
- Classpath / Dependencies
20. Areas Not Covered by Java EE
Well defined life-cycle of components
Multiple instances of a service/component
Hot-swapping* of components
* debug mode doesn’t count
21. Hello OSGi!
“OSGi technology provides a service-oriented,
component-based environment for developers and
offers standardized ways to manage the software
lifecycle.” - Wikipedia
24. Why OSGi
But how about OO in Java?
- OO is all about high cohesion and low coupling, right?
Java has a limited modularization
- no transitive dependencies
- public (keyword) is ’too public’
- error prone class path
- low-level modularization (packages)
25. OSGi Layers
OSGi Layered Architecture
Module
- packaging and sharing
of code
Life Cycle
- module management
Service
- interaction between
modules
26. OSGi Module Layer
Bundle
–a unit of modularity in OSGi
Package as a JAR (classes + MANIFEST.MF with OSGi metadata)
Versionable
Clear dependency declaration
Clear dependency resolution rules
29. OSGi Service Layer
Services registry
- register
- unregister
Service is a POJI
- focus on the contract/interface
- reduce coupling
Service discovery
- LDAP filter based queries
30. Best of Both Worlds
How about combining JEE & OSGi?
- productivity
- reusable bundles with visible dependencies
- version control of components
- automatic transaction handling
- ..
32. Hybrid Applications
“a hybrid application bundle is an OSGi bundle as well
as a Java EE module. At
runtime, it has both an OSGi bundle context and a Java
EE context.”
33. Hybrid Applications
Allows you to develop managed, transactional OSGi services with little
knowledge of OSGi
Makes your EJB:s available as OSGi services with little effort
- bundles can use Java EE services like JTA, JPA, etc
Supports Stateless and Singleton EJBs
36. Hybrid Applications
EJB artifacts + Manifest.MF = ’Declarative’ Service
- Enterprise Application Bundle (EAB)
- Web Application Bundle (WAB)
ExportEJB: List of EJBs to be exported as OSGi services.
- Values: NONE, ALL or fully qualified name
37. Hybrid Applications
In VM SOA
- service-oriented design
- domain-driven design
Different support for hybrid apps
- JBoss
- Glassfish
- IBM Websphere
- Geronimo
This makes hybrid apps less portable!
- RFP 152 ”EJB Integration”
- RFP 146 ”OSGi/CDI Integration”
38. Glassfish + OSGi
OSGi R4, version 4.2 compliant
- Uses Apache Felix as OSGi runtime
Jave EE / OSGi services in Glassfish
- JTA
- JPA
- JMS
- HTTP Service
- Event Admin
- Config Admin
- …
39. Glassfish + OSGi
Type safe injection with CDI Extension
ServiceTracker tracker =
new ServiceTracker(context, Hello.class.getName(), null);
tracker.open();
Hello hello = (Hello) tracker.getService();
System.out.println(hello.sayHello("Duke"));
@Inject @OSGiService(dynamic=true)
Hello hello;
System.out.println(hello.sayHello("Duke"));
With CDI annotation:
40. PROVE IT ! (Demo time)
Asyncronous invocations
Events
Decorators
Service update (hot deployment)
REST service
41. Demo Overview
HybridCommon
(standard OSGi bundle containing
domain objects)
HybridClient
(WAB exposes a service via Jax-RS)
HybridBackend
(EJB as OSGi service, EAB)
<uses>
<uses>
OSGi Service
Registry
<publish>
<discover>
42. CONS JEE + OSGi
”With great power comes great complexity”
- combining OSGi + JEE
- two different component models
- developers need to know both models
- not all app server have (full) hybrid support
- different containers with different characteristics
Technology overlap of Java EE and OSGi
- events, security, monitoring…
Declarative Services, iPojo, Blueprint, ServiceTracker…
44. FUTURE<JavaEE&OSGi>
Project Jigsaw
- monolitic JVM
- will address both compile & runtime (Maven + OSGi)
- no service register nor life cycle handling
- (probably) not until Java 9
46. FUTURE<JavaEE&OSGi>
OSGi
- CDI integration
- EJB incorporation
- more app servers will support hybrid
apps
Jigsaw and OSGi will definitely co-exist
- Project Penrose
47. SUMMARY
Features in Java EE and OSGi
- productivity and modularity
How to combine them
- WAB/EAB
Demonstrated a hybrid application
- using Glassfish + Apache Felix