You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by speed <su...@gmail.com> on 2006/08/11 03:39:10 UTC

scheduling a component's execution

The thing trying to accomplish is start a FilePoller component at a given
time.  I am using CronTrigger which works alright, can use SimpleTrigger as
well to send a message at 11:00 pm, MON-FRI, to the FilePoller component
which then starts and does the required work.

Is it possible to achieve that?  Please give some guidelines on what needs
to get this done.

Thank You.

Sundeep
-- 
View this message in context: http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5755598
Sent from the ServiceMix - User forum at Nabble.com.


Re: scheduling a component's execution - it works now

Posted by speed <su...@gmail.com>.
Here is what I have done, let me know if you see any problems with this
approach:

1. Extended FilePoller with MessageExchangeListner implementation
2. overwritten poll() method with one line code:
    super.stop() - it is very useful to stop polling when the first time the
component gets loaded.
3. in onMessageExchange method, added these lines along with some tracing
info:
   super.setPeriod(1)
   super.start()
   super.poll()  - I don't know whether both start() and poll() needed, one
of them should be enough.
   super.setPeriod(86400000) - poll after 24 hours now.

   Before this 24 hour period gets over it receives another quartz message
which starts polling and like that it continues on.

   so far it works great, unless someone has objection against this
approach.

Here is the code:

