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;
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations