Search in sources :

Example 1 with SchedulingException

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()));
    }
}
Also used : FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) SchedulingException(org.ballerinalang.nativeimpl.task.SchedulingException) BFunctionPointer(org.ballerinalang.model.values.BFunctionPointer)

Example 2 with SchedulingException

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()));
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) BString(org.ballerinalang.model.values.BString) SchedulingException(org.ballerinalang.nativeimpl.task.SchedulingException) BFunctionPointer(org.ballerinalang.model.values.BFunctionPointer)

Aggregations

BFunctionPointer (org.ballerinalang.model.values.BFunctionPointer)2 BString (org.ballerinalang.model.values.BString)2 SchedulingException (org.ballerinalang.nativeimpl.task.SchedulingException)2 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)2 BStruct (org.ballerinalang.model.values.BStruct)1