<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.queue.custom">
    <title>Customizing Zend_Queue</title>

    <sect2 id="zend.queue.custom.adapter">
        <title>Creating your own adapter</title>

        <para>
            <classname>Zend_Queue</classname> will accept any adapter that
            implements
            <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. You can
            create your own adapter by extending one of the existing adapters,
            or the abstract class
            <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. I
            suggest reviewing <classname>Zend_Queue_Adapter_Array</classname> as
            this adapter is the easiest to conceptualize.
        </para>

        <programlisting language="php"><![CDATA[
class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
{
    /**
     * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
     *
     * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
     * this is more likely to produce the wanted rows than the existing code.
     *
     * However, not all databases have SELECT ... FOR UPDATE as a feature.
     *
     * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
     *
     * This code still serves as a good example.
     */
}

$options = array(
    'name'          => 'queue1',
    'driverOptions' => array(
        'host'      => '127.0.0.1',
        'port'      => '3306',
        'username'  => 'queue',
        'password'  => 'queue',
        'dbname'    => 'queue',
        'type'      => 'pdo_mysql'
    )
);

$adapter = new Custom_DbForUpdate($options);
$queue = new Zend_Queue($adapter, $options);
]]></programlisting>

        <para>
            You can also change the adapter on the fly as well.
        </para>

        <programlisting language="php"><![CDATA[
$adapter = new MyCustom_Adapter($options);
$queue   = new Zend_Queue($options);
$queue->setAdapter($adapter);
echo "Adapter: ", get_class($queue->getAdapter()), "\n";
]]></programlisting>

        <para>or</para>

        <programlisting language="php"><![CDATA[
$options = array(
    'name'           => 'queue1',
    'namespace'      => 'Custom',
    'driverOptions'  => array(
        'host'       => '127.0.0.1',
        'port'       => '3306',
        'username'   => 'queue',
        'password'   => 'queue',
        'dbname'     => 'queue',
        'type'       => 'pdo_mysql'
    )
);
$queue = new Zend_Queue('DbForUpdate', $config); // loads Custom_DbForUpdate
]]></programlisting>
    </sect2>

    <sect2 id="zend.queue.custom.message">
        <title>Creating your own message class</title>

        <para>
            <classname>Zend_Queue</classname> will also accept your own message class.
            Our variables start with an underscore. For example:
        </para>

        <programlisting language="php"><![CDATA[
class Zend_Queue_Message
{
    protected $_data = array();
}
]]></programlisting>

        <para>
            You can extend the existing messaging class. See the example code in
            <filename>tests/Zend/Queue/Custom/Message.php</filename>.
        </para>
    </sect2>

    <sect2 id="zend.queue.custom-iterator">
        <title>Creating your own message iterator class</title>

        <para>
            <classname>Zend_Queue</classname> will also accept your own message
            iterator class. The message iterator class is used to return
            messages from
            <methodname>Zend_Queue_Adapter_Abstract::recieve()</methodname>.
            <methodname>Zend_Queue_Abstract::receive()</methodname> should always
            return a container class like
            <classname>Zend_Queue_Message_Iterator</classname>, even if there is
            only one message.
        </para>

        <para>
            See the example filename in
            <filename>tests/Zend/Queue/Custom/Messages.php</filename>.
        </para>
    </sect2>

    <sect2 id="zend.queue.custom.queue">
        <title>Creating your own queue class </title>

        <para>
            <classname>Zend_Queue</classname> can also be overloaded easily.
        </para>

        <para>
            See the example filename in <filename>tests/Zend/Queue/Custom/Queue.php</filename>.
        </para>
    </sect2>
</sect1>
