Commit 3d55c09b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Refactored to create acceptors and start acceptors.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8373 b35dd754-fafc-0310-a699-88a17e54d16e
parent cee7861f
...@@ -74,10 +74,27 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -74,10 +74,27 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
ports = new ArrayList<ServerPort>(4); ports = new ArrayList<ServerPort>(4);
} }
private synchronized void createSocket() { private synchronized void createListeners() {
if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) { if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) {
return; return;
} }
// Create the port listener for s2s communication
createServerListener(localIPAddress);
// Create the port listener for Connections Multiplexers
createConnectionManagerListener();
// Create the port listener for external components
createComponentListener(localIPAddress);
// Create the port listener for clients
createClientListeners();
// Create the port listener for secured clients
createClientSSLListeners();
}
private synchronized void startListeners() {
if (isSocketStarted || sessionManager == null || deliverer == null || router == null || serverName == null) {
return;
}
// Check if plugins have been loaded // Check if plugins have been loaded
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager(); PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
if (!pluginManager.isExecuted()) { if (!pluginManager.isExecuted()) {
...@@ -86,7 +103,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -86,7 +103,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Stop listening for plugin events // Stop listening for plugin events
XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this); XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this);
// Start listeners // Start listeners
createSocket(); startListeners();
} }
}); });
return; return;
...@@ -104,11 +121,11 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -104,11 +121,11 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
// Start the port listener for s2s communication // Start the port listener for s2s communication
startServerListener(localIPAddress); startServerListener();
// Start the port listener for Connections Multiplexers // Start the port listener for Connections Multiplexers
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
// Start the port listener for external components // Start the port listener for external components
startComponentListener(localIPAddress); startComponentListener();
// Start the port listener for clients // Start the port listener for clients
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
// Start the port listener for secured clients // Start the port listener for secured clients
...@@ -117,7 +134,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -117,7 +134,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
startHTTPBindListeners(); startHTTPBindListeners();
} }
private void startServerListener(String localIPAddress) { private void createServerListener(String localIPAddress) {
// Start servers socket unless it's been disabled. // Start servers socket unless it's been disabled.
if (isServerListenerEnabled()) { if (isServerListenerEnabled()) {
int port = getServerListenerPort(); int port = getServerListenerPort();
...@@ -127,6 +144,20 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -127,6 +144,20 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
ports.add(serverSocketThread.getServerPort()); ports.add(serverSocketThread.getServerPort());
serverSocketThread.setDaemon(true); serverSocketThread.setDaemon(true);
serverSocketThread.setPriority(Thread.MAX_PRIORITY); serverSocketThread.setPriority(Thread.MAX_PRIORITY);
}
catch (Exception e) {
System.err.println("Error creating server listener on port " + port + ": " +
e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
}
}
}
private void startServerListener() {
// Start servers socket unless it's been disabled.
if (isServerListenerEnabled()) {
int port = getServerListenerPort();
try {
serverSocketThread.start(); serverSocketThread.start();
List<String> params = new ArrayList<String>(); List<String> params = new ArrayList<String>();
...@@ -149,11 +180,9 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -149,11 +180,9 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
private void startConnectionManagerListener(String localIPAddress) { private void createConnectionManagerListener() {
// Start multiplexers socket unless it's been disabled. // Start multiplexers socket unless it's been disabled.
if (isConnectionManagerListenerEnabled()) { if (isConnectionManagerListenerEnabled()) {
int port = getConnectionManagerListenerPort();
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
multiplexerSocketAcceptor = buildSocketAcceptor(); multiplexerSocketAcceptor = buildSocketAcceptor();
// Customize Executor that will be used by processors to process incoming stanzas // Customize Executor that will be used by processors to process incoming stanzas
...@@ -167,6 +196,14 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -167,6 +196,14 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Add the XMPP codec filter // Add the XMPP codec filter
multiplexerSocketAcceptor.getFilterChain().addFirst("xmpp", new ProtocolCodecFilter(new XMPPCodecFactory())); multiplexerSocketAcceptor.getFilterChain().addFirst("xmpp", new ProtocolCodecFilter(new XMPPCodecFactory()));
}
}
private void startConnectionManagerListener(String localIPAddress) {
// Start multiplexers socket unless it's been disabled.
if (isConnectionManagerListenerEnabled()) {
int port = getConnectionManagerListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
...@@ -206,7 +243,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -206,7 +243,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
private void startComponentListener(String localIPAddress) { private void createComponentListener(String localIPAddress) {
// Start components socket unless it's been disabled. // Start components socket unless it's been disabled.
if (isComponentListenerEnabled()) { if (isComponentListenerEnabled()) {
int port = getComponentListenerPort(); int port = getComponentListenerPort();
...@@ -216,6 +253,21 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -216,6 +253,21 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
ports.add(componentSocketThread.getServerPort()); ports.add(componentSocketThread.getServerPort());
componentSocketThread.setDaemon(true); componentSocketThread.setDaemon(true);
componentSocketThread.setPriority(Thread.MAX_PRIORITY); componentSocketThread.setPriority(Thread.MAX_PRIORITY);
}
catch (Exception e) {
System.err.println("Error starting component listener on port " + port + ": " +
e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.socket-setup"), e);
}
}
}
private void startComponentListener() {
// Start components socket unless it's been disabled.
if (isComponentListenerEnabled()) {
int port = getComponentListenerPort();
try {
componentSocketThread.start(); componentSocketThread.start();
List<String> params = new ArrayList<String>(); List<String> params = new ArrayList<String>();
...@@ -238,10 +290,9 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -238,10 +290,9 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
private void startClientListeners(String localIPAddress) { private void createClientListeners() {
// Start clients plain socket unless it's been disabled. // Start clients plain socket unless it's been disabled.
if (isClientListenerEnabled()) { if (isClientListenerEnabled()) {
int port = getClientListenerPort();
// Create SocketAcceptor with correct number of processors // Create SocketAcceptor with correct number of processors
socketAcceptor = buildSocketAcceptor(); socketAcceptor = buildSocketAcceptor();
// Customize Executor that will be used by processors to process incoming stanzas // Customize Executor that will be used by processors to process incoming stanzas
...@@ -255,7 +306,13 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -255,7 +306,13 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
socketAcceptor.getDefaultConfig().setThreadModel(threadModel); socketAcceptor.getDefaultConfig().setThreadModel(threadModel);
// Add the XMPP codec filter // Add the XMPP codec filter
socketAcceptor.getFilterChain().addFirst("xmpp", new ProtocolCodecFilter(new XMPPCodecFactory())); socketAcceptor.getFilterChain().addFirst("xmpp", new ProtocolCodecFilter(new XMPPCodecFactory()));
}
}
private void startClientListeners(String localIPAddress) {
// Start clients plain socket unless it's been disabled.
if (isClientListenerEnabled()) {
int port = getClientListenerPort();
try { try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
...@@ -296,7 +353,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -296,7 +353,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
private void startClientSSLListeners(String localIPAddress) { private void createClientSSLListeners() {
// Start clients SSL unless it's been disabled. // Start clients SSL unless it's been disabled.
if (isClientSSLListenerEnabled()) { if (isClientSSLListenerEnabled()) {
int port = getClientSSLListenerPort(); int port = getClientSSLListenerPort();
...@@ -347,6 +404,20 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -347,6 +404,20 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
sslSocketAcceptor.getFilterChain().addFirst("tls", new SSLFilter(sslContext)); sslSocketAcceptor.getFilterChain().addFirst("tls", new SSLFilter(sslContext));
}
catch (Exception e) {
System.err.println("Error starting SSL XMPP listener on port " + port + ": " +
e.getMessage());
Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e);
}
}
}
private void startClientSSLListeners(String localIPAddress) {
// Start clients SSL unless it's been disabled.
if (isClientSSLListenerEnabled()) {
int port = getClientSSLListenerPort();
try {
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null; InetAddress bindInterface = null;
...@@ -400,6 +471,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -400,6 +471,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
} }
stopClientSSLListeners(); stopClientSSLListeners();
createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
...@@ -449,6 +521,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -449,6 +521,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if (enabled) { if (enabled) {
JiveGlobals.setProperty("xmpp.socket.plain.active", "true"); JiveGlobals.setProperty("xmpp.socket.plain.active", "true");
// Start the port listener for clients // Start the port listener for clients
createClientListeners();
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
} }
else { else {
...@@ -470,6 +543,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -470,6 +543,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if (enabled) { if (enabled) {
JiveGlobals.setProperty("xmpp.socket.ssl.active", "true"); JiveGlobals.setProperty("xmpp.socket.ssl.active", "true");
// Start the port listener for secured clients // Start the port listener for secured clients
createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
else { else {
...@@ -497,7 +571,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -497,7 +571,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if (enabled) { if (enabled) {
JiveGlobals.setProperty("xmpp.component.socket.active", "true"); JiveGlobals.setProperty("xmpp.component.socket.active", "true");
// Start the port listener for external components // Start the port listener for external components
startComponentListener(localIPAddress); createComponentListener(localIPAddress);
startComponentListener();
} }
else { else {
JiveGlobals.setProperty("xmpp.component.socket.active", "false"); JiveGlobals.setProperty("xmpp.component.socket.active", "false");
...@@ -518,7 +593,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -518,7 +593,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if (enabled) { if (enabled) {
JiveGlobals.setProperty("xmpp.server.socket.active", "true"); JiveGlobals.setProperty("xmpp.server.socket.active", "true");
// Start the port listener for s2s communication // Start the port listener for s2s communication
startServerListener(localIPAddress); createServerListener(localIPAddress);
startServerListener();
} }
else { else {
JiveGlobals.setProperty("xmpp.server.socket.active", "false"); JiveGlobals.setProperty("xmpp.server.socket.active", "false");
...@@ -539,6 +615,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -539,6 +615,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if (enabled) { if (enabled) {
JiveGlobals.setProperty("xmpp.multiplex.socket.active", "true"); JiveGlobals.setProperty("xmpp.multiplex.socket.active", "true");
// Start the port listener for s2s communication // Start the port listener for s2s communication
createConnectionManagerListener();
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
} }
else { else {
...@@ -562,6 +639,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -562,6 +639,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
stopClientListeners(); stopClientListeners();
if (isClientListenerEnabled()) { if (isClientListenerEnabled()) {
// Start the port listener for clients // Start the port listener for clients
createClientListeners();
startClientListeners(localIPAddress); startClientListeners(localIPAddress);
} }
} }
...@@ -588,6 +666,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -588,6 +666,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
stopClientSSLListeners(); stopClientSSLListeners();
if (isClientSSLListenerEnabled()) { if (isClientSSLListenerEnabled()) {
// Start the port listener for secured clients // Start the port listener for secured clients
createClientSSLListeners();
startClientSSLListeners(localIPAddress); startClientSSLListeners(localIPAddress);
} }
} }
...@@ -606,7 +685,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -606,7 +685,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
stopComponentListener(); stopComponentListener();
if (isComponentListenerEnabled()) { if (isComponentListenerEnabled()) {
// Start the port listener for external components // Start the port listener for external components
startComponentListener(localIPAddress); createComponentListener(localIPAddress);
startComponentListener();
} }
} }
...@@ -624,7 +704,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -624,7 +704,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
stopServerListener(); stopServerListener();
if (isServerListenerEnabled()) { if (isServerListenerEnabled()) {
// Start the port listener for s2s communication // Start the port listener for s2s communication
startServerListener(localIPAddress); createServerListener(localIPAddress);
startServerListener();
} }
} }
...@@ -646,6 +727,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -646,6 +727,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
stopConnectionManagerListener(); stopConnectionManagerListener();
if (isConnectionManagerListenerEnabled()) { if (isConnectionManagerListenerEnabled()) {
// Start the port listener for connection managers // Start the port listener for connection managers
createConnectionManagerListener();
startConnectionManagerListener(localIPAddress); startConnectionManagerListener(localIPAddress);
} }
} }
...@@ -712,7 +794,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -712,7 +794,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
public void start() { public void start() {
super.start(); super.start();
serverName = server.getServerInfo().getName(); serverName = server.getServerInfo().getName();
createSocket(); createListeners();
startListeners();
SocketSendingTracker.getInstance().start(); SocketSendingTracker.getInstance().start();
CertificateManager.addListener(this); CertificateManager.addListener(this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment