Commit 342061ef authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for server listeners. JM-625

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3694 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0e8c47ff
...@@ -50,6 +50,7 @@ import java.sql.PreparedStatement; ...@@ -50,6 +50,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* The main XMPP server that will load, initialize and start all the server's * The main XMPP server that will load, initialize and start all the server's
...@@ -95,6 +96,11 @@ public class XMPPServer { ...@@ -95,6 +96,11 @@ public class XMPPServer {
*/ */
private Map<Class, Module> modules = new HashMap<Class, Module>(); private Map<Class, Module> modules = new HashMap<Class, Module>();
/**
* Listeners that will be notified when the server has started or is about to be stopped.
*/
private List<XMPPServerListener> listeners = new CopyOnWriteArrayList<XMPPServerListener>();
/** /**
* Location of the home directory. All configuration files should be * Location of the home directory. All configuration files should be
* located here. * located here.
...@@ -250,6 +256,26 @@ public class XMPPServer { ...@@ -250,6 +256,26 @@ public class XMPPServer {
return admins; return admins;
} }
/**
* Adds a new server listener that will be notified when the server has been started
* or is about to be stopped.
*
* @param listener the new server listener to add.
*/
public void addServerListener(XMPPServerListener listener) {
listeners.add(listener);
}
/**
* Removes a server listener that was being notified when the server was being started
* or was about to be stopped.
*
* @param listener the server listener to remove.
*/
public void removeServerListener(XMPPServerListener listener) {
listeners.remove(listener);
}
private void initialize() throws FileNotFoundException { private void initialize() throws FileNotFoundException {
locateWildfire(); locateWildfire();
...@@ -362,6 +388,10 @@ public class XMPPServer { ...@@ -362,6 +388,10 @@ public class XMPPServer {
startDate = new Date(); startDate = new Date();
stopDate = null; stopDate = null;
// Notify server listeners that the server has been started
for (XMPPServerListener listener : listeners) {
listener.serverStarted();
}
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -753,6 +783,10 @@ public class XMPPServer { ...@@ -753,6 +783,10 @@ public class XMPPServer {
* Makes a best effort attempt to shutdown the server * Makes a best effort attempt to shutdown the server
*/ */
private void shutdownServer() { private void shutdownServer() {
// Notify server listeners that the server is about to be stopped
for (XMPPServerListener listener : listeners) {
listener.serverStopping();
}
// If we don't have modules then the server has already been shutdown // If we don't have modules then the server has already been shutdown
if (modules.isEmpty()) { if (modules.isEmpty()) {
return; return;
......
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