Search in sources :

Example 6 with CallableUnitCallback

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

the class WriteCharacters method writeResponse.

/**
 * Processors the response after reading characters.
 *
 * @param result the response returned after reading characters.
 * @return the response returned from the event.
 */
private static EventResult writeResponse(EventResult<Integer, EventContext> result) {
    BStruct errorStruct = null;
    EventContext eventContext = result.getContext();
    Integer numberOfCharactersWritten = result.getResponse();
    Context context = eventContext.getContext();
    CallableUnitCallback callback = eventContext.getCallback();
    Throwable error = eventContext.getError();
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
        context.setReturnValues(errorStruct);
    } else {
        context.setReturnValues(new BInteger(numberOfCharactersWritten));
    }
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BInteger(org.ballerinalang.model.values.BInteger) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 7 with CallableUnitCallback

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

the class WriteTextRecord method writeResponse.

/**
 * Callback response received after the bytes are written.
 *
 * @param result the response received.
 * @return the result context.
 */
private static EventResult writeResponse(EventResult<Integer, 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 8 with CallableUnitCallback

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

the class CloseCharacterChannel 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 9 with CallableUnitCallback

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

the class ServerStreamingListener method invoke.

@Override
public void invoke(Message request, StreamObserver<Message> responseObserver) {
    List<ParamDetail> paramDetails = resource.getParamDetails();
    BValue[] signatureParams = new BValue[paramDetails.size()];
    signatureParams[0] = getConnectionParameter(resource, responseObserver);
    BValue requestParam = getRequestParameter(resource, request);
    if (requestParam != null) {
        signatureParams[1] = requestParam;
    }
    CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, isEmptyResponse());
    Executor.submit(resource, callback, null, null, signatureParams);
}
Also used : GrpcCallableUnitCallBack(org.ballerinalang.net.grpc.GrpcCallableUnitCallBack) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 10 with CallableUnitCallback

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

the class UnaryMethodListener method invoke.

@Override
public void invoke(Message request, StreamObserver<Message> responseObserver) {
    List<ParamDetail> paramDetails = resource.getParamDetails();
    BValue[] signatureParams = new BValue[paramDetails.size()];
    signatureParams[0] = getConnectionParameter(resource, responseObserver);
    BValue requestParam = getRequestParameter(resource, request);
    if (requestParam != null) {
        signatureParams[1] = requestParam;
    }
    CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, isEmptyResponse());
    Executor.submit(resource, callback, null, null, signatureParams);
}
Also used : GrpcCallableUnitCallBack(org.ballerinalang.net.grpc.GrpcCallableUnitCallBack) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Aggregations

CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)21 BStruct (org.ballerinalang.model.values.BStruct)15 Context (org.ballerinalang.bre.Context)12 EventContext (org.ballerinalang.nativeimpl.io.events.EventContext)11 BValue (org.ballerinalang.model.values.BValue)9 ParamDetail (org.ballerinalang.connector.api.ParamDetail)8 GrpcCallableUnitCallBack (org.ballerinalang.net.grpc.GrpcCallableUnitCallBack)7 Resource (org.ballerinalang.connector.api.Resource)6 BString (org.ballerinalang.model.values.BString)5 BType (org.ballerinalang.model.types.BType)4 BInteger (org.ballerinalang.model.values.BInteger)3 StreamObserver (io.grpc.stub.StreamObserver)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BLangConnectorSPIUtil (org.ballerinalang.connector.api.BLangConnectorSPIUtil)2 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)2 Executor (org.ballerinalang.connector.api.Executor)2 Message (org.ballerinalang.net.grpc.Message)2 PROTOCOL_PACKAGE_HTTP (org.ballerinalang.net.http.HttpConstants.PROTOCOL_PACKAGE_HTTP)2