use of org.ballerinalang.nativeimpl.task.SchedulingException in project ballerina by ballerina-lang.
the class BalScheduleAppointment method execute.
public void execute(Context ctx) {
FunctionRefCPEntry onTriggerFunctionRefCPEntry;
FunctionRefCPEntry onErrorFunctionRefCPEntry = null;
if (ctx.getLocalWorkerData().refRegs[0] != null && ctx.getLocalWorkerData().refRegs[0] instanceof BFunctionPointer) {
onTriggerFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(0)).value();
} else {
ctx.setReturnValues(new BString(""), BLangVMErrors.createError(ctx, 0, "The onTrigger function is not provided"));
return;
}
if (ctx.getLocalWorkerData().refRegs[1] != null && ctx.getLocalWorkerData().refRegs[1] instanceof BFunctionPointer) {
onErrorFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(1)).value();
}
String schedule = ctx.getStringArgument(0);
try {
Appointment appointment = new Appointment(this, ctx, schedule, onTriggerFunctionRefCPEntry, onErrorFunctionRefCPEntry);
ctx.setReturnValues(new BString(appointment.getId()));
} catch (SchedulingException e) {
ctx.setReturnValues(BLangVMErrors.createError(ctx, 0, e.getMessage()));
}
}
use of org.ballerinalang.nativeimpl.task.SchedulingException in project ballerina by ballerina-lang.
the class BalScheduleTimer method execute.
public void execute(Context ctx) {
FunctionRefCPEntry onTriggerFunctionRefCPEntry;
FunctionRefCPEntry onErrorFunctionRefCPEntry = null;
if (ctx.getLocalWorkerData().refRegs[0] != null && ctx.getLocalWorkerData().refRegs[0] instanceof BFunctionPointer) {
onTriggerFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(0)).value();
} else {
ctx.setReturnValues(new BString(""), BLangVMErrors.createError(ctx, 0, "The onTrigger function is not provided"));
return;
}
if (ctx.getLocalWorkerData().refRegs[1] != null && ctx.getLocalWorkerData().refRegs[1] instanceof BFunctionPointer) {
onErrorFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(1)).value();
}
BStruct scheduler = (BStruct) ctx.getRefArgument(2);
long delay = scheduler.getIntField(0);
long interval = scheduler.getIntField(1);
try {
Timer timer = new Timer(this, ctx, delay, interval, onTriggerFunctionRefCPEntry, onErrorFunctionRefCPEntry);
ctx.setReturnValues(new BString(timer.getId()));
} catch (SchedulingException e) {
ctx.setReturnValues(BLangVMErrors.createError(ctx, 0, e.getMessage()));
}
}
Aggregations