public class BCFilePoller extends FilePoller implements
MessageExchangeListener 
{
	private static Logger logger = Logger.getLogger(BCFilePoller.class);
	private SourceTransformer sourceTransformer = new SourceTransformer();
	
    public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
        // Skip done exchanges
        if (exchange.getStatus() == ExchangeStatus.DONE) {
            return;
        // Handle error exchanges
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            return;
        }
        
        try {
            // lets dump the incoming message
            NormalizedMessage message = exchange.getMessage("in");
            if (message == null) {
                logger.warn("Received null message from exchange: " +
exchange);
            }
            else {
                logger.info("Exchange: " + exchange + " received IN message:
" + message);
                logger.info("Body is: " +
sourceTransformer.toString(message.getContent()));
            }
            super.setPeriod(1);  //set to run now, upon receiving message
from Quartz timer.
            super.start();
            super.poll();
            super.setPeriod(86400000); //sleep until the next message
arrives
       
        catch (TransformerException e) {
            logger.error("Failed to turn message body into text: " + e, e);
        }
        catch (Exception e) {
        	ExceptionHandler.processErrorMessage("File polling failed:",
e.toString());
			throw new MessagingException("File polling failed: " + e, e);
        }
    }
    
    public void poll() throws Exception
    {
    	super.stop();
    }
}

Sundeep


speed wrote:
> 
> Yes, I will be more than happy to write this component and contribute
> here.  
> 
> The main problem I am facing is, as soon as the SU loads the FilePoller
> component it starts polling.  Is there any way to make it not start until
> the message is received.
> 
> For now I have extended the FilePoller and implemented
> MessageExchangeListener to listen to the message received from Quartz
> component.  I am not able to stop the FilePoller for the very first time
> when servicemix starts and loads the SU and underlying servicemix.xml.
> 
> Please givem some pointers and I will implement the way needs to be done.
> 
> Here is my config snippet:
> <!-- Setup a timer which polls for file on a ftp server "Every day MON-FRI
> at 11:00 PM, 0 0 23 ? * MON-FRI" -->
> 			<sm:activationSpec componentName="scheduler" service="bc:scheduler"
> destinationService="bc:filePoller">
> 		  		<sm:component>
> 					<bean
> class="org.apache.servicemix.components.quartz.QuartzComponent">
> 						<property name="triggers">
> 							<map>
> 								<entry>
> 									<key>
> 										<bean class="org.quartz.CronTrigger">
> 											<property name="name" value="VendorDataTrigger"/>
> 											<property name="group" value="ServiceMix"/>
> 											<property name="cronExpression" value="0 0 23 ? * MON-FRI"/>
> 										</bean>
> 									</key>
> 									<bean class="org.quartz.JobDetail">
> 										<property name="name" value="VendorDataJob"/>
> 										<property name="group" value="ServiceMix"/>
> 									</bean>
> 								</entry>
> 							</map>
> 						</property>
> 					</bean>
> 				</sm:component>
> 			</sm:activationSpec>
> 			
> 			<sm:activationSpec componentName="filePoller" service="bc:filePoller"
> destinationService="bc:recipients">
> 		  		<sm:component>
> 			        <bean class="com.my.components.file.BCFilePoller"> 
> 			        <property name="workManager" ref="workManager"/> 
> 			        <property name="deleteFile" value="false"/>
> 			        <property name="period" value="86400000"/>
>         			<property name="path"
> value="ftp://username:password@myftp.com/test/"/>
> 			        <property name="marshaler" ref="marshaler"/> 
> 			        </bean>
> 		        </sm:component> 
> 	      	</sm:activationSpec>
> 
> Thank You.
> Sundeep
> 
> gnodet wrote:
>> 
>> I think the way to do that would be to send the quartz message to a
>> component
>> which would start / stop the file poller using the jmx beans.
>> It will be easier and more reusable than enhancing the file poller
>> component.
>> Unfortunately, this component does not exist yet, so you will have to
>> write
>> it.
>> 
>> On 8/11/06, speed <su...@gmail.com> wrote:
>>>
>>>
>>> The thing trying to accomplish is start a FilePoller component at a
>>> given
>>> time.  I am using CronTrigger which works alright, can use SimpleTrigger
>>> as
>>> well to send a message at 11:00 pm, MON-FRI, to the FilePoller component
>>> which then starts and does the required work.
>>>
>>> Is it possible to achieve that?  Please give some guidelines on what
>>> needs
>>> to get this done.
>>>
>>> Thank You.
>>>
>>> Sundeep
>>> --
>>> View this message in context:
>>> http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5755598
>>> Sent from the ServiceMix - User forum at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> Cheers,
>> Guillaume Nodet
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5771509
Sent from the ServiceMix - User forum at Nabble.com.


Re: scheduling a component's execution

Posted by speed <su...@gmail.com>.
Yes, I will be more than happy to write this component and contribute here.  

The main problem I am facing is, as soon as the SU loads the FilePoller
component it starts polling.  Is there any way to make it not start until
the message is received.

For now I have extended the FilePoller and implemented
MessageExchangeListener to listen to the message received from Quartz
component.  I am not able to stop the FilePoller for the very first time
when servicemix starts and loads the SU and underlying servicemix.xml.

Please givem some pointers and I will implement the way needs to be done.

Here is my config snippet:
<!-- Setup a timer which polls for file on a ftp server "Every day MON-FRI
at 11:00 PM, 0 0 23 ? * MON-FRI" -->
			<sm:activationSpec componentName="scheduler" service="bc:scheduler"
destinationService="bc:filePoller">
		  		<sm:component>
					<bean class="org.apache.servicemix.components.quartz.QuartzComponent">
						<property name="triggers">
							<map>
								<entry>
									<key>
										<bean class="org.quartz.CronTrigger">
											<property name="name" value="VendorDataTrigger"/>
											<property name="group" value="ServiceMix"/>
											<property name="cronExpression" value="0 0 23 ? * MON-FRI"/>
										</bean>
									</key>
									<bean class="org.quartz.JobDetail">
										<property name="name" value="VendorDataJob"/>
										<property name="group" value="ServiceMix"/>
									</bean>
								</entry>
							</map>
						</property>
					</bean>
				</sm:component>
			</sm:activationSpec>
			
			<sm:activationSpec componentName="filePoller" service="bc:filePoller"
destinationService="bc:recipients">
		  		<sm:component>
			        <bean class="com.my.components.file.BCFilePoller"> 
			        <property name="workManager" ref="workManager"/> 
			        <property name="deleteFile" value="false"/>
			        <property name="period" value="86400000"/>
        			<property name="path"
value="ftp://username:password@myftp.com/test/"/>
			        <property name="marshaler" ref="marshaler"/> 
			        </bean>
		        </sm:component> 
	      	</sm:activationSpec>

Thank You.
Sundeep

gnodet wrote:
> 
> I think the way to do that would be to send the quartz message to a
> component
> which would start / stop the file poller using the jmx beans.
> It will be easier and more reusable than enhancing the file poller
> component.
> Unfortunately, this component does not exist yet, so you will have to
> write
> it.
> 
> On 8/11/06, speed <su...@gmail.com> wrote:
>>
>>
>> The thing trying to accomplish is start a FilePoller component at a given
>> time.  I am using CronTrigger which works alright, can use SimpleTrigger
>> as
>> well to send a message at 11:00 pm, MON-FRI, to the FilePoller component
>> which then starts and does the required work.
>>
>> Is it possible to achieve that?  Please give some guidelines on what
>> needs
>> to get this done.
>>
>> Thank You.
>>
>> Sundeep
>> --
>> View this message in context:
>> http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5755598
>> Sent from the ServiceMix - User forum at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> 
> 

-- 
View this message in context: http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5768178
Sent from the ServiceMix - User forum at Nabble.com.


Re: scheduling a component's execution

Posted by Guillaume Nodet <gn...@gmail.com>.
I think the way to do that would be to send the quartz message to a
component
which would start / stop the file poller using the jmx beans.
It will be easier and more reusable than enhancing the file poller
component.
Unfortunately, this component does not exist yet, so you will have to write
it.

On 8/11/06, speed <su...@gmail.com> wrote:
>
>
> The thing trying to accomplish is start a FilePoller component at a given
> time.  I am using CronTrigger which works alright, can use SimpleTrigger
> as
> well to send a message at 11:00 pm, MON-FRI, to the FilePoller component
> which then starts and does the required work.
>
> Is it possible to achieve that?  Please give some guidelines on what needs
> to get this done.
>
> Thank You.
>
> Sundeep
> --
> View this message in context:
> http://www.nabble.com/scheduling-a-component%27s-execution-tf2088238.html#a5755598
> Sent from the ServiceMix - User forum at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet