/hazelcast-documentation/src/main/docbook/manual/content/j2ee/JEEIntegration.xml
https://bitbucket.org/gabral6_gmailcom/hazelcast · XML · 264 lines · 242 code · 7 blank · 15 comment · 0 complexity · 20b37856568fff2fa4b7b8f6a17ccc4d MD5 · raw file
- <?xml version='1.0' encoding='UTF-8'?>
- <!--
- ~ Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
- <sect1 xml:id="JEEIntegration" version='5.0' xmlns='http://docbook.org/ns/docbook'
- xmlns:xi="http://www.w3.org/2001/XInclude"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
- http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
- <title>J2EE Integration</title>
- <para>Hazelcast can be integrated into J2EE containers via Hazelcast Resource Adapter (
- hazelcast-ra.rar ). After proper configuration, Hazelcast can participate in standard J2EE
- transactions.
- <programlisting language="java"><![CDATA[<%@page import="javax.resource.ResourceException" %>
- <%@page import="javax.transaction.*" %>
- <%@page import="javax.naming.*" %>
- <%@page import="javax.resource.cci.*" %>
- <%@page import="java.util.*" %>
- <%@page import="com.hazelcast.core.Hazelcast" %>
- <%
- UserTransaction txn = null;
- Connection conn = null;
- Config cfg = new Config();
- HazelcastInstance hz = Hazelcast.newHazelcastInstance(cfg);
- Queue queue = hz.getQueue ("default");
- Map map = hz.getMap ("default");
- Set set = hz.getSet ("default");
- List list = hz.getList ("default");
- try {
- Context context = new InitialContext();
- txn = (UserTransaction) context.lookup("java:comp/UserTransaction");
- txn.begin();
-
- ConnectionFactory cf = (ConnectionFactory) context.lookup ("java:comp/env/HazelcastCF");
- conn = cf.getConnection();
-
- queue.offer("newitem");
- map.put ("1", "value1");
- set.add ("item1");
- list.add ("listitem1");
-
- txn.commit();
- } catch (Throwable e) {
- if (txn != null) {
- try {
- txn.rollback();
- } catch (Exception ix) {ix.printStackTrace();};
- }
- e.printStackTrace();
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (Exception ignored) {};
- }
- }
- %>
- ]]></programlisting>
- </para>
- <sect2 xml:id="JEEIntegrationConfig" version='5.0' xmlns='http://docbook.org/ns/docbook'
- xmlns:xlink='http://www.w3.org/1999/xlink'
- xmlns:xi='http://www.w3.org/2001/XInclude'
- xmlns:ns5='http://www.w3.org/2000/svg'
- xmlns:ns4='http://www.w3.org/1998/Math/MathML'
- xmlns:ns3='http://www.w3.org/1999/xhtml'
- xmlns:db='http://docbook.org/ns/docbook'>
- <title>Resource Adapter Configuration</title>
- <para>Deploying and configuring Hazelcast resource adapter is no different than any other
- resource adapter since it is a standard
- <literal>JCA</literal>
- resource adapter but
- resource adapter installation and configuration is container specific, so please consult
- your J2EE vendor documentation for details. Most common steps are:
- <orderedlist>
- <listitem>
- <para>Add the
- <literal>hazelcast.jar</literal>
- to container's classpath. Usually
- there is a lib directory that is loaded automatically by the container on
- startup.
- </para>
- </listitem>
- <listitem>
- <para>Deploy<literal>hazelcast-ra.rar</literal>. Usually there is a some kind of
- deploy directory. Name of the directory varies by container.
- </para>
- </listitem>
- <listitem>
- <para>Make container specific configurations when/after
- deploying<literal>hazelcast-ra.rar</literal>. Besides container specific
- configurations,
- <literal>JNDI</literal>
- name for Hazelcast resource is
- set.
- </para>
- </listitem>
- <listitem>
- <para>Configure your application to use the Hazelcast resource. Updating
- <literal>web.xml</literal>
- and/or
- <literal>ejb-jar.xml</literal>
- to let
- container know that your application will use the Hazelcast resource and
- define the resource reference.
- </para>
- </listitem>
- <listitem>
- <para>Make container specific application configuration to specify
- <literal>JNDI</literal>
- name used for the resource in the application.
- </para>
- </listitem>
- </orderedlist>
- </para>
- </sect2>
- <sect2 xml:id="JEEIntegrationGlassfishSample" version='5.0' xmlns='http://docbook.org/ns/docbook'
- >
- <title>Sample Glassfish v3 Web Application Configuration</title>
- <para>
- <orderedlist>
- <listitem>
- <para>Place the
- <literal>hazelcast-<version>.jar</literal>
- into
- <literal>GLASSFISH_HOME/glassfish/domains/domain1/lib/ext/</literal>
- directory.
- </para>
- </listitem>
- <listitem>
- <para>Place the
- <literal>hazelcast-ra-<version>.rar</literal>
- into
- <literal>GLASSFISH_HOME/glassfish/domains/domain1/autodeploy/</literal>
- directory
- </para>
- </listitem>
- <listitem>
- <para>Add the following lines to the
- <literal>web.xml</literal>
- file.
- <programlisting language="xml"><![CDATA[<resource-ref>
- <res-ref-name>HazelcastCF</res-ref-name>
- <res-type>com.hazelcast.jca.ConnectionFactoryImpl</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- ]]></programlisting>
- </para>
- </listitem>
- </orderedlist>
- Notice that we didn't have to put
- <literal>sun-ra.xml</literal>
- into the
- rar file because it comes with the
- <literal>hazelcast-ra-<version>.rar</literal>
- file already.
- </para>
- <para>If Hazelcast resource is used from EJBs, you should configure
- <literal>ejb-jar.xml</literal>
- for resource reference and
- <literal>JNDI</literal>
- definitions, just like we did for<literal>web.xml</literal>.
- </para>
- </sect2>
- <sect2 xml:id="JEEIntegrationJBossSample" version='5.0' xmlns='http://docbook.org/ns/docbook'
- >
- <title>Sample JBoss Web Application Configuration</title>
- <para>
- <itemizedlist>
- <listitem>
- <para>Place the
- <literal>hazelcast-<version>.jar</literal>
- into
- <literal>JBOSS_HOME/server/deploy/default/lib</literal>
- directory.
- </para>
- </listitem>
- <listitem>
- <para>Place the
- <literal>hazelcast-ra-<version>.rar</literal>
- into
- <literal>JBOSS_HOME/server/deploy/default/deploy</literal>
- directory
- </para>
- </listitem>
- <listitem>
- <para>Create a
- <literal>hazelcast-ds.xml</literal>
- at
- <literal>JBOSS_HOME/server/deploy/default/deploy</literal>
- directory
- containing the following content. Make sure to set the
- <literal>rar-name</literal>
- element
- to<literal>hazelcast-ra-<version>.rar</literal>.
- <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE connection-factories
- PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
- "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
- <connection-factories>
- <tx-connection-factory>
- <local-transaction/>
- <track-connection-by-tx>true</track-connection-by-tx>
- <jndi-name>HazelcastCF</jndi-name>
- <rar-name>hazelcast-ra-<version>.rar</rar-name>
- <connection-definition>
- javax.resource.cci.ConnectionFactory
- </connection-definition>
- </tx-connection-factory>
- </connection-factories>
- ]]></programlisting>
- </para>
- </listitem>
- <listitem>
- <para>Add the following lines to the
- <literal>web.xml</literal>
- file.
- <programlisting language="xml"><![CDATA[<resource-ref>
- <res-ref-name>HazelcastCF</res-ref-name>
- <res-type>com.hazelcast.jca.ConnectionFactoryImpl</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- ]]></programlisting>
- </para>
- </listitem>
- <listitem>
- <para>Add the following lines to the
- <literal>jboss-web.xml</literal>
- file.
- <programlisting language="xml"><![CDATA[<resource-ref>
- <res-ref-name>HazelcastCF</res-ref-name>
- <jndi-name>java:HazelcastCF</jndi-name>
- </resource-ref>
- ]]></programlisting>
- </para>
- </listitem>
- </itemizedlist>
- If Hazelcast resource is used from EJBs, you should configure
- <literal>ejb-jar.xml</literal>
- and
- <literal>jboss.xml</literal>
- for resource
- reference and
- <literal>JNDI</literal>
- definitions.
- </para>
- </sect2>
- </sect1>