📄 pubsubmodule.java
字号:
return serviceName + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(); } public JID getAddress() { // TODO Cache this JID for performance? return new JID(null, getServiceDomain(), null); } public Collection<String> getUsersAllowedToCreate() { return allowedToCreate; } public Collection<String> getSysadmins() { return sysadmins; } public void addSysadmin(String userJID) { sysadmins.add(userJID.trim().toLowerCase()); // Update the config. String[] jids = new String[sysadmins.size()]; jids = sysadmins.toArray(jids); JiveGlobals.setProperty("xmpp.pubsub.sysadmin.jid", fromArray(jids)); } public void removeSysadmin(String userJID) { sysadmins.remove(userJID.trim().toLowerCase()); // Update the config. String[] jids = new String[sysadmins.size()]; jids = sysadmins.toArray(jids); JiveGlobals.setProperty("xmpp.pubsub.sysadmin.jid", fromArray(jids)); } public boolean isNodeCreationRestricted() { return nodeCreationRestricted; } public boolean isMultipleSubscriptionsEnabled() { return multipleSubscriptionsEnabled; } public void setNodeCreationRestricted(boolean nodeCreationRestricted) { this.nodeCreationRestricted = nodeCreationRestricted; JiveGlobals.setProperty("xmpp.pubsub.create.anyone", Boolean.toString(nodeCreationRestricted)); } public void addUserAllowedToCreate(String userJID) { // Update the list of allowed JIDs to create nodes. allowedToCreate.add(userJID.trim().toLowerCase()); // Update the config. String[] jids = new String[allowedToCreate.size()]; jids = allowedToCreate.toArray(jids); JiveGlobals.setProperty("xmpp.pubsub.create.jid", fromArray(jids)); } public void removeUserAllowedToCreate(String userJID) { // Update the list of allowed JIDs to create nodes. allowedToCreate.remove(userJID.trim().toLowerCase()); // Update the config. String[] jids = new String[allowedToCreate.size()]; jids = allowedToCreate.toArray(jids); JiveGlobals.setProperty("xmpp.pubsub.create.jid", fromArray(jids)); } public void initialize(XMPPServer 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"); if (serviceName == null) { serviceName = "pubsub"; } // Load the list of JIDs that are sysadmins of the PubSub service String property = JiveGlobals.getProperty("xmpp.pubsub.sysadmin.jid"); String[] jids; if (property != null) { jids = property.split(","); for (String jid : jids) { sysadmins.add(jid.trim().toLowerCase()); } } nodeCreationRestricted = JiveGlobals.getBooleanProperty("xmpp.pubsub.create.anyone", false); // Load the list of JIDs that are allowed to create nodes property = JiveGlobals.getProperty("xmpp.pubsub.create.jid"); if (property != null) { jids = property.split(","); for (String jid : jids) { allowedToCreate.add(jid.trim().toLowerCase()); } } multipleSubscriptionsEnabled = JiveGlobals.getBooleanProperty("xmpp.pubsub.multiple-subscriptions", true); routingTable = server.getRoutingTable(); router = server.getPacketRouter(); engine = new PubSubEngine(server.getPacketRouter()); // Load default configuration for leaf nodes leafDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, true); if (leafDefaultConfiguration == null) { // Create and save default configuration for leaf nodes; leafDefaultConfiguration = new DefaultNodeConfiguration(true); leafDefaultConfiguration.setAccessModel(AccessModel.open); leafDefaultConfiguration.setPublisherModel(PublisherModel.publishers); leafDefaultConfiguration.setDeliverPayloads(true); leafDefaultConfiguration.setLanguage("English"); leafDefaultConfiguration.setMaxPayloadSize(5120); leafDefaultConfiguration.setNotifyConfigChanges(true); leafDefaultConfiguration.setNotifyDelete(true); leafDefaultConfiguration.setNotifyRetract(true); leafDefaultConfiguration.setPersistPublishedItems(false); leafDefaultConfiguration.setMaxPublishedItems(-1); leafDefaultConfiguration.setPresenceBasedDelivery(false); leafDefaultConfiguration.setSendItemSubscribe(true); leafDefaultConfiguration.setSubscriptionEnabled(true); leafDefaultConfiguration.setReplyPolicy(null); PubSubPersistenceManager.createDefaultConfiguration(this, leafDefaultConfiguration); } // Load default configuration for collection nodes collectionDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, false); if (collectionDefaultConfiguration == null ) { // Create and save default configuration for collection nodes; collectionDefaultConfiguration = new DefaultNodeConfiguration(false); collectionDefaultConfiguration.setAccessModel(AccessModel.open); collectionDefaultConfiguration.setPublisherModel(PublisherModel.publishers); collectionDefaultConfiguration.setDeliverPayloads(false); collectionDefaultConfiguration.setLanguage("English"); collectionDefaultConfiguration.setNotifyConfigChanges(true); collectionDefaultConfiguration.setNotifyDelete(true); collectionDefaultConfiguration.setNotifyRetract(true); collectionDefaultConfiguration.setPresenceBasedDelivery(false); collectionDefaultConfiguration.setSubscriptionEnabled(true); collectionDefaultConfiguration.setReplyPolicy(null); collectionDefaultConfiguration .setAssociationPolicy(CollectionNode.LeafNodeAssociationPolicy.all); collectionDefaultConfiguration.setMaxLeafNodes(-1); PubSubPersistenceManager .createDefaultConfiguration(this, collectionDefaultConfiguration); } // Load nodes to memory PubSubPersistenceManager.loadNodes(this); // Ensure that we have a root collection node String rootNodeID = JiveGlobals.getProperty("xmpp.pubsub.root.nodeID", ""); if (nodes.isEmpty()) { // Create root collection node String creator = JiveGlobals.getProperty("xmpp.pubsub.root.creator"); JID creatorJID = creator != null ? new JID(creator) : server.getAdmins().iterator().next(); rootCollectionNode = new CollectionNode(this, null, rootNodeID, creatorJID); // Add the creator as the node owner rootCollectionNode.addOwner(creatorJID); // Save new root node rootCollectionNode.saveToDB(); } else { rootCollectionNode = (CollectionNode) getNode(rootNodeID); } // Listen to cluster events ClusterManager.addListener(this); } public void start() { // Check that the service is enabled if (!isServiceEnabled()) { return; } super.start(); // Add the route to this service routingTable.addComponentRoute(getAddress(), this); // Start the pubsub engine engine.start(this); ArrayList<String> params = new ArrayList<String>(); params.clear(); params.add(getServiceDomain()); Log.info(LocaleUtils.getLocalizedString("startup.starting.pubsub", params)); } public void stop() { super.stop(); // Remove the route to this service routingTable.removeComponentRoute(getAddress()); // Stop the pubsub engine. This will gives us the chance to // save queued items to the database. engine.shutdown(this); } private void enableService(boolean enabled) { if (serviceEnabled == enabled) { // Do nothing if the service status has not changed return; } XMPPServer server = XMPPServer.getInstance(); if (!enabled) { // Disable disco information server.getIQDiscoItemsHandler().removeServerItemsProvider(this); // Stop the service/module stop(); } serviceEnabled = enabled; if (enabled) { // Start the service/module start(); // Enable disco information server.getIQDiscoItemsHandler().addServerItemsProvider(this); } } 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() { // Disable the service until we know that we are the senior cluster member enableService(false); } public void joinedCluster(byte[] nodeID) { // Do nothing } public void leftCluster() { // Offer the service when not running in a cluster enableService(true); } public void leftCluster(byte[] nodeID) { // Do nothing } public void markedAsSeniorClusterMember() { // Offer the service since we are the senior cluster member enableService(true); } 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>(); final DiscoServerItem item = new DiscoServerItem(new JID( getServiceDomain()), "Publish-Subscribe service", null, null, this, this); items.add(item); return items.iterator(); } public Iterator<Element> getIdentities(String name, String node, JID senderJID) { ArrayList<Element> identities = new ArrayList<Element>(); if (name == null && node == null) { // Answer the identity of the PubSub service Element identity = DocumentHelper.createElement("identity"); identity.addAttribute("category", "pubsub"); identity.addAttribute("name", "Publish-Subscribe service"); identity.addAttribute("type", "service"); identities.add(identity); } else if (name == null) { // Answer the identity of a given node Node pubNode = getNode(node); if (canDiscoverNode(pubNode)) { Element identity = DocumentHelper.createElement("identity"); identity.addAttribute("category", "pubsub"); identity.addAttribute("type", pubNode.isCollectionNode() ? "collection" : "leaf"); identities.add(identity); } } return identities.iterator(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -