Search in sources :

Example 1 with WebSocketServicesRegistry

use of org.ballerinalang.net.http.WebSocketServicesRegistry in project ballerina by ballerina-lang.

the class NonListeningRegister 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);
    }
    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)

Example 2 with WebSocketServicesRegistry

use of org.ballerinalang.net.http.WebSocketServicesRegistry in project ballerina by ballerina-lang.

the class InitEndpoint method execute.

@Override
public void execute(Context context) {
    try {
        Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
        // Creating server connector
        Struct serviceEndpointConfig = serviceEndpoint.getStructField(HttpConstants.SERVICE_ENDPOINT_CONFIG);
        ListenerConfiguration listenerConfiguration = getListerConfig(serviceEndpointConfig);
        ServerConnector httpServerConnector = HttpConnectionManager.getInstance().createHttpServerConnector(listenerConfiguration);
        serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVER_CONNECTOR, httpServerConnector);
        // Adding service registries to native data
        WebSocketServicesRegistry webSocketServicesRegistry = new WebSocketServicesRegistry();
        HTTPServicesRegistry httpServicesRegistry = new HTTPServicesRegistry(webSocketServicesRegistry);
        serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVICE_REGISTRY, httpServicesRegistry);
        serviceEndpoint.addNativeData(HttpConstants.WS_SERVICE_REGISTRY, webSocketServicesRegistry);
        // set filters
        setFilters(serviceEndpointConfig, serviceEndpoint);
        context.setReturnValues((BValue) null);
    } catch (Throwable throwable) {
        BStruct errorStruct = HttpUtil.getHttpConnectorError(context, throwable);
        context.setReturnValues(errorStruct);
    }
}
Also used : ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) BStruct(org.ballerinalang.model.values.BStruct) HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 3 with WebSocketServicesRegistry

use of org.ballerinalang.net.http.WebSocketServicesRegistry in project ballerina by ballerina-lang.

the class InitWebSubSubscriberServiceEndpoint method execute.

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

Example 4 with WebSocketServicesRegistry

use of org.ballerinalang.net.http.WebSocketServicesRegistry 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

Struct (org.ballerinalang.connector.api.Struct)4 WebSocketServicesRegistry (org.ballerinalang.net.http.WebSocketServicesRegistry)4 HTTPServicesRegistry (org.ballerinalang.net.http.HTTPServicesRegistry)3 Service (org.ballerinalang.connector.api.Service)2 BStruct (org.ballerinalang.model.values.BStruct)2 WebSocketService (org.ballerinalang.net.http.WebSocketService)2 WebSubServicesRegistry (org.ballerinalang.net.websub.WebSubServicesRegistry)1 ListenerConfiguration (org.wso2.transport.http.netty.config.ListenerConfiguration)1 ServerConnector (org.wso2.transport.http.netty.contract.ServerConnector)1