james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Jackson" <foamd...@gmail.com>
Subject Accessing JdbcDataSource config in custom service
Date Mon, 01 Oct 2007 06:32:20 GMT
Hi,

Further to my request for help concerning removing spam mail after 15 days:

In my james config.xml I have:

<!-- configure to remove old mails from repository -->
   <mailclean enabled="true">
     <cleanup name="spams">
       <!-- 24*60*60*1000 = 1 day -->
       <interval>86400000</interval>
       <mail-cleaner delay="15" schema="public" table="spams"/>
     </cleanup>
   </mailclean>

In my CleanMailRepoService code I have: (taken from FetchScheduler)

Configuration[] confs = conf.getChildren( "cleanup" );
            for(int i=0; i<confs.length; i++) {
            	Configuration conf = confs[i];
                String cleanName = conf.getAttribute( "name" );
                Integer interval = new Integer( conf.getChild(
"interval" ).getValue() );

                MailCleaner mc = new MailCleaner();

                /* avalon specific initialization */
                ContainerUtil.enableLogging(
mc,getLogger().getChildLogger( cleanName ) );
                ContainerUtil.service( mc,manager );
                ContainerUtil.configure( mc,conf );

and in my MailCleaner code I have:

public void configure(Configuration conf) throws ConfigurationException {
		Configuration jdbcConf = conf.getChild( "database-connections"
).getChild( "data-source" );
		ds = new JdbcDataSource();
		ds.configure( jdbcConf );
		Configuration mConf = conf.getChild( "mail-cleaner" );
		delay = mConf.getAttributeAsInteger( "delay" );
		schema = mConf.getAttribute( "schema" );
		table = mConf.getAttribute( "table" );
	}

Finally my CleanMailRepoService xinfo:

<blockinfo>

  <!-- section to describe block -->
  <block>
    <version>1.0</version>
  </block>

  <!-- services that are offered by this block -->
  <services/>

  <dependencies>
    <dependency>
      <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector"
version="1.0"/>
    </dependency>
    <dependency>
      <service name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"
version="1.0"/>
    </dependency>
  </dependencies>
</blockinfo>

Now I want to access the <database-connections> config from the
config.xml, but I can only access it if I duplicate that config in my
<mailclean> section (and I don't want to do that)

Is there a way of injecting the JdbcDataSource into my code without
having a duplicate block of config?

Another option is not to perform any configuration in the
CleanMailRepoService (but I have to do this to setup the scheduler).

Any advice on how to get my desired result in the most avalon-like way
is much appreciated.

Thanks,
Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message