You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Mark Woon <mo...@SMI.Stanford.EDU> on 2002/02/07 06:12:44 UTC

Question on connection pools

Hello,

I'm new to Avalon and am looking to use the connection pool that'
Excalibur provides, although I'm a little confused as to how I'm
actually supposed to use it.  It looks like I'm just supposed to use
JdbcDataSource, and it'll magically handle all pooling tasks.

What are my options for the connection-class parameter to
pool-controller (I'm guessing this will be JdbcConnectionPool)?  What
does the keep-alive option do?

Since JdbcConnectionPool implements HardResourceLimitingPool, does this
mean that the number of connections will only grow to the max, and will
never shrink?

Can I have multiple datasources available?  There doesn't seem to be a
name option in the configuration for the JdbcDataSource.  How are they
identified?

My apologies if these questions would be answered if I'd just spent more
time familiarizing myself with the Avalon Framework.  Any pointers to
documentation would be greatly appreciated.

Thanks,
-Mark

P/S - Has anyone done any comparisons between Excalibur's connection
pool and PoolMan and Bitmechanic's?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Question on connection pools

Posted by Mark Woon <mo...@SMI.Stanford.EDU>.
So the hints become valid tags...

Genius!

-Mark

Leif Mortenson wrote:

> Mark Woon wrote:
>
> >Leif Mortenson wrote:
> >
> >>Let me know if you still have questions.
> >>
> >
> >More questions:
> >
> >What are hints used for?  I see them declared in roles.xml for the
> >DataSourceComponentSelector but don't see where they're actually being used.
> >
> In the roles.xml file, you see the following:
>     <role
> name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
>           shorthand="datasources"
>
> default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
>
>         <hint shorthand="jdbc"
> class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
>         <hint shorthand="j2ee"
> class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
>     </role>
>
> And in configuration.xml, you have this section:
>     <datasources>
>         <jdbc name="test-db" logger="app.jdbc">
>             <pool-controller min="1" max="1">
>                 <keep-alive disable="true"/>
>             </pool-controller>
>             <auto-commit>true</auto-commit>
>             <driver>org.hsqldb.jdbcDriver</driver>
>             <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
>             <user>sa</user>
>             <password></password>
>         </jdbc>
>     </datasources>
>
> The shorthand in the DataSourceComponentSelector element is how the
> datasources element in the configuration.xml file is able to be
> resolved.  The hints are used to define what the jdbc element is under
> datasources.
>
> You could do something like the following;
>     <role
> name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
>           shorthand="datasources"
>
> default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
>
>         <hint shorthand="jdbc"
> class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
>         <hint shorthand="rl-jdbc"
>
> class="org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource"/>
>         <hint shorthand="j2ee"
> class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
>     </role>
>
>     <datasources>
>         <jdbc name="test-db" logger="app.jdbc">
>             <pool-controller min="1" max="1">
>                 <keep-alive disable="true"/>
>             </pool-controller>
>             <auto-commit>true</auto-commit>
>             <driver>org.hsqldb.jdbcDriver</driver>
>             <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
>             <user>sa</user>
>             <password></password>
>         </jdbc>
>
>         <rl-jdbc name="test-rl-db" logger="app.jdbc">
>             <pool-controller min="1" max="1">
>                 <keep-alive disable="true"/>
>             </pool-controller>
>             <auto-commit>true</auto-commit>
>             <driver>org.hsqldb.jdbcDriver</driver>
>             <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
>             <user>sa</user>
>             <password></password>
>         </rl-jdbc>
>     </datasources>
>
> to Get 2 different datasources.  One of each implementation type.
>
> You could then try each one out by changing the dbpool name from:
>     <hello-db logger="app">
>         <dbpool>test-db</dbpool>
>     </hello-db>
> to:
>     <hello-db logger="app">
>         <dbpool>test-rl-db</dbpool>
>     </hello-db>
>
> Make sense?  It really quite powerful once you get used to it.  You can
> use Component Selectors for all kinds of components, not just data sources.
>
> Cheers,
> Leif
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
~~Mark Woon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're not part of the solution, you're part of the precipitate.



Re: Question on connection pools

Posted by Leif Mortenson <le...@silveregg.co.jp>.

Mark Woon wrote:

>Leif Mortenson wrote:
>
>>Let me know if you still have questions.
>>
>
>More questions:
>
>What are hints used for?  I see them declared in roles.xml for the
>DataSourceComponentSelector but don't see where they're actually being used.
>
In the roles.xml file, you see the following:
    <role 
name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
          shorthand="datasources"
          
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
       
        <hint shorthand="jdbc" 
class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
        <hint shorthand="j2ee" 
class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
    </role>

And in configuration.xml, you have this section:
    <datasources>
        <jdbc name="test-db" logger="app.jdbc">
            <pool-controller min="1" max="1">
                <keep-alive disable="true"/>
            </pool-controller>
            <auto-commit>true</auto-commit>
            <driver>org.hsqldb.jdbcDriver</driver>
            <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
            <user>sa</user>
            <password></password>
        </jdbc>
    </datasources>

The shorthand in the DataSourceComponentSelector element is how the 
datasources element in the configuration.xml file is able to be 
resolved.  The hints are used to define what the jdbc element is under 
datasources.

You could do something like the following;
    <role 
name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
          shorthand="datasources"
          
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
       
        <hint shorthand="jdbc" 
class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
        <hint shorthand="rl-jdbc"
                 
class="org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource"/>
        <hint shorthand="j2ee" 
class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
    </role>

    <datasources>
        <jdbc name="test-db" logger="app.jdbc">
            <pool-controller min="1" max="1">
                <keep-alive disable="true"/>
            </pool-controller>
            <auto-commit>true</auto-commit>
            <driver>org.hsqldb.jdbcDriver</driver>
            <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
            <user>sa</user>
            <password></password>
        </jdbc>

        <rl-jdbc name="test-rl-db" logger="app.jdbc">
            <pool-controller min="1" max="1">
                <keep-alive disable="true"/>
            </pool-controller>
            <auto-commit>true</auto-commit>
            <driver>org.hsqldb.jdbcDriver</driver>
            <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
            <user>sa</user>
            <password></password>
        </rl-jdbc>
    </datasources>

to Get 2 different datasources.  One of each implementation type.

You could then try each one out by changing the dbpool name from:
    <hello-db logger="app">
        <dbpool>test-db</dbpool>
    </hello-db>
to:
    <hello-db logger="app">
        <dbpool>test-rl-db</dbpool>
    </hello-db>


Make sense?  It really quite powerful once you get used to it.  You can 
use Component Selectors for all kinds of components, not just data sources.

Cheers,
Leif


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Question on connection pools

Posted by Mark Woon <mo...@SMI.Stanford.EDU>.
Leif Mortenson wrote:

> Let me know if you still have questions.

More questions:

What are hints used for?  I see them declared in roles.xml for the
DataSourceComponentSelector but don't see where they're actually being used.


Thanks,
-Mark


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Question on connection pools

Posted by Leif Mortenson <le...@silveregg.co.jp>.

Mark Woon wrote:

>Leif Mortenson wrote:
>
>>I just went ahead and checked in a JdbcDataSource example that I've had
>>sitting on my computer.
>>
>
>Thanks so much.  This is a great help.
>
>>It was not 100% ready for prime time documentation wise, but the example
>>itself is ready.  Go into the new examples/jdbcdatasource directory and
>>run build.  Then run bin\run.bat  (Still need to create a run.sh file)
>>
>
>The build.sh doesn't work if AVALON_HOME isn't set due to problems with the
>relative paths.  I've attached a copy of my build.sh that works.  It would be
>nice if it could get checked in with execute permissions too.
>
I program on NT.  Could someone with Linux please take care of this for 
me?  Thanks.
Also, if you could write a run.sh file at the same time I would sure 
appreciate it :-)

