Skip to content

Commit

Permalink
Merge pull request ballerina-platform#4 from irunika/transport-refactor
Browse files Browse the repository at this point in the history
Issue Fixes
  • Loading branch information
shafreenAnfar authored Aug 17, 2017
2 parents c5b2d65 + 161f47b commit 72b1a06
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class BallerinaConnectorManager {
private Map<String, ServerConnector> startupDelayedServerConnectors = new HashMap<>();
private Map<String, org.wso2.carbon.transport.http.netty.contract.ServerConnector>
startupDelayedHTTPServerConnectors = new HashMap<>();
private Map<String, org.wso2.carbon.transport.http.netty.contract.ServerConnector>
startedHTTPServerConnectors = new HashMap<>();
private ServerBootstrapConfiguration serverBootstrapConfiguration;
private TransportsConfiguration trpConfig;
private CarbonMessageProcessor messageProcessor;
Expand All @@ -84,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);
}
}
Expand Down Expand Up @@ -147,10 +150,14 @@ public ServerConnector createServerConnector(String protocol, String id, Map<Str
return startupDelayedHTTPServerConnectors.get(id);
}
org.wso2.carbon.transport.http.netty.contract.ServerConnector serverConnector =
httpConnectorFactory.createServerConnector(serverBootstrapConfiguration, listenerConfig);
httpConnectorFactory.getServerConnector(serverBootstrapConfiguration, listenerConfig);
return serverConnector;
}

public org.wso2.carbon.transport.http.netty.contract.ServerConnector
getStartedHTTPServerConnector(String id) {
return startedHTTPServerConnectors.get(id);
}
/**
* Register the given server connector error handler instance with the manager. Protocol of the handler will be
* used with registering the handler.
Expand Down Expand Up @@ -263,6 +270,7 @@ public List<org.wso2.carbon.transport.http.netty.contract.ServerConnector> start
connectorFuture.setHTTPConnectorListener(new BallerinaHTTPConnectorListener());
connectorFuture.setWSConnectorListener(new BallerinaWebSocketConnectorListener());
startedConnectors.add(serverConnector);
startedHTTPServerConnectors.put(serverConnector.getConnectorID(), serverConnector);
}
startupDelayedServerConnectors.clear();
return startedConnectors;
Expand Down Expand Up @@ -295,6 +303,10 @@ public HttpClientConnector getHTTPHttpClientConnector() {
Map<String, Object> properties = HTTPMessageUtil.getTransportProperties(trpConfig);
SenderConfiguration senderConfiguration =
HTTPMessageUtil.getSenderConfiguration(trpConfig);
return httpConnectorFactory.createHttpClientConnector(properties, senderConfiguration);
return httpConnectorFactory.getHTTPClientConnector(properties, senderConfiguration);
}

public WebSocketClientConnector getWebSocketClientConnector(Map<String, Object> properties) {
return httpConnectorFactory.getWSClientConnector(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,8 @@ public void unregisterService(ServiceInfo service) {
if (servicesOnInterface.isEmpty()) {
servicesInfoMap.remove(listenerInterface);

// TODO: Add correct parameters
Map<String, String> parameters = new HashMap<>();
ServerConnector connector =
BallerinaConnectorManager.getInstance().
createHTTPServerConnector(listenerInterface, parameters);
BallerinaConnectorManager.getInstance().getStartedHTTPServerConnector(listenerInterface);
if (connector != null) {
connector.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> customHeaders = new HashMap<>();
Headers headers = carbonMessage.getHeaders();
headers.getAll().forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -79,8 +77,8 @@ public BValue execute(Context context) {
Map<String, Object> 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<String, String> customHeaders = new HashMap<>();
Session clientSession;
try {
Expand Down

0 comments on commit 72b1a06

Please sign in to comment.