Search in sources :

Example 66 with BValue

use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.

the class BLangVMUtils method populateReturnData.

public static BValue[] populateReturnData(WorkerExecutionContext ctx, CallableUnitInfo callableUnitInfo, int[] retRegs) {
    WorkerData data = ctx.workerLocal;
    BType[] retTypes = callableUnitInfo.getRetParamTypes();
    BValue[] returnValues = new BValue[retTypes.length];
    for (int i = 0; i < returnValues.length; i++) {
        BType retType = retTypes[i];
        switch(retType.getTag()) {
            case TypeTags.INT_TAG:
                returnValues[i] = new BInteger(data.longRegs[retRegs[i]]);
                break;
            case TypeTags.FLOAT_TAG:
                returnValues[i] = new BFloat(data.doubleRegs[retRegs[i]]);
                break;
            case TypeTags.STRING_TAG:
                returnValues[i] = new BString(data.stringRegs[retRegs[i]]);
                break;
            case TypeTags.BOOLEAN_TAG:
                boolean boolValue = data.intRegs[retRegs[i]] == 1;
                returnValues[i] = new BBoolean(boolValue);
                break;
            case TypeTags.BLOB_TAG:
                returnValues[i] = new BBlob(data.byteRegs[retRegs[i]]);
                break;
            default:
                returnValues[i] = data.refRegs[retRegs[i]];
                break;
        }
    }
    return returnValues;
}
Also used : BType(org.ballerinalang.model.types.BType) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BBoolean(org.ballerinalang.model.values.BBoolean) WorkerData(org.ballerinalang.bre.bvm.WorkerData) BBlob(org.ballerinalang.model.values.BBlob)

Example 67 with BValue

use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.

the class TransactionResourceManager method invokeCommittedFunction.

private void invokeCommittedFunction(int transactionBlockId) {
    BFunctionPointer fp = committedFuncRegistry.get(transactionBlockId);
    if (fp != null) {
        BValue[] args = {};
        BLangFunctions.invokeCallable(fp.value().getFunctionInfo(), args);
    }
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFunctionPointer(org.ballerinalang.model.values.BFunctionPointer)

Example 68 with BValue

use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.

the class ConnectionAction method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    HTTPCarbonMessage inboundRequestMsg = HttpUtil.getCarbonMsg(connectionStruct, null);
    HttpUtil.checkFunctionValidity(connectionStruct, inboundRequestMsg);
    BStruct outboundResponseStruct = (BStruct) context.getRefArgument(1);
    HTTPCarbonMessage outboundResponseMsg = HttpUtil.getCarbonMsg(outboundResponseStruct, HttpUtil.createHttpCarbonMessage(false));
    HttpUtil.prepareOutboundResponse(context, inboundRequestMsg, outboundResponseMsg, outboundResponseStruct);
    if (CacheUtils.isValidCachedResponse(outboundResponseMsg, inboundRequestMsg)) {
        outboundResponseMsg.setProperty(HTTP_STATUS_CODE, HttpResponseStatus.NOT_MODIFIED.code());
        outboundResponseMsg.waitAndReleaseAllEntities();
        outboundResponseMsg.completeMessage();
    }
    BValue[] outboundResponseStatus = sendOutboundResponseRobust(context, inboundRequestMsg, outboundResponseStruct, outboundResponseMsg);
    context.setReturnValues(outboundResponseStatus);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) BValue(org.ballerinalang.model.values.BValue)

Example 69 with BValue

use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.

the class WebSocketDispatcher method dispatchIdleTimeout.

public static void dispatchIdleTimeout(WebSocketOpenConnectionInfo connectionInfo, WebSocketControlMessage controlMessage) {
    WebSocketService wsService = connectionInfo.getService();
    Resource onIdleTimeoutResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_IDLE_TIMEOUT);
    if (onIdleTimeoutResource == null) {
        return;
    }
    List<ParamDetail> paramDetails = onIdleTimeoutResource.getParamDetails();
    BValue[] bValues = new BValue[paramDetails.size()];
    bValues[0] = connectionInfo.getWsConnection();
    // TODO handle BallerinaConnectorException
    Executor.submit(onIdleTimeoutResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Also used : ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) Resource(org.ballerinalang.connector.api.Resource)

Example 70 with BValue

use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.

the class WebSocketDispatcher method dispatchTextMessage.

public static void dispatchTextMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketTextMessage textMessage) {
    WebSocketService wsService = connectionInfo.getService();
    Resource onTextMessageResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_TEXT_MESSAGE);
    if (onTextMessageResource == null) {
        return;
    }
    List<ParamDetail> paramDetails = onTextMessageResource.getParamDetails();
    BValue[] bValues = new BValue[paramDetails.size()];
    bValues[0] = connectionInfo.getWsConnection();
    BStruct wsTextFrame = wsService.createTextFrameStruct();
    wsTextFrame.setStringField(0, textMessage.getText());
    if (textMessage.isFinalFragment()) {
        wsTextFrame.setBooleanField(0, 1);
    } else {
        wsTextFrame.setBooleanField(0, 0);
    }
    bValues[1] = wsTextFrame;
    // TODO handle BallerinaConnectorException
    Executor.submit(onTextMessageResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) Resource(org.ballerinalang.connector.api.Resource)

Aggregations

BValue (org.ballerinalang.model.values.BValue)1043 Test (org.testng.annotations.Test)923 BString (org.ballerinalang.model.values.BString)437 BInteger (org.ballerinalang.model.values.BInteger)323 BStruct (org.ballerinalang.model.values.BStruct)188 BFloat (org.ballerinalang.model.values.BFloat)118 BJSON (org.ballerinalang.model.values.BJSON)112 BBoolean (org.ballerinalang.model.values.BBoolean)79 CompileResult (org.ballerinalang.launcher.util.CompileResult)60 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)45 BMap (org.ballerinalang.model.values.BMap)43 BXMLItem (org.ballerinalang.model.values.BXMLItem)42 BXML (org.ballerinalang.model.values.BXML)40 BStringArray (org.ballerinalang.model.values.BStringArray)30 BIntArray (org.ballerinalang.model.values.BIntArray)25 BBlob (org.ballerinalang.model.values.BBlob)23 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)19 BeforeTest (org.testng.annotations.BeforeTest)19 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)19 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)16