>>>What are my options for the connection-class parameter to
>>>pool-controller (I'm guessing this will be JdbcConnectionPool)?
>>>
>>Actually no, it defaults to
>>"org.apache.avalon.excalibur.datasource.JdbcConnection".  I also updated
>>the javadocs, so take a look checkout the latest CVS and take a look at
>>the Javadocs.  Go ahead and just leave it off as the default will work.
>>
>
>The Javadoc claims that I can set connection-class to
>"org.apache.avalon.excalibur.datasource.Jdbc3Connection" but there isn't any
>such class.  Did you mean JdbcConnection (i.e. no "3")?
>
This is only built if your JVM supports JDBC3.  The build checks for a 
class called java.sql.Savepoint which odes not exist in JDBC2 and sets 
jdbc3.present if it there.  Added this to the Javadocs.

>>> What does the keep-alive option do?
>>>
>>It is used for making sure the connection is alive before allowing it to
>>be allocated.  See New Javadocs for details. :-)
>>
>
>What happens if the connection is discovered to be dead?  Will it be disposed
>off and a new one created?
>
Yes, this will all happen transparently to the caller.  Only if a new 
connection can not be created will an SQLException be thrown.

>>>Since JdbcConnectionPool implements HardResourceLimitingPool, does this
>>>mean that the number of connections will only grow to the max, and will
>>>never shrink?
>>>
>>That is correct.  Take a look at the ResourceLimitingJdbcDataSource in
>>the scratchpad.  It will trim unused connections.
>>
>
>Would you consider this ready for production use?  Will it be moved over to
>Excalibur proper anytime soon?
>
We are using it in a production system but it is new to the checked in 
code for Excalibur.  Hopefully it will be after more people have had a 
chance to try it and give it their +1

>>Let me know if you still have questions.
>>
>
>Why doesn't JdbcDataSource declare that it implements Configurable?
>
See the implemented interface DataSourceComponent.  A little hard to 
find, but it does.
---
public interface DataSourceComponent
    extends Component, Configurable, ThreadSafe
---

>
>
>Is there a reason you use DefaultConfigurationBuilder.build(FileInputStream) vs
>DefaultConfigurationBuilder.buildFromFile(String)?  I'd think the latter would
>save you the trouble of writing the loadConfiguration method.
>
That it would.  Fixed and committed.

Cheers,
Leif



Re: Question on connection pools

