From 00fa0e6e85c7d4090970890dc843527cefb9118d Mon Sep 17 00:00:00 2001 From: irunika Date: Thu, 17 Aug 2017 14:32:47 +0530 Subject: [PATCH 1/2] Fix issue in unregister server connector. --- .../natives/connectors/BallerinaConnectorManager.java | 7 +++++++ .../services/dispatchers/http/HTTPServicesRegistry.java | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java b/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java index 60cf8707bfc0..f6d4c3cfbb0a 100644 --- a/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java +++ b/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java @@ -64,6 +64,8 @@ public class BallerinaConnectorManager { private Map startupDelayedServerConnectors = new HashMap<>(); private Map startupDelayedHTTPServerConnectors = new HashMap<>(); + private Map + startedHTTPServerConnectors = new HashMap<>(); private ServerBootstrapConfiguration serverBootstrapConfiguration; private TransportsConfiguration trpConfig; private CarbonMessageProcessor messageProcessor; @@ -151,6 +153,10 @@ public ServerConnector createServerConnector(String protocol, String id, Map start connectorFuture.setHTTPConnectorListener(new BallerinaHTTPConnectorListener()); connectorFuture.setWSConnectorListener(new BallerinaWebSocketConnectorListener()); startedConnectors.add(serverConnector); + startedHTTPServerConnectors.put(serverConnector.getConnectorID(), serverConnector); } startupDelayedServerConnectors.clear(); return startedConnectors; diff --git a/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/http/HTTPServicesRegistry.java b/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/http/HTTPServicesRegistry.java index 3e77e347370c..4b9386342d9c 100644 --- a/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/http/HTTPServicesRegistry.java +++ b/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/http/HTTPServicesRegistry.java @@ -289,11 +289,8 @@ public void unregisterService(ServiceInfo service) { if (servicesOnInterface.isEmpty()) { servicesInfoMap.remove(listenerInterface); - // TODO: Add correct parameters - Map parameters = new HashMap<>(); ServerConnector connector = - BallerinaConnectorManager.getInstance(). - createHTTPServerConnector(listenerInterface, parameters); + BallerinaConnectorManager.getInstance().getStartedHTTPServerConnector(listenerInterface); if (connector != null) { connector.stop(); } From 161f47bb99f953a82e4aa701366aec3b6ea9357b Mon Sep 17 00:00:00 2001 From: irunika Date: Thu, 17 Aug 2017 15:25:18 +0530 Subject: [PATCH 2/2] Add new methods to Ballerina connector manager --- .../natives/connectors/BallerinaConnectorManager.java | 11 ++++++++--- .../dispatchers/ws/WebSocketConnectionManager.java | 5 +++-- .../org/ballerinalang/nativeimpl/actions/ws/Init.java | 8 +++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java b/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java index 9e8db8acc2e1..8c333daaca69 100644 --- a/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java +++ b/modules/ballerina-core/src/main/java/org/ballerinalang/natives/connectors/BallerinaConnectorManager.java @@ -37,6 +37,7 @@ import org.wso2.carbon.transport.http.netty.contract.HttpClientConnector; import org.wso2.carbon.transport.http.netty.contract.HttpWsConnectorFactory; import org.wso2.carbon.transport.http.netty.contract.ServerConnectorFuture; +import org.wso2.carbon.transport.http.netty.contract.websocket.WebSocketClientConnector; import org.wso2.carbon.transport.http.netty.contractimpl.HttpWsConnectorFactoryImpl; import org.wso2.carbon.transport.http.netty.listener.ServerBootstrapConfiguration; import org.wso2.carbon.transport.http.netty.message.HTTPMessageUtil; @@ -86,7 +87,7 @@ private BallerinaConnectorManager() { org.wso2.carbon.transport.http.netty.contract.ServerConnector serverConnector; for (ListenerConfiguration listenerConfiguration : listenerConfigurationSet) { serverConnector = httpConnectorFactory - .createServerConnector(serverBootstrapConfiguration, listenerConfiguration); + .getServerConnector(serverBootstrapConfiguration, listenerConfiguration); addStartupDelayedHTTPServerConnector(listenerConfiguration.getId(), serverConnector); } } @@ -149,7 +150,7 @@ public ServerConnector createServerConnector(String protocol, String id, Map properties = HTTPMessageUtil.getTransportProperties(trpConfig); SenderConfiguration senderConfiguration = HTTPMessageUtil.getSenderConfiguration(trpConfig); - return httpConnectorFactory.createHttpClientConnector(properties, senderConfiguration); + return httpConnectorFactory.getHTTPClientConnector(properties, senderConfiguration); + } + + public WebSocketClientConnector getWebSocketClientConnector(Map properties) { + return httpConnectorFactory.getWSClientConnector(properties); } } diff --git a/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/ws/WebSocketConnectionManager.java b/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/ws/WebSocketConnectionManager.java index 63023a8c2874..957bf68bb0da 100644 --- a/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/ws/WebSocketConnectionManager.java +++ b/modules/ballerina-core/src/main/java/org/ballerinalang/services/dispatchers/ws/WebSocketConnectionManager.java @@ -19,6 +19,7 @@ package org.ballerinalang.services.dispatchers.ws; import org.ballerinalang.model.values.BConnector; +import org.ballerinalang.natives.connectors.BallerinaConnectorManager; import org.ballerinalang.util.codegen.ServiceInfo; import org.ballerinalang.util.exceptions.BallerinaException; import org.wso2.carbon.messaging.CarbonMessage; @@ -341,8 +342,8 @@ private Session initializeClientConnection(BConnector bConnector, CarbonMessage properties.put(Constants.REMOTE_ADDRESS, remoteUrl); properties.put(Constants.TO, clientServiceName); properties.put(Constants.WEBSOCKET_MESSAGE, websocketMessage); - WebSocketClientConnector clientConnector = connectorFactory.createWsClientConnector(properties); - + WebSocketClientConnector clientConnector = BallerinaConnectorManager.getInstance(). + getWebSocketClientConnector(properties); Map customHeaders = new HashMap<>(); Headers headers = carbonMessage.getHeaders(); headers.getAll().forEach( diff --git a/modules/ballerina-native/src/main/java/org/ballerinalang/nativeimpl/actions/ws/Init.java b/modules/ballerina-native/src/main/java/org/ballerinalang/nativeimpl/actions/ws/Init.java index 6389b589295c..27d8798b7c87 100644 --- a/modules/ballerina-native/src/main/java/org/ballerinalang/nativeimpl/actions/ws/Init.java +++ b/modules/ballerina-native/src/main/java/org/ballerinalang/nativeimpl/actions/ws/Init.java @@ -27,6 +27,7 @@ import org.ballerinalang.natives.annotations.BallerinaAction; import org.ballerinalang.natives.annotations.BallerinaAnnotation; import org.ballerinalang.natives.connectors.AbstractNativeAction; +import org.ballerinalang.natives.connectors.BallerinaConnectorManager; import org.ballerinalang.services.dispatchers.ws.BallerinaWebSocketConnectorListener; import org.ballerinalang.services.dispatchers.ws.Constants; import org.ballerinalang.services.dispatchers.ws.WebSocketConnectionManager; @@ -35,9 +36,7 @@ import org.ballerinalang.util.exceptions.BallerinaException; import org.osgi.service.component.annotations.Component; import org.wso2.carbon.messaging.exceptions.ClientConnectorException; -import org.wso2.carbon.transport.http.netty.contract.HttpWsConnectorFactory; import org.wso2.carbon.transport.http.netty.contract.websocket.WebSocketClientConnector; -import org.wso2.carbon.transport.http.netty.contractimpl.HttpWsConnectorFactoryImpl; import java.util.HashMap; import java.util.Map; @@ -69,7 +68,6 @@ public class Init extends AbstractWebSocketAction { @Override public BValue execute(Context context) { - HttpWsConnectorFactory httpConnectorFactory = new HttpWsConnectorFactoryImpl(); BConnector bconnector = (BConnector) getRefArgument(context, 0); String remoteUrl = bconnector.getStringField(0); String clientServiceName = bconnector.getStringField(1); @@ -79,8 +77,8 @@ public BValue execute(Context context) { Map properties = new HashMap<>(); properties.put(Constants.REMOTE_ADDRESS, remoteUrl); properties.put(Constants.TO, clientServiceName); - WebSocketClientConnector clientConnector = httpConnectorFactory.createWsClientConnector(properties); - + WebSocketClientConnector clientConnector = BallerinaConnectorManager.getInstance(). + getWebSocketClientConnector(properties); Map customHeaders = new HashMap<>(); Session clientSession; try {