Search in sources :

Example 11 with Context

use of org.ballerinalang.bre.Context in project ballerina by ballerina-lang.

the class Close method closeResponse.

private static EventResult closeResponse(EventResult<Boolean, EventContext> result) {
    BStruct errorStruct = null;
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    CallableUnitCallback callback = eventContext.getCallback();
    Throwable error = eventContext.getError();
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
    }
    context.setReturnValues(errorStruct);
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BStruct(org.ballerinalang.model.values.BStruct) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 12 with Context

use of org.ballerinalang.bre.Context in project ballerina by ballerina-lang.

the class CloseDelimitedRecordChannel method closeResponse.

private static EventResult closeResponse(EventResult<Boolean, EventContext> result) {
    BStruct errorStruct = null;
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    CallableUnitCallback callback = eventContext.getCallback();
    Throwable error = eventContext.getError();
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
    }
    context.setReturnValues(errorStruct);
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BStruct(org.ballerinalang.model.values.BStruct) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 13 with Context

use of org.ballerinalang.bre.Context in project ballerina by ballerina-lang.

the class NextTextRecord method response.

/*
     * Response obtained after reading record.
     *
     * @param result the result obtained after processing the record.
     * @return the response obtained after reading record.
     */
private static EventResult response(EventResult<String[], EventContext> result) {
    BStruct errorStruct = null;
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    String[] fields = result.getResponse();
    CallableUnitCallback callback = eventContext.getCallback();
    Throwable error = eventContext.getError();
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
        context.setReturnValues(errorStruct);
    } else {
        context.setReturnValues(new BStringArray(fields));
    }
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BStruct(org.ballerinalang.model.values.BStruct) BStringArray(org.ballerinalang.model.values.BStringArray) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 14 with Context

use of org.ballerinalang.bre.Context in project ballerina by ballerina-lang.

the class Read method readResponse.

/*
     * Function which will be notified on the response obtained after the async operation.
     *
     * @param result context of the callback.
     * @return Once the callback is processed we further return back the result.
     */
private static EventResult readResponse(EventResult<Integer, EventContext> result) {
    BStruct errorStruct;
    BRefValueArray contentTuple = new BRefValueArray(readTupleType);
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    Throwable error = eventContext.getError();
    Integer numberOfBytes = result.getResponse();
    CallableUnitCallback callback = eventContext.getCallback();
    byte[] content = (byte[]) eventContext.getProperties().get(ReadBytesEvent.CONTENT_PROPERTY);
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
        context.setReturnValues(errorStruct);
    } else {
        contentTuple.add(0, new BBlob(content));
        contentTuple.add(1, new BInteger(numberOfBytes));
        context.setReturnValues(contentTuple);
    }
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BInteger(org.ballerinalang.model.values.BInteger) BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BBlob(org.ballerinalang.model.values.BBlob) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 15 with Context

use of org.ballerinalang.bre.Context in project ballerina by ballerina-lang.

the class ReadCharacters method readCharactersResponse.

/*
     * Callback method of the read characters response.
     *
     * @param result the result returned as the response.
     * @return the processed event result.
     */
private static EventResult readCharactersResponse(EventResult<String, EventContext> result) {
    BStruct errorStruct = null;
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    CallableUnitCallback callback = eventContext.getCallback();
    String readChars = result.getResponse();
    Throwable error = eventContext.getError();
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
        context.setReturnValues(errorStruct);
    } else {
        context.setReturnValues(new BString(readChars));
    }
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Aggregations

Context (org.ballerinalang.bre.Context)15 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)12 EventContext (org.ballerinalang.nativeimpl.io.events.EventContext)11 BStruct (org.ballerinalang.model.values.BStruct)10 NativeCallableUnit (org.ballerinalang.model.NativeCallableUnit)3 BInteger (org.ballerinalang.model.values.BInteger)3 NativeCallContext (org.ballerinalang.bre.NativeCallContext)2 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)2 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)2 ForkJoinWorkerResponseContext (org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext)2 InitWorkerResponseContext (org.ballerinalang.bre.bvm.InitWorkerResponseContext)2 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)2 WorkerData (org.ballerinalang.bre.bvm.WorkerData)2 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)2 WorkerResponseContext (org.ballerinalang.bre.bvm.WorkerResponseContext)2 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)2 Path (java.nio.file.Path)1 List (java.util.List)1 BLangProgramLoader (org.ballerinalang.BLangProgramLoader)1 BLangCallableUnitCallback (org.ballerinalang.bre.BLangCallableUnitCallback)1