This post explains how the scheduled task works in WSO2 DSS
This example is tested in WSO2 DSS 3.0.1
1. Write the following class which extends the org.wso2.carbon.dataservices.task.DataTask interface.
package com.example.DssSchedlueTask;
import java.util.HashMap;
import java.util.Map;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.engine.ParamValue;
import org.wso2.carbon.dataservices.task.DataTask;
import org.wso2.carbon.dataservices.task.DataTaskContext;
public class ScheduledDataTask_abcCompany implements DataTask {
public void execute(DataTaskContext ctx) {
System.out.println("Data Task executing...");
String soldItems = getSoldItems();
Map<String, ParamValue> params = new HashMap<String, ParamValue>();
params.put("soldItems", new ParamValue(soldItems));
params.put("productCode", new ParamValue("0001a3"));
try {
ctx.invokeOperation("abcCompany", "UpdateSales", params);
System.out.println("Successfully updated the database. \tSoldItems = "+soldItems);
} catch (DataServiceFault e) {
System.out.println("Error...."+e.getMessage());
}
}
private String getSoldItems(){
int soldItems = (int )(Math.random() * 10000 + 1);
return Integer.toString(soldItems);
}
}
Assume that you are getting sold items from another service, here you will get a random number for the sold items, and you are going to update your system with that value.
2.Then create the jar of the above class and copy it to the DSS_HOME/repository/components/lib folder and start the WSO2 DSS server.
3. Create a Keyspace name ‘abcCompany’ in cassandra db. Then create a columnfamily name ‘salesDetails’ in abcCompany keyspace.
cqlsh:abccompany> CREATE COLUMNFAMILY salesDetails ( productCode varchar PRIMARY KEY , productName varchar , soldItems int, instock int) ;
4. Insert following dummy values to the above created column family.
cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0001a3', 'phone a3', 9999, 10000);
cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0001b2', 'phone b2', 99, 100);
cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0002x5', 'phone x5', 9, 10);
Continue reading →