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