You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@synapse.apache.org by Paul Fremantle <pz...@gmail.com> on 2007/08/07 18:26:14 UTC

Simple Quartz job scheduling in Synapse

I've just checked in the code for the simplified Quartz-based
scheduling of jobs.

Here is how it works:

You define a class that implements org.apache.synapse.startup.Job. You
most likely need to also implement ManagedLifeCycle to get hold of the
SynapseEnvironment at init() time.

Your class can also implement setX(String val) or setY(OMElement val2)
and these will be injected before execute(); is called.

You then define when and how often to call this class, along with any
injectable properties.

Here is a sample synapse.xml fragment:
<startup>
  <job class="MessageInjector">
      <simpletrigger count="10" interval="5000"/>
      <property name="message">
         <test xmlns="urn:paul"/>
      </property>
      <property name="to" value="urn:test"/>
    </job>
  </startup>

To make life a little easier I figured we might create some default
built-in Jobs. I've created a package org.apache.synapse.startup.jobs.
There is one job there already - MessageInjector. It allows you to
specify a static XML and To address and it injects a message there.

To make life a teensy bit easier, you don't need to specify the full
class name for any job in that package. If there is no package set
then I concatenate that package, so specifying class="MessageInjector"
is the same as specifying
"org.apache.synapse.startup.jobs.MessageInjector

Here is core of the code for MessageInjector:
	public void execute() {
		MessageContext mc = synapseEnvironment.createMessageContext();
		mc.setTo(new EndpointReference(to));
		PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
		synapseEnvironment.injectMessage(mc);

	}

You can read the full code here:
http://tinyurl.com/2v465m

Personally I think this is a nice feature (yeah I know I added it :-))

One last thing - the build doesn't correctly add
commons-collection-3.1.jar to the Synapse lib directory, so you need
to do that. Can someone (Ruwan!) please fix that?

Paul


-- 
Paul Fremantle
Co-Founder and VP of Technical Sales, WSO2
OASIS WS-RX TC Co-chair

blog: http://pzf.fremantle.org
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-user-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-user-help@ws.apache.org


Re: Simple Quartz job scheduling in Synapse

Posted by Ruwan Linton <ru...@gmail.com>.
Fixed.
Paul, can you have a look and confirm whether it is OK now?

Thanks,
Ruwan

On 8/8/07, Ruwan Linton <ru...@gmail.com> wrote:
>
> Seems cool, I will fix the build.
>
> Thanks,
> Ruwan
>
> On 8/7/07, Paul Fremantle <pz...@gmail.com> wrote:
> >
> > I've just checked in the code for the simplified Quartz-based
> > scheduling of jobs.
> >
> > Here is how it works:
> >
> > You define a class that implements org.apache.synapse.startup.Job. You
> > most likely need to also implement ManagedLifeCycle to get hold of the
> > SynapseEnvironment at init() time.
> >
> > Your class can also implement setX(String val) or setY(OMElement val2)
> > and these will be injected before execute(); is called.
> >
> > You then define when and how often to call this class, along with any
> > injectable properties.
> >
> > Here is a sample synapse.xml fragment:
> > <startup>
> >   <job class="MessageInjector">
> >       <simpletrigger count="10" interval="5000"/>
> >       <property name="message">
> >          <test xmlns="urn:paul"/>
> >       </property>
> >       <property name="to" value="urn:test"/>
> >     </job>
> >   </startup>
> >
> > To make life a little easier I figured we might create some default
> > built-in Jobs. I've created a package org.apache.synapse.startup.jobs.
> > There is one job there already - MessageInjector. It allows you to
> > specify a static XML and To address and it injects a message there.
> >
> > To make life a teensy bit easier, you don't need to specify the full
> > class name for any job in that package. If there is no package set
> > then I concatenate that package, so specifying class="MessageInjector"
> > is the same as specifying
> > "org.apache.synapse.startup.jobs.MessageInjector
> >
> > Here is core of the code for MessageInjector:
> >         public void execute() {
> >                 MessageContext mc =
> > synapseEnvironment.createMessageContext ();
> >                 mc.setTo(new EndpointReference(to));
> >                 PayloadHelper.setXMLPayload(mc, message.cloneOMElement
> > ());
> >                 synapseEnvironment.injectMessage(mc);
> >
> >         }
> >
> > You can read the full code here:
> > http://tinyurl.com/2v465m
> >
> > Personally I think this is a nice feature (yeah I know I added it :-))
> >
> > One last thing - the build doesn't correctly add
> > commons-collection-3.1.jar to the Synapse lib directory, so you need
> > to do that. Can someone (Ruwan!) please fix that?
> >
> > Paul
> >
> >
> > --
> > Paul Fremantle
> > Co-Founder and VP of Technical Sales, WSO2
> > OASIS WS-RX TC Co-chair
> >
> > blog: http://pzf.fremantle.org
> > paul@wso2.com
> >
> > "Oxygenating the Web Service Platform", www.wso2.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail: synapse-dev-help@ws.apache.org
> >
> >
>
>
> --
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"




-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: Simple Quartz job scheduling in Synapse

Posted by Ruwan Linton <ru...@gmail.com>.
Seems cool, I will fix the build.

Thanks,
Ruwan

On 8/7/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> I've just checked in the code for the simplified Quartz-based
> scheduling of jobs.
>
> Here is how it works:
>
> You define a class that implements org.apache.synapse.startup.Job. You
> most likely need to also implement ManagedLifeCycle to get hold of the
> SynapseEnvironment at init() time.
>
> Your class can also implement setX(String val) or setY(OMElement val2)
> and these will be injected before execute(); is called.
>
> You then define when and how often to call this class, along with any
> injectable properties.
>
> Here is a sample synapse.xml fragment:
> <startup>
>   <job class="MessageInjector">
>       <simpletrigger count="10" interval="5000"/>
>       <property name="message">
>          <test xmlns="urn:paul"/>
>       </property>
>       <property name="to" value="urn:test"/>
>     </job>
>   </startup>
>
> To make life a little easier I figured we might create some default
> built-in Jobs. I've created a package org.apache.synapse.startup.jobs.
> There is one job there already - MessageInjector. It allows you to
> specify a static XML and To address and it injects a message there.
>
> To make life a teensy bit easier, you don't need to specify the full
> class name for any job in that package. If there is no package set
> then I concatenate that package, so specifying class="MessageInjector"
> is the same as specifying
> "org.apache.synapse.startup.jobs.MessageInjector
>
> Here is core of the code for MessageInjector:
>         public void execute() {
>                 MessageContext mc =
> synapseEnvironment.createMessageContext();
>                 mc.setTo(new EndpointReference(to));
>                 PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
>                 synapseEnvironment.injectMessage(mc);
>
>         }
>
> You can read the full code here:
> http://tinyurl.com/2v465m
>
> Personally I think this is a nice feature (yeah I know I added it :-))
>
> One last thing - the build doesn't correctly add
> commons-collection-3.1.jar to the Synapse lib directory, so you need
> to do that. Can someone (Ruwan!) please fix that?
>
> Paul
>
>
> --
> Paul Fremantle
> Co-Founder and VP of Technical Sales, WSO2
> OASIS WS-RX TC Co-chair
>
> blog: http://pzf.fremantle.org
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>


-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: Simple Quartz job scheduling in Synapse

Posted by Paul Fremantle <pz...@gmail.com>.
Actually you can use a class without a namespace because it will try
that first.

I will doc the whole thing properly when I get back to proper Internet access.

Paul

On 8/18/07, Sanjiva Weerawarana <sa...@opensource.lk> wrote:
> Paul Fremantle wrote:
> >
> > To make life a teensy bit easier, you don't need to specify the full
> > class name for any job in that package. If there is no package set
> > then I concatenate that package, so specifying class="MessageInjector"
> > is the same as specifying
> > "org.apache.synapse.startup.jobs.MessageInjector
>
> -1 for this bit .. it means you can't use a class without a namespace! I
> don't see value in this "extra, extra sugar"!
>
> Has the language spec been updated with the new extension? I'd like to
> think about the whole thing but need to see the big picture first!
>
> Thanks,
>
> Sanjiva.
> --
> Sanjiva Weerawarana, Ph.D.
> Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
> Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
> Member; Apache Software Foundation; http://www.apache.org/
> Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>


-- 
Paul Fremantle
Co-Founder and VP of Technical Sales, WSO2
OASIS WS-RX TC Co-chair

blog: http://pzf.fremantle.org
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

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


Re: Simple Quartz job scheduling in Synapse

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
Paul Fremantle wrote:
> 
> To make life a teensy bit easier, you don't need to specify the full
> class name for any job in that package. If there is no package set
> then I concatenate that package, so specifying class="MessageInjector"
> is the same as specifying
> "org.apache.synapse.startup.jobs.MessageInjector

-1 for this bit .. it means you can't use a class without a namespace! I 
don't see value in this "extra, extra sugar"!

Has the language spec been updated with the new extension? I'd like to 
think about the whole thing but need to see the big picture first!

Thanks,

Sanjiva.
-- 
Sanjiva Weerawarana, Ph.D.
Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
Member; Apache Software Foundation; http://www.apache.org/
Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/

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