Commit 508584fb authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for enabling/disabling the service. JM-1262

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9855 b35dd754-fafc-0310-a699-88a17e54d16e
parent d0230cd8
...@@ -28,10 +28,7 @@ import org.jivesoftware.openfire.forms.spi.XDataFormImpl; ...@@ -28,10 +28,7 @@ import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.forms.spi.XFormFieldImpl; import org.jivesoftware.openfire.forms.spi.XFormFieldImpl;
import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.pubsub.models.PublisherModel; import org.jivesoftware.openfire.pubsub.models.PublisherModel;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.*;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.*; import org.xmpp.packet.*;
import java.util.*; import java.util.*;
...@@ -46,7 +43,7 @@ import java.util.concurrent.LinkedBlockingQueue; ...@@ -46,7 +43,7 @@ import java.util.concurrent.LinkedBlockingQueue;
* @author Matt Tucker * @author Matt Tucker
*/ */
public class PubSubModule extends BasicModule implements ServerItemsProvider, DiscoInfoProvider, public class PubSubModule extends BasicModule implements ServerItemsProvider, DiscoInfoProvider,
DiscoItemsProvider, RoutableChannelHandler, PubSubService, ClusterEventListener { DiscoItemsProvider, RoutableChannelHandler, PubSubService, ClusterEventListener, PropertyEventListener {
/** /**
* the chat service's hostname * the chat service's hostname
...@@ -289,7 +286,7 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -289,7 +286,7 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
public String getServiceDomain() { public String getServiceDomain() {
return serviceName + "." + XMPPServer.getInstance().getServerInfo().getName(); return serviceName + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
} }
public JID getAddress() { public JID getAddress() {
...@@ -355,6 +352,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -355,6 +352,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
super.initialize(server); super.initialize(server);
// Listen to property events so that the template is always up to date
PropertyEventDispatcher.addListener(this);
serviceEnabled = JiveGlobals.getBooleanProperty("xmpp.pubsub.enabled", true);
serviceName = JiveGlobals.getProperty("xmpp.pubsub.service"); serviceName = JiveGlobals.getProperty("xmpp.pubsub.service");
if (serviceName == null) { if (serviceName == null) {
serviceName = "pubsub"; serviceName = "pubsub";
...@@ -451,6 +452,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -451,6 +452,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
public void start() { public void start() {
// Check that the service is enabled
if (!isServiceEnabled()) {
return;
}
super.start(); super.start();
// Add the route to this service // Add the route to this service
routingTable.addComponentRoute(getAddress(), this); routingTable.addComponentRoute(getAddress(), this);
...@@ -492,6 +497,23 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -492,6 +497,23 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
} }
public void setServiceEnabled(boolean enabled) {
// Enable/disable the service
enableService(enabled);
// Store the new setting
JiveGlobals.setProperty("xmpp.pubsub.enabled", Boolean.toString(enabled));
}
/**
* Returns true if the service is available. Use {@link #setServiceEnabled(boolean)} to
* enable or disable the service.
*
* @return true if the MUC service is available.
*/
public boolean isServiceEnabled() {
return serviceEnabled;
}
public void joinedCluster() { public void joinedCluster() {
// Disable the service until we know that we are the senior cluster member // Disable the service until we know that we are the senior cluster member
enableService(false); enableService(false);
...@@ -516,6 +538,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -516,6 +538,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
public Iterator<DiscoServerItem> getItems() { public Iterator<DiscoServerItem> getItems() {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return null;
}
ArrayList<DiscoServerItem> items = new ArrayList<DiscoServerItem>(); ArrayList<DiscoServerItem> items = new ArrayList<DiscoServerItem>();
final DiscoServerItem item = new DiscoServerItem(new JID( final DiscoServerItem item = new DiscoServerItem(new JID(
getServiceDomain()), "Publish-Subscribe service", null, null, this, getServiceDomain()), "Publish-Subscribe service", null, null, this,
...@@ -652,6 +678,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -652,6 +678,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
public boolean hasInfo(String name, String node, JID senderJID) { public boolean hasInfo(String name, String node, JID senderJID) {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return false;
}
if (name == null && node == null) { if (name == null && node == null) {
// We always have info about the Pubsub service // We always have info about the Pubsub service
return true; return true;
...@@ -664,6 +694,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -664,6 +694,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) { public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return null;
}
List<DiscoItem> answer = new ArrayList<DiscoItem>(); List<DiscoItem> answer = new ArrayList<DiscoItem>();
String serviceDomain = getServiceDomain(); String serviceDomain = getServiceDomain();
if (name == null && node == null) { if (name == null && node == null) {
...@@ -804,4 +838,27 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -804,4 +838,27 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
public void setItemsTaskTimeout(int timeout) { public void setItemsTaskTimeout(int timeout) {
items_task_timeout = timeout; items_task_timeout = timeout;
} }
public void propertySet(String property, Map<String, Object> params) {
if (property.equals("xmpp.pubsub.enabled")) {
boolean enabled = Boolean.parseBoolean((String)params.get("value"));
// Enable/disable the service
enableService(enabled);
}
}
public void propertyDeleted(String property, Map<String, Object> params) {
if (property.equals("xmpp.pubsub.enabled")) {
// Enable/disable the service
enableService(true);
}
}
public void xmlPropertySet(String property, Map<String, Object> params) {
// Do nothing
}
public void xmlPropertyDeleted(String property, Map<String, Object> params) {
// Do nothing
}
} }
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