use of org.ballerinalang.connector.api.ParamDetail in project ballerina by ballerina-lang.
the class ClientStreamingListener method invoke.
@Override
public StreamObserver<Message> invoke(StreamObserver<Message> responseObserver) {
Resource onOpen = resourceMap.get(MessageConstants.ON_OPEN_RESOURCE);
List<ParamDetail> paramDetails = onOpen.getParamDetails();
BValue[] signatureParams = new BValue[paramDetails.size()];
signatureParams[0] = getConnectionParameter(onOpen, responseObserver);
CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, Boolean.FALSE);
Executor.submit(onOpen, callback, null, null, signatureParams);
return new StreamObserver<Message>() {
@Override
public void onNext(Message value) {
Resource onMessage = resourceMap.get(MessageConstants.ON_MESSAGE_RESOURCE);
List<ParamDetail> paramDetails = onMessage.getParamDetails();
BValue[] signatureParams = new BValue[paramDetails.size()];
signatureParams[0] = getConnectionParameter(onMessage, responseObserver);
BValue requestParam = getRequestParameter(onMessage, value);
if (requestParam != null) {
signatureParams[1] = requestParam;
}
CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, Boolean.FALSE);
Executor.submit(onMessage, callback, null, null, signatureParams);
}
@Override
public void onError(Throwable t) {
Resource onError = resourceMap.get(MessageConstants.ON_ERROR_RESOURCE);
if (onError == null) {
String message = "Error in listener service definition. onError resource does not exists";
LOG.error(message);
throw new RuntimeException(message);
}
List<ParamDetail> paramDetails = onError.getParamDetails();
BValue[] signatureParams = new BValue[paramDetails.size()];
signatureParams[0] = getConnectionParameter(onError, responseObserver);
if (paramDetails.size() != 2) {
String message = "Error in onError resource definition. It must have two input params, but have " + paramDetails.size();
LOG.error(message);
throw new RuntimeException(message);
}
BType errorType = paramDetails.get(1).getVarType();
BStruct errorStruct = MessageUtils.getConnectorError((BStructType) errorType, t);
signatureParams[1] = errorStruct;
CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, Boolean.FALSE);
Executor.submit(onError, callback, null, null, signatureParams);
}
@Override
public void onCompleted() {
Resource onCompleted = resourceMap.get(MessageConstants.ON_COMPLETE_RESOURCE);
if (onCompleted == null) {
String message = "Error in listener service definition. onError resource does not exists";
LOG.error(message);
throw new RuntimeException(message);
}
List<ParamDetail> paramDetails = onCompleted.getParamDetails();
BValue[] signatureParams = new BValue[paramDetails.size()];
signatureParams[0] = getConnectionParameter(onCompleted, responseObserver);
CallableUnitCallback callback = new GrpcCallableUnitCallBack(responseObserver, isEmptyResponse());
Executor.submit(onCompleted, callback, null, null, signatureParams);
}
};
}
use of org.ballerinalang.connector.api.ParamDetail in project ballerina by ballerina-lang.
the class ResourceImpl method getParamDetails.
@Override
public List<ParamDetail> getParamDetails() {
LocalVariableAttributeInfo attributeInfo = (LocalVariableAttributeInfo) resourceInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
List<ParamDetail> paramDetails = new ArrayList<>();
for (LocalVariableInfo variableInfo : attributeInfo.getLocalVariableInfoEntries()) {
paramDetails.add(new ParamDetail(variableInfo.getVariableType(), variableInfo.getVariableName()));
}
return paramDetails;
}
use of org.ballerinalang.connector.api.ParamDetail in project ballerina by ballerina-lang.
the class SignatureParams method validatePathParam.
private void validatePathParam(List<ParamDetail> paramDetails) {
for (ParamDetail param : paramDetails) {
int varTag = param.getVarType().getTag();
if (varTag != TypeTags.STRING_TAG && varTag != TypeTags.INT_TAG && varTag != TypeTags.BOOLEAN_TAG && varTag != TypeTags.FLOAT_TAG) {
throw new BallerinaConnectorException("incompatible resource signature parameter type");
}
paramCount++;
}
this.pathParams = paramDetails;
}
use of org.ballerinalang.connector.api.ParamDetail in project ballerina by ballerina-lang.
the class WebSocketDispatcher method dispatchBinaryMessage.
public static void dispatchBinaryMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketBinaryMessage binaryMessage) {
WebSocketService wsService = connectionInfo.getService();
Resource onBinaryMessageResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_BINARY_MESSAGE);
if (onBinaryMessageResource == null) {
return;
}
List<ParamDetail> paramDetails = onBinaryMessageResource.getParamDetails();
BValue[] bValues = new BValue[paramDetails.size()];
bValues[0] = connectionInfo.getWsConnection();
BStruct wsBinaryFrame = wsService.createBinaryFrameStruct();
byte[] data = binaryMessage.getByteArray();
wsBinaryFrame.setBlobField(0, data);
if (binaryMessage.isFinalFragment()) {
wsBinaryFrame.setBooleanField(0, 1);
} else {
wsBinaryFrame.setBooleanField(0, 0);
}
bValues[1] = wsBinaryFrame;
// TODO handle BallerinaConnectorException
Executor.submit(onBinaryMessageResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
use of org.ballerinalang.connector.api.ParamDetail in project ballerina by ballerina-lang.
the class WebSocketDispatcher method dispatchPongMessage.
private static void dispatchPongMessage(WebSocketOpenConnectionInfo connectionInfo, WebSocketControlMessage controlMessage) {
WebSocketService wsService = connectionInfo.getService();
Resource onPongMessageResource = wsService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_PONG);
if (onPongMessageResource == null) {
return;
}
List<ParamDetail> paramDetails = onPongMessageResource.getParamDetails();
BValue[] bValues = new BValue[paramDetails.size()];
bValues[0] = connectionInfo.getWsConnection();
BStruct wsPongFrame = wsService.createPongFrameStruct();
byte[] data = controlMessage.getByteArray();
wsPongFrame.setBlobField(0, data);
bValues[1] = wsPongFrame;
// TODO handle BallerinaConnectorException
Executor.submit(onPongMessageResource, new WebSocketEmptyCallableUnitCallback(), null, null, bValues);
}
Aggregations