This slides give you an overview of the technical challgens that Java EE application servers have faced to reinvent themselves. From monolithic to jigsaw puzzles, app servers are not the burden developpers use to use anymore
2. Antonio Goncalves
●
Freelance software architect
●
Author (Java EE 5 and Java EE 6)
●
JCP expert member (Java EE 6, Java EE 7)
●
Co-leader of the Paris JUG
●
Les Cast Codeurs podcast
● Java Champion
antonio goncalves 2
3. Co-creator of Devoxx France
●
Little brother of Devoxx (Belgium)
●
3 days conference (18th to 20th April 2012)
●
140 talks (75% in French)
●
In Paris
●
Cheap (450€)
● www.devoxx.fr
antonio goncalves 3
4. Why am I talking here today
●
Former BEA employee
●
Started working with J2EE in 1998
●
With Weblogic 3.x
●
Java EE 6 / 7 Expert Member
●
Has used/played with most app servers
● Blogs about app servers
antonio goncalves 4
8. Server and services
●
Server ●
Services
● « Program running to ● Security
serve the requests of ● Transaction
other programs »
● Load balancing
● Application server
● Distribution
● Database server
● Management
● Communication server
● Performance
● File server
● ...
● Fax server
● ...
antonio goncalves 8
9. We use application servers not to
reinvent the wheel
(i.e the technical services)
10. « Application » server
●
Market dominated by
● Java
● .Net
●
Proprietary
●
Other programming models
antonio goncalves 10
11. Let's focus on Java
Java EE 6
Web Profile 6
Servlet
antonio goncalves 11
12. Web profile
●
Java EE 6
● 28 specifications
● Web profile
● 12 specifications
●
Other profiles will come
●
Brings modularity
antonio goncalves 12
13. Modularity
●
OSGi / Modules / What ever
● Java modules in Java SE 8 / Java EE 8 ?
● App servers become jigsaw puzzles
●
Only startup needed modules
● Faster
●
Lighter
●
Time is changing
antonio goncalves 13
14. History
JPE J2EE 1.2 J2EE 1.3 J2EE 1.4 Java EE 5 Java EE 6 Java EE 7
1995 May 1998 Dec 1999 Sept 2001 Nov 2003 May 2006 Dec 2009 Mar 2013
antonio goncalves 14
15. Startup time of JBoss
Using a Windows XP virtual machine (Virtual Box)
antonio goncalves 15
16. Startup time of other servers
Using a Windows XP virtual machine (Virtual Box)
antonio goncalves 16
17. Industrial strengh
●
App servers implement the same specs
●
They all do the same basic stuff...
●
… so they must find a differentiator
● Startup time
● Memory footprint
● Administration
● Add ons
● Clustering
antonio goncalves 17
18. Money, get away
●
Why is the app server battle so tough ?
●
*Because there is money involved :
● 2010 : app server market = $3.2 billion
● 9% growth per year
● 2015 : reaching $5 billion
(*)Gartner 2010
antonio goncalves 18
22. Future<App Server>
●
« *In the next 5 years most app servers will be
extended for cloud computing purposes »
●
Elastic resource allocation
●
Dynamic clustering
●
Horizontal scaling
●
Multitenancy (Java EE 7)
(*)Gartner 2011
antonio goncalves 22
25. Webs.... fear
●
Ops love it
●
Devs hate it
● … and IBM wants us to love it now
●
OGSi
● Simple, Lightweight, Fast
●
Liberty Profile (not the web profile)
● No EJB Lite, no CDI
●
Free for development
antonio goncalves 25
34. Resin
●
Created in 1999 (web server)
●
First web profile certified in 2011
●
4.7 millions web sites hosted on Resin
● Mostly in finance
● “Visionary” on Gartner Magic Quadrant
●
Resin open source (free)
●
Resin professional
● Commercial license
antonio goncalves 34
35. Inside Resin
●
Based on CanDI
●
Quercus (PHP)
●
Watchdog
●
Cloud ready (dynamic clustering)
●
Remote EJBs use Hessian (instead of RMI)
● Multitenancy
antonio goncalves 35
41. Developing / Debugging
●
Good old “develop/package/deploy/start”
● Event if app servers start quickly
● Takes too much time
●
JRebel...
● … is your friend
● Hot deployment
● Reload classes
● Updates web resources
● Saves you time
antonio goncalves 41
43. Testing
●
Unit Tests
● Mock container services
● Integration Tests
● WYTIWYR (What You Test Is What You Run)
● Use container services
● EJBContainer API (in Java EE 6)
● Arquillian
antonio goncalves 43
44. Unit test with Mockito
@RunWith(MockitoJUnitRunner.class)
public class ItemEJBTest {
@Mock
private EntityManager mockedEntityManager;
@Mock
private TypedQuery mockedQuery;
private ItemEJB itemEJB;
@Before
public void init() throws Exception {
itemEJB = new ItemEJB();
itemEJB.setEntityManager(mockedEntityManager);
}
}
antonio goncalves 44
45. Integration test with EJBContainer
public class ItemEJBIT {
private static EJBContainer ec;
private static Context ctx;
@BeforeClass
public static void init() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put(EJBContainer.MODULES, new
File("target/classes"));
ec = EJBContainer.createEJBContainer(properties);
ctx = ec.getContext();
}
}
antonio goncalves 45
46. Integration test with Arquillian
@RunWith(Arquillian.class)
public class ItemEJBIT {
@Inject
private ItemEJB itemEJB;
@Deployment
public static JavaArchive createTestArchive() {
JavaArchive archive = ShrinkWrap
.create(JavaArchive.class)
.addPackage(Book.class.getPackage())
.addAsManifestResource(INSTANCE, "beans.xml")
.addAsResource("META-INF/persistence.xml"..);
return archive;
}
antonio goncalves 46
47. Integration Testing
●
In memory database
●
In memory container
● EJBContainer API
●
Embedded container with Arquillian
● Remote container with Arquillian
●
IT richer but slower that UT
antonio goncalves 47
49. Portable ?
●
Java EE is a standard
●
Yaps Petstore only uses standards
●
Standards should run everywhere
●
I want my Yaps Petstore to run everywhere
● But it's not that easy
antonio goncalves 49
50. JPA
●
Lazy Loading bidirectional entities
● Spec has undefined behaviour
● Works well with EclipseLink
● Doesn't with Hibernate (use Fetch Join)
● Fetch Joins don't work with EclipseLink
antonio goncalves 50
51. Lazy loading
List<Product> products = em.createQuery
("SELECT p FROM Product p WHERE p.category.name =:n")
.getResultList();
for (Product product : products) {
Category category = product.getCategory();
}
antonio goncalves 51
52. Lazy loading
List<Product> products = em.createQuery
("SELECT p FROM Product p WHERE p.category.name =:n")
.getResultList();
for (Product product : products) {
Category category = product.getCategory();
if (category != null)
category.getName(); Can return a proxy
}
Makes sure you get the entity
antonio goncalves 52
53. Datasource
●
Needs to be defined
● In the container through admin
● Via web.xml, application.xml, ejb-jar.xml
● Or via annotation
●
Points to a database
●
In memory DB are good for development
● Each app server uses it's own in memory DB
● Derby
● Not in JBoss (add derby.jar to .war)
antonio goncalves 53
55. Default Datasource in Java EE 7
@DataSourceDefinition(
className ="org.apache.derby.jdbc.EmbeddedDataSource
name = "java:global/jdbc/applicationPetstoreDS",
...)
<persistence>
<persistence-unit name="applicationPetstorePU"...>
<jta-data-source>
java:global/jdbc/applicationPetstoreDS
...
</persistence>
@Inject
private EntityManager em;
antonio goncalves 55
56. Other resources in Java EE 7
@JMSConnectionFactoryDefinition(
name="java:app/MyJMSFactory",
resourceType="javax.jms.QueueConnectionFactory",
clientId="foo",resourceAdapter="jmsra",
InitialPoolSize=5, maxPoolSize=15
)
@JMSDestinationDefinition(
name="java:app/orderQueue",
resourceType="javax.jms.Queue",
resourceAdapter="jmsra",
destinationName="orderQueue"
)
antonio goncalves 56
57. Properties not all standard
<persistence-unit name="applicationPetstorePU"...>
...
<properties>
<!-- Standard Properties -->
<property name="javax.persistence.xxx" value="xxx"/>
<!-- Properties for EclipseLink -->
<property name="eclipselink.ddl-generation" value="create-tables
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<!-- Properties for OpenJPA -->
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
antonio goncalves 57
58. Persistence properties in Java EE 7
<persistence-unit name="applicationPetstorePU"...>
...
<properties>
<!-- Standard Properties -->
<property name="javax.persistence.xxx" value="xxx"/>
<property name="javax.persistence.ddl" value="drop-and-create"/>
<!-- Properties for EclipseLink -->
<property name="eclipselink.ddl-generation" value="create-tables
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<!-- Properties for OpenJPA -->
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
Not sure of the syntax Not sure of the syntax
antonio goncalves 58
59. Initialize database
●
Having some data in the DB
●
Running sql script
●
derbytools.jar has an API
●
Hibernate : import.sql (but not with other ORMs)
antonio goncalves 59
60. Use a Singleton with @Startup
@Singleton
@Startup
public class DBPopulator {
@Inject
private CatalogService catalogService;
@PostConstruct
private void populateDB() {
catalogService.createCategory(new Category("Fish"))
}
}
antonio goncalves 60
62. Portable ?
●
TCK doesn't cover all the cases
● e.x. all the possible JPQL query syntax
● Implementations fill (or not) black holes
●
100% portability is still a myth...
● … but it's getting better
●
… and Java EE 7 will improve some bits
●
Any way, you don't change app server every day
●
… except for the Yaps Petstore ;o)
antonio goncalves 62
68. Creative Commons
●
Attribution — You must attribute the work in
the manner specified by the author or licensor
(but not in any way that suggests that they
endorse you or your use of the work).
● Noncommercial — You may not use this work for
commercial purposes.
● Share Alike — If you alter, transform, or build
upon this work, you may distribute the resulting
work only under the same or similar license to
this one.
antonio goncalves 68