Posted by Mark Woon <mo...@SMI.Stanford.EDU>.
Leif Mortenson wrote:

> I just went ahead and checked in a JdbcDataSource example that I've had
> sitting on my computer.

Thanks so much.  This is a great help.


> It was not 100% ready for prime time documentation wise, but the example
> itself is ready.  Go into the new examples/jdbcdatasource directory and
> run build.  Then run bin\run.bat  (Still need to create a run.sh file)

The build.sh doesn't work if AVALON_HOME isn't set due to problems with the
relative paths.  I've attached a copy of my build.sh that works.  It would be
nice if it could get checked in with execute permissions too.


> >What are my options for the connection-class parameter to
> >pool-controller (I'm guessing this will be JdbcConnectionPool)?
> >
> Actually no, it defaults to
> "org.apache.avalon.excalibur.datasource.JdbcConnection".  I also updated
> the javadocs, so take a look checkout the latest CVS and take a look at
> the Javadocs.  Go ahead and just leave it off as the default will work.

The Javadoc claims that I can set connection-class to
"org.apache.avalon.excalibur.datasource.Jdbc3Connection" but there isn't any
such class.  Did you mean JdbcConnection (i.e. no "3")?


> >  What does the keep-alive option do?
> >
> It is used for making sure the connection is alive before allowing it to
> be allocated.  See New Javadocs for details. :-)

What happens if the connection is discovered to be dead?  Will it be disposed
off and a new one created?


> >Since JdbcConnectionPool implements HardResourceLimitingPool, does this
> >mean that the number of connections will only grow to the max, and will
> >never shrink?
> >
> That is correct.  Take a look at the ResourceLimitingJdbcDataSource in
> the scratchpad.  It will trim unused connections.

Would you consider this ready for production use?  Will it be moved over to
Excalibur proper anytime soon?


> Let me know if you still have questions.

Why doesn't JdbcDataSource declare that it implements Configurable?

Is there a reason you use DefaultConfigurationBuilder.build(FileInputStream) vs
DefaultConfigurationBuilder.buildFromFile(String)?  I'd think the latter would
save you the trouble of writing the loadConfiguration method.


Thanks,
-Mark

Re: Question on connection pools

Posted by Leif Mortenson <le...@silveregg.co.jp>.
>
>
>I'm new to Avalon and am looking to use the connection pool that'
>Excalibur provides, although I'm a little confused as to how I'm
>actually supposed to use it.  It looks like I'm just supposed to use
>JdbcDataSource, and it'll magically handle all pooling tasks.
>
I just went ahead and checked in a JdbcDataSource example that I've had 
sitting on my computer.
It was not 100% ready for prime time documentation wise, but the example 
itself is ready.  Go into the new examples/jdbcdatasource directory and 
run build.  Then run bin\run.bat  (Still need to create a run.sh file)
Source is all there as well.  If you rebuild the excalibur docs with 
"build docs", you will find a link to what is
done so far on the documentation for the demo at the bottom of the left 
hand menu.

>
>What are my options for the connection-class parameter to
>pool-controller (I'm guessing this will be JdbcConnectionPool)?
>
Actually no, it defaults to 
"org.apache.avalon.excalibur.datasource.JdbcConnection".  I also updated 
the javadocs, so take a look checkout the latest CVS and take a look at 
the Javadocs.  Go ahead and just leave it off as the default will work.

>  What does the keep-alive option do?
>
It is used for making sure the connection is alive before allowing it to 
be allocated.  See New Javadocs for details. :-)

>Since JdbcConnectionPool implements HardResourceLimitingPool, does this
>mean that the number of connections will only grow to the max, and will
>never shrink?
>
That is correct.  Take a look at the ResourceLimitingJdbcDataSource in 
the scratchpad.  It will trim unused connections.

>Can I have multiple datasources available?  There doesn't seem to be a
>name option in the configuration for the JdbcDataSource.  How are they
>identified?
>
Take a look at the example.  You set it up by defining something like 
the following in the conponents.xml file.

    <datasources>
        <jdbc name="test-db" logger="app.jdbc">
            <pool-controller min="1" max="1">
                <keep-alive disable="true"/>
            </pool-controller>
            <auto-commit>true</auto-commit>
            <driver>org.hsqldb.jdbcDriver</driver>
            <dburl>jdbc:hsqldb:..\sqldata\example</dburl>
            <user>sa</user>
            <password></password>
        </jdbc>

        <jdbc name="another-db" logger="app.jdbc">
            <pool-controller min="1" max="1">
                <keep-alive disable="true"/>
            </pool-controller>
            <auto-commit>true</auto-commit>
            <driver>org.hsqldb.jdbcDriver</driver>
            <dburl>jdbc:hsqldb:..\sqldata\example2</dburl>
            <user>sa</user>
            <password></password>
        </jdbc>
    </datasources>

    Then you reference the different datasources using the dbpool 
element in the configurations of your components.

>My apologies if these questions would be answered if I'd just spent more
>time familiarizing myself with the Avalon Framework.  Any pointers to
>documentation would be greatly appreciated.
>
Let me know if you still have questions.

Cheers,
Leif



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>