use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class CPU method beginTransaction.
private static void beginTransaction(WorkerExecutionContext ctx, int transactionBlockId, int retryCountRegIndex, int committedFuncIndex, int abortedFuncIndex) {
// If global tx enabled, it is managed via transaction coordinator. Otherwise it is managed locally without
// any interaction with the transaction coordinator.
boolean isGlobalTransactionEnabled = ctx.getGlobalTransactionEnabled();
// Transaction is attempted three times by default to improve resiliency
int retryCount = TransactionConstants.DEFAULT_RETRY_COUNT;
if (retryCountRegIndex != -1) {
retryCount = (int) ctx.workerLocal.longRegs[retryCountRegIndex];
if (retryCount < 0) {
ctx.setError(BLangVMErrors.createError(ctx, BLangExceptionHelper.getErrorMessage(RuntimeErrors.INVALID_RETRY_COUNT)));
handleError(ctx);
return;
}
}
// Register committed function handler if exists.
if (committedFuncIndex != -1) {
FunctionRefCPEntry funcRefCPEntry = (FunctionRefCPEntry) ctx.constPool[committedFuncIndex];
BFunctionPointer fpCommitted = new BFunctionPointer(funcRefCPEntry);
TransactionResourceManager.getInstance().registerCommittedFunction(transactionBlockId, fpCommitted);
}
// Register aborted function handler if exists.
if (abortedFuncIndex != -1) {
FunctionRefCPEntry funcRefCPEntry = (FunctionRefCPEntry) ctx.constPool[abortedFuncIndex];
BFunctionPointer fpAborted = new BFunctionPointer(funcRefCPEntry);
TransactionResourceManager.getInstance().registerAbortedFunction(transactionBlockId, fpAborted);
}
LocalTransactionInfo localTransactionInfo = ctx.getLocalTransactionInfo();
if (localTransactionInfo == null) {
String globalTransactionId;
String protocol = null;
String url = null;
if (isGlobalTransactionEnabled) {
BValue[] returns = TransactionUtils.notifyTransactionBegin(ctx, null, null, transactionBlockId, TransactionConstants.DEFAULT_COORDINATION_TYPE);
BStruct txDataStruct = (BStruct) returns[0];
globalTransactionId = txDataStruct.getStringField(1);
protocol = txDataStruct.getStringField(2);
url = txDataStruct.getStringField(3);
} else {
globalTransactionId = UUID.randomUUID().toString().replaceAll("-", "");
}
localTransactionInfo = new LocalTransactionInfo(globalTransactionId, url, protocol);
ctx.setLocalTransactionInfo(localTransactionInfo);
} else {
if (isGlobalTransactionEnabled) {
TransactionUtils.notifyTransactionBegin(ctx, localTransactionInfo.getGlobalTransactionId(), localTransactionInfo.getURL(), transactionBlockId, localTransactionInfo.getProtocol());
}
}
localTransactionInfo.beginTransactionBlock(transactionBlockId, retryCount);
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class CallableWorkerResponseContext method propagateErrorToTarget.
protected WorkerExecutionContext propagateErrorToTarget() {
BStruct error = BLangVMErrors.createCallFailedException(this.targetCtx, this.getWorkerErrors());
WorkerExecutionContext ctx = this.onFinalizedError(this.targetCtx, error);
this.doFailCallbackNotify(error);
return ctx;
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class AsyncInvocableWorkerResponseContext method sendAsyncCancelErrorSignal.
private void sendAsyncCancelErrorSignal() {
WorkerData result = BLangVMUtils.createWorkerData(this.callableUnitInfo.retWorkerIndex);
BStruct error = BLangVMErrors.createCallCancelledException(this.callableUnitInfo);
WorkerExecutionContext ctx = this.signal(new WorkerSignal(new WorkerExecutionContext(error), SignalType.ERROR, result));
BLangScheduler.resume(ctx);
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class BLangVMErrors method getCasueStackTrace.
public static String getCasueStackTrace(BStruct error) {
StringBuilder sb = new StringBuilder();
// Get error type name and the message (if any)
String errorMsg = getErrorMessage(error);
sb.append(errorMsg).append("\n\tat ");
BStruct stackFrame = (BStruct) error.getNativeData(STRUCT_CALL_STACK_ELEMENT);
// Append function/action/resource name with package path (if any)
if (stackFrame.getStringField(1).isEmpty() || stackFrame.getStringField(1).equals(PACKAGE_BUILTIN)) {
sb.append(stackFrame.getStringField(0));
} else {
sb.append(stackFrame.getStringField(1)).append(":").append(stackFrame.getStringField(0));
}
// Append the filename
sb.append("(").append(stackFrame.getStringField(2));
// Append the line number
if (stackFrame.getIntField(0) > 0) {
sb.append(":").append(stackFrame.getIntField(0));
}
sb.append(")");
BRefValueArray cause = (BRefValueArray) error.getRefField(0);
if (cause != null && cause.size() > 0) {
sb.append("\ncaused by ").append(getCauseStackTraceArray(cause));
}
return sb.toString();
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class BLangVMStructs method createBStruct.
/**
* Create BStruct for given StructInfo and BValues.
*
* @param structInfo {@link StructInfo} of the BStruct
* @param values field values of the BStruct.
* @return BStruct instance.
*/
public static BStruct createBStruct(StructInfo structInfo, Object... values) {
BStructType structType = structInfo.getType();
BStruct bStruct = new BStruct(structType);
int[] indexes = new int[] { -1, -1, -1, -1, -1, -1 };
BStructType.StructField[] structFields = structType.getStructFields();
for (int i = 0; i < structFields.length; i++) {
if (values.length < i + 1) {
break;
}
BType paramType = structFields[i].getFieldType();
setValue(bStruct, indexes, paramType.getTag(), values[i]);
}
return bStruct;
}
Aggregations