Actually, Madhawa, shall we fix it with a new version of ntask component. As Sagara mentioned, put just a single method called "execute(Map<String, String> properties)", and remove all the other methods. Please create a JIRA for it, and fix it.
Cheers, Anjana. On Wed, Jun 3, 2015 at 8:58 AM, Anjana Fernando <[email protected]> wrote: > Hi Sagara, > > Yes, you're correct, earlier when this was designed first, thinking, it > would work in the way that, properties set first, init called once, and > execute called multiple times. But later on, it was discovered actually, > that Quartz creates instances of the task implementations and calls this > every time. At that time, I didn't properly make the changes to reflect > this behavior, and I agree it is a bit misleading. This has to be fixed > properly eventually. For now, we explicitly has to remember that is how the > flow will work. > > Cheers, > Anjana. > > On Wed, Jun 3, 2015 at 6:42 AM, Sagara Gunathunga <[email protected]> wrote: > >> >> org.wso2.carbon.ntask.core.Task interface has defined following 3 >> methods. >> >> setProperties(Map map) >> init() >> execute() >> >> According to my understanding it's obvious to think setProperties() and >> init() as task's lifecycle methods and call only one time during >> initialization while execute() method is call by scheduler several times >> depend on cron expression. >> >> I wrote very simple Registry Task [1] and tested, it seems all 3 methods >> runs several times. I only expect to run execute() method N times but >> actual result is all 3 methods run N times. Little debugging revealed >> during the TaskQuartzJobAdapter:execute()[2] method it calls above 3 >> methods one after another as follows. >> >> >> * task.setProperties(properties);* >> int tenantId = >> Integer.parseInt(properties.get(TaskInfo.TENANT_ID_PROP)); >> try { >> PrivilegedCarbonContext.startTenantFlow(); >> >> PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, >> true); >> *task.init();* >> * task.execute();* >> } >> >> With this I have following questions. >> >> 1.) What are the distinct design objectives of above 3 methods ? >> >> 2.) If TaskQuartzJobAdapter implementation is correct then why we need 3 >> distinct methods ? IMO *execute(properties) * can provide all these >> capabilities ? >> >> >> [1] - https://docs.wso2.com/display/Governance460/Scheduled+Task+Sample >> [2] - >> https://github.com/wso2/carbon-commons/blob/master/components/ntask/org.wso2.carbon.ntask.core/src/main/java/org/wso2/carbon/ntask/core/impl/TaskQuartzJobAdapter.java >> >> >> Thanks ! >> -- >> Sagara Gunathunga >> >> Architect; WSO2, Inc.; http://wso2.com >> V.P Apache Web Services; http://ws.apache.org/ >> Linkedin; http://www.linkedin.com/in/ssagara >> Blog ; http://ssagara.blogspot.com >> >> > > > -- > *Anjana Fernando* > Senior Technical Lead > WSO2 Inc. | http://wso2.com > lean . enterprise . middleware > -- *Anjana Fernando* Senior Technical Lead WSO2 Inc. | http://wso2.com lean . enterprise . middleware
_______________________________________________ Architecture mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
