<?xml version="1.0" encoding="UTF-8"?>
<chapter id="deployers">
  <title>Deployers</title>

  <para>The deployer chains for the project is located in the <code>deployers</code> module.</para>

  <section id="rardeployer">
    <title>RAR Deployer</title>

    <para>The responsibility of the RAR deployer is to deploy a resource adapter archive (.RAR) file.</para>

    <section id="rardeployer_fungal">
      <title>Fungal</title>

      <para>The Fungal kernel features a simple deployment framework, so only three classes are needed for the
        deployer chain.</para>

      <para>The classes are located in the</para>

      <programlisting>
deployers/src/main/java/org/jboss/jca/deployers/fungal
      </programlisting>

      <para>directory.</para>

      <!-- TODO: a picture showing the deployer chain classes -->

      <section id="rardeployer_fungal_radeployer">
        <title>RADeployer</title>

        <para>This class represent a resource adapter deployer and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployer
com.github.fungal.spi.deployers.MultiStageDeployer
com.github.fungal.spi.deployers.DeployerOrder
        </programlisting>

        <para>interfaces.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Create a classloader for the deployment
          </listitem>
          <listitem>
            Retrieve metadata and annotations such that they can be merged
          </listitem>
          <listitem>
            Perform archive validation using the JCA validator
          </listitem>
          <listitem>
            Perform bean validation
          </listitem>
          <listitem>
            Register the metadata in the metadata repository
          </listitem>
          <listitem>
            Register the resource adapter in the metadata repository
          </listitem>
          <listitem>
            Identify and activate the resource adapter objects - if JNDI information is available
          </listitem>
          <listitem>
            Bind connection factories and admin objects into JNDI - if JNDI information is available
          </listitem>
        </itemizedlist>

        <para>If the resource adapter isn't activated in this step based on an <code>ironjacamar.xml</code>
          file, the deployment will advance to the next step in the deployer chain.</para>
      
      </section>

      <section id="rardeployer_fungal_radeployment">
        <title>RADeployment</title>
      
        <para>This class represent a resource adapter deployment and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployment
        </programlisting>

        <para>interface.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Unregister the resource adapter from the metadata repository
          </listitem>
          <listitem>
            Unregister the JNDI bindings in the metadata repository - if the deployment was activated
          </listitem>
          <listitem>
            Unbind connection factories and admin objects in JNDI - if the deployment was activated
          </listitem>
          <listitem>
            Close the classloader
          </listitem>
          <listitem>
            Clean up any temporary files
          </listitem>
        </itemizedlist>

      </section>

      <section id="rardeployer_fungal_raxmldeployer">
        <title>RaXmlDeployer</title>

        <para>This class represent a resource adapter deployer and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployer
com.github.fungal.spi.deployers.MultiStageDeployer
com.github.fungal.spi.deployers.DeployerOrder
com.github.fungal.spi.deployers.DeployerPhases
        </programlisting>

        <para>interface.</para>

        <para>The class deploys resource adapter archives based on a <code>-ra.xml</code> which
          provides the necessary deployment information.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Create a classloader for the deployment
          </listitem>
          <listitem>
            Retrieve metadata from the metadata repository
          </listitem>
          <listitem>
            Merge metadata from the deployment descriptor
          </listitem>
          <listitem>
            Perform archive validation using the JCA validator
          </listitem>
          <listitem>
            Perform bean validation
          </listitem>
          <listitem>
            Register the metadata in the metadata repository
          </listitem>
          <listitem>
            Identify and activate the resource adapter objects
          </listitem>
          <listitem>
            Bind connection factories and admin objects into JNDI
          </listitem>
        </itemizedlist>

        <para>Since multiple resource adapter archives can be activated within a single <code>-ra.xml</code>
          file the class uses the <code>DeployerPhases</code> callbacks to unregister these from the
          container. If there is only a single resource adapter activation the deployer acts as part of 
          the normal deployer chain.</para>
      
      </section>

      <section id="rardeployer_fungal_raxmldeployment">
        <title>RaXmlDeployment</title>
      
        <para>This class represent a resource adapter deployment from the <code>RaXmlDeployer</code>
          and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployment
        </programlisting>

        <para>interface.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Unregister the JNDI bindings in the metadata repository
          </listitem>
          <listitem>
            Unbind connection factories and admin objects in JNDI
          </listitem>
          <listitem>
            Close the classloader
          </listitem>
        </itemizedlist>

      </section>

      <section id="rardeployer_fungal_raactivator">
        <title>RAActivator</title>
      
        <para>This class will activate all resource adapters which hasn't been deployed by a previous step.
          The class implements the </para>

        <programlisting>
com.github.fungal.spi.deployers.DeployerPhases
        </programlisting>

        <para>interface. This interface allows the class to hook into the deployer lifecycle of the kernel
          and receive callback notifications.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Find any resource adapters which hasn't been deployed through the metadata repository
          </listitem>
          <listitem>
            Perform a deployment like <code>RADeployer</code>
          </listitem>
          <listitem>
            Register each deployment with the kernel through the main deployer
          </listitem>
        </itemizedlist>

      </section>

      <section id="rardeployer_fungal_raactivator_deployment">
        <title>RAActivatorDeployment</title>
      
        <para>This class represent a resource adapter deployment activated by the <code>RAActivator</code>
          and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployment
        </programlisting>

        <para>interface.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Unregister the JNDI bindings in the metadata repository
          </listitem>
          <listitem>
            Unbind connection factories and admin objects in JNDI
          </listitem>
          <listitem>
            Close the classloader
          </listitem>
        </itemizedlist>

      </section>

    </section>

  </section>

  <section id="dsdeployer">
    <title>DataSource Deployer</title>

    <para>The responsibility of the datasource deployer is to deploy a datasource deployment (-ds.xml) file.</para>

    <section id="dsdeployer_fungal">
      <title>Fungal</title>

      <para>The Fungal datasource deployer chain consists of two classes.</para>

      <para>The classes are located in the</para>

      <programlisting>
deployers/src/main/java/org/jboss/jca/deployers/fungal
      </programlisting>

      <para>directory.</para>

      <section id="dsdeployer_fungal_dsxmldeployer">
        <title>DsXmlDeployer</title>

        <para>This class represent a datasource deployer and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployer
        </programlisting>

        <para>interface.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Locate metadata about JDBC in the metadata repository
          </listitem>
          <listitem>
            Activate each <code>DataSource</code> using <code>jdbc-local.rar</code> as a template
          </listitem>
          <listitem>
            Activate each <code>XaDataSource</code> using <code>jdbc-xa.rar</code> as a template
          </listitem>
        </itemizedlist>
      
      </section>

      <section id="dsdeployer_fungal_dsxmldeployment">
        <title>DsXmlDeployment</title>
      
        <para>This class represent a datasource deployment and implements the</para>

        <programlisting>
com.github.fungal.spi.deployers.Deployment
        </programlisting>

        <para>interface.</para>

        <para>The responsible of the class is to</para>

        <itemizedlist>
          <listitem>
            Unbind the datasource in JNDI
          </listitem>
          <listitem>
            Close the classloader
          </listitem>
        </itemizedlist>

      </section>

    </section>


  </section>
</chapter>
