/** * Get the ID of the connection. * * @since 0.966 */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "stop", receiver = @Receiver(type = TypeKind.OBJECT, structType = MOCK_LISTENER_ENDPOINT, structPackage = "ballerina.http"), isPublic = true ) public class NonListeningStop extends org.ballerinalang.net.http.serviceendpoint.Stop { }
private NativeElementCodeDef functionToDef(BallerinaFunction func, Element element) { NativeFunctionCodeDef def = new NativeFunctionCodeDef(); def.org = func.orgName(); def.pkg = func.packageName(); if (func.receiver().type() == TypeKind.OBJECT) { def.name = func.receiver().structType() + "." + func.functionName(); } else { def.name = func.functionName(); } def.className = this.extractClassName(element); Arrays.stream(func.args()).forEach(e -> def.argTypes.add(e.type())); Arrays.stream(func.returnType()).forEach(e -> def.retTypes.add(e.type())); return def; }
/** * This function which implements the finishSpan method for tracing. */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "finishSpan", receiver = @Receiver(type = TypeKind.STRUCT, structType = "Span", structPackage = "ballerina.observe"), isPublic = true ) public class FinishSpan extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BStruct span = (BStruct) context.getRefArgument(0); String spanId = span.getStringField(0); OpenTracerBallerinaWrapper.getInstance().finishSpan(spanId); } }
/** * Get the ID of the connection. * * @since 0.966 */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "start", receiver = @Receiver(type = TypeKind.OBJECT, structType = HTTP_LISTENER_ENDPOINT, structPackage = "ballerina/http"), isPublic = true ) public class Start extends AbstractHttpNativeFunction { @Override public void execute(Context context) { context.setReturnValues(); } }
/** * Get the ID of the connection. * * @since 0.966 */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "start", receiver = @Receiver(type = TypeKind.OBJECT, structType = MOCK_LISTENER_ENDPOINT, structPackage = "ballerina.http"), isPublic = true ) public class NonListeningStart extends org.ballerinalang.net.http.serviceendpoint.Start { @Override public void execute(Context context) { // don't want to open a port to listen, hence nothing to do } }
/** * This is the native reset function implementation of the Counter object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "reset", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.COUNTER, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH), isPublic = true ) public class CounterReset extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap bStruct = (BMap) context.getRefArgument(0); Counter counter = (Counter) bStruct.getNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY); counter.reset(); } }
/** * Get the ID of the connection. * * @since 0.966 */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "stop", receiver = @Receiver(type = TypeKind.OBJECT, structType = HTTP_LISTENER_ENDPOINT, structPackage = "ballerina/http"), isPublic = true ) public class Stop extends AbstractHttpNativeFunction { @Override public void execute(Context context) { Struct serverEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context); getServerConnector(serverEndpoint).stop(); serverEndpoint.addNativeData(HttpConstants.CONNECTOR_STARTED, false); resetRegistry(serverEndpoint); context.setReturnValues(); } }
/** * {@code RemoveAllHeaders} is the ballerina extern function to remove all headers of a Push Promise. */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "removeAllHeaders", receiver = @Receiver(type = TypeKind.OBJECT, structType = "PushPromise", structPackage = "ballerina/http"), isPublic = true ) public class RemoveAllHeaders extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap<String, BValue> pushPromiseStruct = (BMap<String, BValue>) context.getRefArgument(0); Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct)); http2PushPromise.removeAllHeaders(); context.setReturnValues(); } }
/** * Extern function to stop gRPC server instance. * * @since 1.0.0 */ @BallerinaFunction( orgName = ORG_NAME, packageName = PROTOCOL_PACKAGE_GRPC, functionName = "stop", receiver = @Receiver(type = TypeKind.OBJECT, structType = LISTENER, structPackage = PROTOCOL_STRUCT_PACKAGE_GRPC), isPublic = true ) public class Stop extends AbstractGrpcNativeFunction { @Override public void execute(Context context) { Struct serverEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context); getServerConnector(serverEndpoint).stop(); context.setReturnValues(); } }
/** * This is the native register function implementation of the Counter object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "unregister", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.GAUGE, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH), isPublic = true ) public class GaugeUnregister extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap bStruct = (BMap) context.getRefArgument(0); Gauge gauge = (Gauge) bStruct.getNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY); gauge.unregister(); } }
/** * This is the native register function implementation of the Counter object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "unregister", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.COUNTER, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH), isPublic = true ) public class CounterUnregister extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap bStruct = (BMap) context.getRefArgument(0); Counter counter = (Counter) bStruct.getNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY); counter.unregister(); } }
/** * Start server connector. */ @BallerinaFunction( orgName = "ballerina", packageName = "file", functionName = "start", receiver = @Receiver(type = TypeKind.OBJECT, structType = "Listener", structPackage = "ballerina/file"), isPublic = true ) public class Start extends BlockingNativeCallableUnit { @Override public void execute(Context context) { Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context); LocalFileSystemServerConnector serverConnector = (LocalFileSystemServerConnector) serviceEndpoint .getNativeData(DirectoryListenerConstants.FS_SERVER_CONNECTOR); try { serverConnector.start(); } catch (LocalFileSystemServerConnectorException e) { context.setReturnValues(FileUtils.createError(context, e.getMessage())); return; } context.setReturnValues(); } }
/** * This is the native initialize function that's getting called when instantiating the Counter object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "initialize", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.COUNTER, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH) ) public class CounterInitialize extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap<String, BValue> bStruct = (BMap<String, BValue>) context.getRefArgument(0); Counter counter = Counter.builder(bStruct.get(ObserveNativeImplConstants.NAME_FIELD).stringValue()) .description(bStruct.get(ObserveNativeImplConstants.DESCRIPTION_FIELD).stringValue()) .tags(Utils.toStringMap((BMap) bStruct.get(ObserveNativeImplConstants.TAGS_FIELD))) .build(); bStruct.addNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY, counter); } }
/** * This is the native register function implementation of the Counter object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "register", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.COUNTER, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH), isPublic = true ) public class CounterRegister extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap bStruct = (BMap) context.getRefArgument(0); Counter counter = (Counter) bStruct.getNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY); Counter registeredCounter = counter.register(); bStruct.addNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY, registeredCounter); } }
/** * {@code RejectPromise} action can be used to reject a push promise. */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "rejectPromise", receiver = @Receiver(type = TypeKind.OBJECT, structType = HttpConstants.HTTP_CALLER, structPackage = "ballerina/http") ) public class RejectPromise extends AbstractHTTPAction { @Override public void execute(Context context, CallableUnitCallback callback) { BMap<String, BValue> pushPromiseStruct = (BMap<String, BValue>) context.getRefArgument(1); Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, null); if (http2PushPromise == null) { throw new BallerinaException("invalid push promise"); } BMap<String, BValue> bConnector = (BMap<String, BValue>) context.getRefArgument(0); HttpClientConnector clientConnector = (HttpClientConnector) ((BMap<String, BValue>) bConnector.values()[0]) .getNativeData(HttpConstants.HTTP_CLIENT); clientConnector.rejectPushResponse(http2PushPromise); callback.notifySuccess(); } }
/** * This is the register function native implementation of the Gauge object. * * @since 0.980.0 */ @BallerinaFunction( orgName = "ballerina", packageName = "observe", functionName = "register", receiver = @Receiver(type = TypeKind.OBJECT, structType = ObserveNativeImplConstants.GAUGE, structPackage = ObserveNativeImplConstants.OBSERVE_PACKAGE_PATH), isPublic = true ) public class GaugeRegister extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap bStruct = (BMap) context.getRefArgument(0); Gauge gauge = (Gauge) bStruct.getNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY); Gauge registeredCounter = gauge.register(); bStruct.addNativeData(ObserveNativeImplConstants.METRIC_NATIVE_INSTANCE_KEY, registeredCounter); } }
/** * Get the ID of the connection. * * @since 0.970 */ @BallerinaFunction( orgName = "ballerina", packageName = "jms", functionName = "start", receiver = @Receiver(type = TypeKind.OBJECT, structType = "Connection", structPackage = "ballerina/jms"), isPublic = true ) public class Start implements NativeCallableUnit { @Override public void execute(Context context, CallableUnitCallback callableUnitCallback) { Struct connectionBObject = BallerinaAdapter.getReceiverObject(context); Connection connection = BallerinaAdapter.getNativeObject(connectionBObject, Constants.JMS_CONNECTION, Connection.class, context); try { connection.start(); } catch (JMSException e) { BallerinaAdapter.throwBallerinaException("Error occurred while starting connection.", context, e); } } @Override public boolean isBlocking() { return true; } }
/** * Set custom Header to the Message. * * @since 1.0.0 */ @BallerinaFunction( orgName = ORG_NAME, packageName = PROTOCOL_PACKAGE_GRPC, functionName = "removeAll", receiver = @Receiver(type = TypeKind.OBJECT, structType = "Headers", structPackage = PROTOCOL_STRUCT_PACKAGE_GRPC), isPublic = true ) public class RemoveAll extends BlockingNativeCallableUnit { @Override public void execute(Context context) { BMap<String, BValue> headerValues = (BMap<String, BValue>) context.getRefArgument(0); HttpHeaders headers = headerValues != null ? (HttpHeaders) headerValues.getNativeData(MESSAGE_HEADERS) : null; if (headers != null) { headers.clear(); } context.setReturnValues(); } }
/** * Extern function invalidate session. * * @since 0.89 */ @BallerinaFunction( orgName = "ballerina", packageName = "http", functionName = "invalidate", receiver = @Receiver(type = TypeKind.OBJECT, structType = "Session", structPackage = "ballerina/http"), isPublic = true ) public class Invalidate extends BlockingNativeCallableUnit { @Override public void execute(Context context) { try { BMap<String, BValue> sessionStruct = ((BMap<String, BValue>) context.getRefArgument(0)); Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION); if (session != null && session.isValid()) { session.invalidate(); } else { throw new IllegalStateException("Failed to invalidate session: No such session in progress"); } } catch (IllegalStateException e) { throw new BallerinaException(e.getMessage(), e); } context.setReturnValues(); } }
/** * Get the ID of the connection. * * @since 0.970 */ @BallerinaFunction( orgName = "ballerina", packageName = "jms", functionName = "stop", receiver = @Receiver(type = TypeKind.OBJECT, structType = "Connection", structPackage = "ballerina/jms"), isPublic = true ) public class Stop implements NativeCallableUnit { @Override public void execute(Context context, CallableUnitCallback callableUnitCallback) { Struct connectionBObject = BallerinaAdapter.getReceiverObject(context); Connection connection = BallerinaAdapter.getNativeObject(connectionBObject, Constants.JMS_CONNECTION, Connection.class, context); try { connection.stop(); } catch (JMSException e) { BallerinaAdapter.throwBallerinaException("Error occurred while stopping the connection.", context, e); } } @Override public boolean isBlocking() { return true; } }