Search in sources :

Example 6 with Service

use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.

the class ServerConnectorRegistry method registerService.

/**
 * This method is used to register service to relevant server connector implementation.
 *
 * @param serviceInfo to be registered.
 */
public void registerService(ServiceInfo serviceInfo) {
    if (!serverConnectorMap.containsKey(serviceInfo.getEndpointName())) {
        throw BLangExceptionHelper.getRuntimeException(RuntimeErrors.INVALID_SERVICE_PROTOCOL, serviceInfo.getEndpointName());
    }
    Service service = buildService(serviceInfo);
    serverConnectorMap.get(serviceInfo.getEndpointName()).serviceRegistered(service);
}
Also used : Service(org.ballerinalang.connector.api.Service)

Example 7 with Service

use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.

the class RegisterWebSubSubscriberServiceEndpoint method execute.

@Override
public void execute(Context context) {
    Service service = BLangConnectorSPIUtil.getServiceRegistered(context);
    Struct subscriberServiceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
    Struct serviceEndpoint = ConnectorSPIModelHelper.createStruct((BStruct) ((BStruct) (subscriberServiceEndpoint.getVMValue())).getRefField(1));
    WebSubServicesRegistry webSubServicesRegistry = (WebSubServicesRegistry) serviceEndpoint.getNativeData(WebSubSubscriberConstants.WEBSUB_SERVICE_REGISTRY);
    webSubServicesRegistry.registerWebSubSubscriberService(service);
    context.setReturnValues();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) WebSubServicesRegistry(org.ballerinalang.net.websub.WebSubServicesRegistry) Service(org.ballerinalang.connector.api.Service) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 8 with Service

use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.

the class InitEndpoint method execute.

@Override
public void execute(Context context) {
    Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
    Struct clientEndpointConfig = clientEndpoint.getStructField(HttpConstants.CLIENT_ENDPOINT_CONFIG);
    String remoteUrl = clientEndpointConfig.getStringField(WebSocketConstants.CLIENT_URL_CONFIG);
    Value clientServiceType = clientEndpointConfig.getTypeField(WebSocketConstants.CLIENT_SERVICE_CONFIG);
    Service service = BLangConnectorSPIUtil.getServiceFromType(context.getProgramFile(), clientServiceType);
    if (service == null) {
        throw new BallerinaConnectorException("Cannot find client service: " + clientServiceType);
    }
    if (WebSocketConstants.WEBSOCKET_CLIENT_ENDPOINT_NAME.equals(service.getEndpointName())) {
        WebSocketService wsService = new WebSocketService(service);
        // TODO: Fix this validation
        // WebSocketServiceValidator.validateServiceEndpoint(wsService);
        WsClientConnectorConfig clientConnectorConfig = new WsClientConnectorConfig(remoteUrl);
        Value[] subProtocolValues = clientEndpointConfig.getArrayField(WebSocketConstants.CLIENT_SUBPROTOCOLS_CONFIG);
        if (subProtocolValues != null) {
            clientConnectorConfig.setSubProtocols(Arrays.stream(subProtocolValues).map(Value::getStringValue).toArray(String[]::new));
        }
        Map<String, Value> headerValues = clientEndpointConfig.getMapField(WebSocketConstants.CLIENT_CUSTOMHEADERS_CONFIG);
        if (headerValues != null) {
            clientConnectorConfig.addHeaders(getCustomHeaders(headerValues));
        }
        long idleTimeoutInSeconds = clientEndpointConfig.getIntField(WebSocketConstants.CLIENT_IDLETIMOUT_CONFIG);
        if (idleTimeoutInSeconds > 0) {
            clientConnectorConfig.setIdleTimeoutInMillis((int) (idleTimeoutInSeconds * 1000));
        }
        clientEndpointConfig.addNativeData(WebSocketConstants.CLIENT_SERVICE_CONFIG, wsService);
        clientEndpointConfig.addNativeData(WebSocketConstants.CLIENT_CONNECTOR_CONFIGS, clientConnectorConfig);
    } else {
        throw new BallerinaConnectorException("Incorrect endpoint: " + service.getEndpointName());
    }
    context.setReturnValues();
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) WsClientConnectorConfig(org.wso2.transport.http.netty.contract.websocket.WsClientConnectorConfig) Value(org.ballerinalang.connector.api.Value) Service(org.ballerinalang.connector.api.Service) WebSocketService(org.ballerinalang.net.http.WebSocketService) WebSocketService(org.ballerinalang.net.http.WebSocketService) Struct(org.ballerinalang.connector.api.Struct)

Example 9 with Service

use of org.ballerinalang.connector.api.Service in project ballerina by ballerina-lang.

the class Register method execute.

@Override
public void execute(Context context) {
    Service service = BLangConnectorSPIUtil.getServiceRegistered(context);
    Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
    HTTPServicesRegistry httpServicesRegistry = getHttpServicesRegistry(serviceEndpoint);
    WebSocketServicesRegistry webSocketServicesRegistry = getWebSocketServicesRegistry(serviceEndpoint);
    // TODO: In HTTP to WebSocket upgrade register WebSocket service in WebSocketServiceRegistry
    if (HttpConstants.HTTP_SERVICE_ENDPOINT_NAME.equals(service.getEndpointName())) {
        httpServicesRegistry.registerService(service);
    }
    if (WebSocketConstants.WEBSOCKET_ENDPOINT_NAME.equals(service.getEndpointName())) {
        WebSocketService webSocketService = new WebSocketService(service);
        webSocketServicesRegistry.registerService(webSocketService);
    }
    if (!isConnectorStarted(serviceEndpoint)) {
        startServerConnector(serviceEndpoint, httpServicesRegistry, webSocketServicesRegistry);
    }
    context.setReturnValues();
}
Also used : HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) Service(org.ballerinalang.connector.api.Service) WebSocketService(org.ballerinalang.net.http.WebSocketService) WebSocketService(org.ballerinalang.net.http.WebSocketService) Struct(org.ballerinalang.connector.api.Struct)

Aggregations

Service (org.ballerinalang.connector.api.Service)9 Struct (org.ballerinalang.connector.api.Struct)4 BStruct (org.ballerinalang.model.values.BStruct)4 WebSocketService (org.ballerinalang.net.http.WebSocketService)3 MethodDescriptor (io.grpc.MethodDescriptor)2 BTypeDescValue (org.ballerinalang.model.values.BTypeDescValue)2 Message (org.ballerinalang.net.grpc.Message)2 GrpcClientException (org.ballerinalang.net.grpc.exception.GrpcClientException)2 DefaultStreamObserver (org.ballerinalang.net.grpc.stubs.DefaultStreamObserver)2 GrpcNonBlockingStub (org.ballerinalang.net.grpc.stubs.GrpcNonBlockingStub)2 HTTPServicesRegistry (org.ballerinalang.net.http.HTTPServicesRegistry)2 WebSocketServicesRegistry (org.ballerinalang.net.http.WebSocketServicesRegistry)2 Annotation (org.ballerinalang.connector.api.Annotation)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 Value (org.ballerinalang.connector.api.Value)1 BString (org.ballerinalang.model.values.BString)1 BValue (org.ballerinalang.model.values.BValue)1 GrpcServicesBuilder.registerService (org.ballerinalang.net.grpc.GrpcServicesBuilder.registerService)1 GrpcServerException (org.ballerinalang.net.grpc.exception.GrpcServerException)1 WebSubServicesRegistry (org.ballerinalang.net.websub.WebSubServicesRegistry)1