By Pablo Silberkasten-Oracle on Sep 17, 2015
Even though WebLogic with Active GridlLink is Oracle's suggested approach to deploy Java applications that use Oracle Real Applications Clusters (RAC), there might be scenarios in which you can't make that choice (e.g.: certification issues, licensing, library dependency, etc.). Application servers and their database connection pool mechanisms might end up being a bottleneck in the architecture of your applications and a critical component to provide performance, scalability and high-availability.
UCP, besides providing connection pooling and all its intrinsic benefits, leverages features specific from RAC.
These features are:
- Runtime Connection Load Balancing (RCLB)
- Fast Connection Failover (FCF)
- Transaction Affinity
- Built-in support for Database Resident Connection Pooling (DRCP) and Application Continuity (AC)
You won't be able to exploit this features by using out of the box JBoss' connection pools.
In this simple example we will show you how to configure UCP to be used in a JBoss deployed application, wrapping UCP around a Singleton Enterprise Java Bean (EJB) and using a Servlet as client to the wrapper. We will also show you how to monitor and administer UCP using JBoss JMX-Console without needing extra configuration, coding or deployment.
In an ideal scenario the application server would provide us the possibility to set a custom implementation of a connection pooling (by implementing an interface, for example), but that is not the case with JBoss. In JBoss you can configure all the necessary information to create a connection (driver, url, user, password, etc) and some configuration for the pool (minimum size, maximum size, etc), but you can't configure the class that is going to provide the implementation for connection pooling. There's a workaround for that in this article: https://blogs.oracle.com/dev2dev/entry/how_to_use_oracle_universal1 , which explains how to set a UCP data-source using Spring). But for both scenarios you're declaring beans, or wrappers, to contain the UCP configuration.
1. Download and start JBoss AS:
You can download it from this site: http://jbossas.jboss.org/downloads/.
For this sample we used “JBoss AS 6.1.0.Final”: http://download.jboss.org/jbossas/6.1/jboss-as-distribution-6.1.0.Final.zip.
After unzipping the file you should set your JAVA_HOME env variable to an existing JDK directory (jdk7, it won't work with jdk8).
To start the app server you go to the unzipped directory /bin and run standalone.sh or standalone.bat, depending on your OS (you can skip this step if you install JBoss Developer Studio.
You can check successful start-up by opening a browser to http://localhost:8080/
2. Download and install JBoss Developer Studio:
This is also an optional step, you can download JBoss Developer Studio from http://www.jboss.org/products/devstudio/download/ after unzipping you start it by running jbdevstudio executable. This is an extension of Eclipse with JBoss specific plugins installed.
3. Configure JBoss AS in JBoss Developer Studio:
In “servers” view choose “new” / “server”, select “JBoss Community, JBoss AS 6.x”, select “Home Directory” to the previously downloaded JBoss AS and leave default values.
After this step you can start/stop application server from JBoss Developer Studio and deploy / un-deploy applications by selecting “Add and Remove..” in Server's contextual menu.
4. Add ucp.jar and ojdbc.jar both to Jboss's runtime:
Add both jars in (JBOSS_HOME/common/lib) and in project's build path (project / properties / Java Build Path / libraries). You could also deploy this jars as specifics for the app, off course.
5. Create the Singleton Wrapper for UCP as this:
6. Create EJB configuration file (WEB-INF/ejb-jar.xml) with this values:
7. Create the client as this sample servlet:
8. From Servers's view execute “Publish” and “Start” (or just execute from project's context menu “run in server”).
9. Administer EJB from JMX-Console:
Login to http://localhost:8080/jmx-console/
Look for UCP's MBEANs:
Invoke getConnectionPoolName (you will get what was setted on the EJB, “ucp_demo.UcpDemoSingletonWrapper").
Go through oracle.ucp.admin.UniversalConnectionPoolMBean and look for availableConnectionsCount.
10. Invoke servlet:
Typing in a browser http://localhost:8080/ucp_jboss_demo_web_project/UcpDemoServletClient
Check that after several executions the amount of available connections remains constant.
Do the same but not closing the connections in the wrapper (remove from the try with resources block, avoiding connection.close())
Or just execute Connection connection = ucpWrapper.getConnection(); without closing the connection.
You will check that available connections decreases until exception is thrown.
Use JMX-console to administer life-cycle of UCP (start / stop / purge connection pool, etc.).
A full-fledged test would include modifications in the RAC (shutting down/up nodes, checking load balance between them, validating transaction affinity, etc.), in these scenarios UCP would show all its capacities and features (as described at the beginning of this article).