korosh afshar wrote:

Does anyone have a code snipet showing how to use the Scheduler service
component to setup  periodic timers ?


Korosh.



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



I can make no representation of the quality of my code as I'm new to avalon but heres a bit:


import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler; import org.apache.avalon.cornerstone.services.scheduler.Target; import org.apache.avalon.cornerstone.services.scheduler.TimeTriggerFactory;

<...>

/**
* Servicing of the component by the container during which the
* component aquires the ThreadManager service.
*
* @param manager the thread manager
* @exception ServiceException if the thread manager service is
* unresolvable
*
* @avalon.dependency key="scheduler" type="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"
*
* @avalon.dependency key="spoolmonitors" type="example.services.spoolmonitor.SpoolMonitorSelector"
*
*
*/
public void service( ServiceManager manager ) throws ServiceException
{
m_manager=manager;
getLogger().info( "acquiring TimeScheduler" );
m_scheduler= (TimeScheduler) m_manager.lookup( "scheduler" );
getLogger().info( "acquiring SpoolMonitorSelector" );
m_spoolmonitorselector= (SpoolMonitorSelector) m_manager.lookup( "spoolmonitors" );
}


/* (non-Javadoc)
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration config) throws ConfigurationException {
getLogger().info( "starting configuration" );
m_configuration=config;
}
/**
* @exception Exception if an initialization stage error occurs
*/
public void initialize() throws Exception
{
getLogger().info( "initialization" );
TimeTriggerFactory ttf=new TimeTriggerFactory();
Configuration [] spools = m_configuration.getChildren( "spool" );
getLogger().info( "number of spools: "+spools.length );
for (int i=0; i<spools.length; i++) {
String name = spools[i].getAttribute( "name" );
String spoolmonitorname = spools[i].getAttribute( "monitor" );
getLogger().info( "spool: "+name+" "+spoolmonitorname );
Target sm = (Target) m_spoolmonitorselector.select(spoolmonitorname);


final Configuration conf=spools[i].getChild("trigger");
getLogger().info( "configuring spool "+ name );
m_scheduler.addTrigger(name, ttf.createTimeTrigger(spools[i].getChild("trigger")), sm);
}
getLogger().info( "end of initialization" );
}



block.xml


<component name="spoolmanager" class="example.spoolmanager.SpoolManager" 
activation="startup">
        <configuration>
                <spool name="daf-monitor" monitor="daf">
                        <trigger type="periodic">
                                <offset>5000</offset>
                                <period>5000</period>
                        </trigger>
                </spool>
        </configuration>
</component>


--Jon



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to