Commit 7edf58dc authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

InternalComponentManager is now a module. JM-916

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6430 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5e8d4090
......@@ -364,8 +364,6 @@ public class XMPPServer {
initModules();
// Start all the modules
startModules();
// Initialize component manager (initialize before plugins get loaded)
InternalComponentManager.getInstance().start();
}
catch (Exception e) {
e.printStackTrace();
......@@ -400,8 +398,6 @@ public class XMPPServer {
initModules();
// Start all the modules
startModules();
// Initialize component manager (initialize before plugins get loaded)
InternalComponentManager.getInstance().start();
}
// Initialize statistics
ServerTrafficCounter.initStatistics();
......@@ -490,6 +486,7 @@ public class XMPPServer {
loadModule(FileTransferProxy.class.getName());
loadModule(PubSubModule.class.getName());
loadModule(UpdateManager.class.getName());
loadModule(InternalComponentManager.class.getName());
// Load this module always last since we don't want to start listening for clients
// before the rest of the modules have been started
loadModule(ConnectionManagerImpl.class.getName());
......
......@@ -15,6 +15,7 @@ import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.container.BasicModule;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager;
......@@ -42,7 +43,7 @@ import java.util.concurrent.TimeUnit;
*
* @author Derek DeMoro
*/
public class InternalComponentManager implements ComponentManager, RoutableChannelHandler {
public class InternalComponentManager extends BasicModule implements ComponentManager, RoutableChannelHandler {
private Map<String, Component> components = new ConcurrentHashMap<String, Component>();
private Map<String, IQ> componentInfo = new ConcurrentHashMap<String, IQ>();
......@@ -53,7 +54,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
private List<ComponentEventListener> listeners =
new CopyOnWriteArrayList<ComponentEventListener>();
private static InternalComponentManager instance = new InternalComponentManager();
private static InternalComponentManager instance;
/**
* XMPP address of this internal service. The address is of the form: component.[domain]
*/
......@@ -64,6 +65,11 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
*/
private String serverDomain;
public InternalComponentManager() {
super("Internal Component Manager");
instance = this;
}
public static InternalComponentManager getInstance() {
return instance;
}
......@@ -82,6 +88,14 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
}
}
public void stop() {
super.stop();
if (getAddress() != null) {
// Remove the route to this service
XMPPServer.getInstance().getRoutingTable().removeRoute(getAddress());
}
}
public void addComponent(String subdomain, Component component) throws ComponentException {
// Check that the requested subdoman is not taken by another component
Component existingComponent = components.get(subdomain);
......@@ -102,15 +116,6 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
try {
component.initialize(componentJID, this);
component.start();
}
catch (ComponentException e) {
// Unregister the componet's domain
components.remove(subdomain);
// Remove the route
XMPPServer.getInstance().getRoutingTable().removeRoute(componentJID);
// Rethrow the exception
throw e;
}
// Notify listeners that a new component has been registered
for (ComponentEventListener listener : listeners) {
......@@ -123,6 +128,20 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
// then it will be added to the list of discoverable server items.
checkDiscoSupport(component, componentJID);
}
catch (Exception e) {
// Unregister the componet's domain
components.remove(subdomain);
// Remove the route
XMPPServer.getInstance().getRoutingTable().removeRoute(componentJID);
if (e instanceof ComponentException) {
// Rethrow the exception
throw (ComponentException)e;
}
// Rethrow the exception
throw new ComponentException(e);
}
}
public void removeComponent(String subdomain) {
Component component = components.remove(subdomain);
......
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