InetSocketAddress socketAddress = request.getRemoteSocketAddress();
SCMPMessage message = request.getMessage();
String serviceName = message.getServiceName();
// lookup service and checks properness
StatefulService service = this.getStatefulService(serviceName);
String serverKey = serviceName + "_" + socketAddress.getHostName() + Constants.SLASH + socketAddress.getPort();
// controls that server not has been registered before for specific service
this.getServerByKeyAndValidateNotRegistered(serverKey);
int maxSessions = message.getHeaderInt(SCMPHeaderAttributeKey.MAX_SESSIONS);
int maxConnections = message.getHeaderInt(SCMPHeaderAttributeKey.MAX_CONNECTIONS);
int portNr = message.getHeaderInt(SCMPHeaderAttributeKey.PORT_NR);
boolean immediateConnect = message.getHeaderFlag(SCMPHeaderAttributeKey.IMMEDIATE_CONNECT);
int keepAliveIntervalSeconds = message.getHeaderInt(SCMPHeaderAttributeKey.KEEP_ALIVE_INTERVAL);
int checkRegistrationIntervalSeconds = message.getHeaderInt(SCMPHeaderAttributeKey.CHECK_REGISTRATION_INTERVAL);
String httpUrlFileQualifier = message.getHeader(SCMPHeaderAttributeKey.URL_PATH);
if (httpUrlFileQualifier == null) {
// httpUrlFileQualifier is an optional attribute
httpUrlFileQualifier = Constants.SLASH;
}
ResponderRegistry responderRegistry = AppContext.getResponderRegistry();
IResponder responder = responderRegistry.getCurrentResponder();
ListenerConfiguration listenerConfig = responder.getListenerConfig();
String connectionType = listenerConfig.getConnectionType();
RemoteNodeConfiguration remoteNodeConfiguration = new RemoteNodeConfiguration(ServerType.STATEFUL_SERVER, serverKey,
socketAddress.getHostName(), portNr, connectionType, keepAliveIntervalSeconds, checkRegistrationIntervalSeconds,
maxConnections, maxSessions, httpUrlFileQualifier);
// create new server
StatefulServer server = new StatefulServer(remoteNodeConfiguration, serviceName, socketAddress);
try {
if (immediateConnect) {
// server connections get connected immediately
server.immediateConnect();
}
} catch (Exception ex) {
LOGGER.error("immediate connect", ex);
HasFaultResponseException communicationException = new SCMPCommunicationException(SCMPError.CONNECTION_EXCEPTION,
"immediate connect to server=" + serverKey);
communicationException.setMessageType(getKey());
throw communicationException;
}
// add server to service
service.addServer(server);
// add service to server
server.setService(service);
// add server to server registry
this.serverRegistry.addServer(serverKey, server);