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
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to