Unverified Commit 21639a68 authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #1029 from guusdk/OF-1496_Reduce_discovery_complexity

OF-1496 reduce discovery complexity
parents e92adc6f 4b98b442
...@@ -667,6 +667,33 @@ public class XMPPServer { ...@@ -667,6 +667,33 @@ public class XMPPServer {
logger.error(LocaleUtils.getLocalizedString("admin.error"), e); logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
// Register modules with service discovery provides where applicable.
for (Module module : modules.values() )
{
// Service discovery info
if (module instanceof ServerFeaturesProvider) {
getIQDiscoInfoHandler().addServerFeaturesProvider( (ServerFeaturesProvider) module );
}
if (module instanceof ServerIdentitiesProvider) {
getIQDiscoInfoHandler().addServerIdentitiesProvider( (ServerIdentitiesProvider) module );
}
if (module instanceof UserIdentitiesProvider) {
getIQDiscoInfoHandler().addUserIdentitiesProvider( (UserIdentitiesProvider) module );
}
// Service discovery items
if (module instanceof ServerItemsProvider) {
getIQDiscoItemsHandler().addServerItemsProvider( (ServerItemsProvider) module );
}
if (module instanceof UserItemsProvider) {
getIQDiscoItemsHandler().addUserItemsProvider( (UserItemsProvider) module);
}
}
} }
/** /**
...@@ -1330,7 +1357,9 @@ public class XMPPServer { ...@@ -1330,7 +1357,9 @@ public class XMPPServer {
* Returns a list with all the modules that provide "discoverable" features. * Returns a list with all the modules that provide "discoverable" features.
* *
* @return a list with all the modules that provide "discoverable" features. * @return a list with all the modules that provide "discoverable" features.
* @deprecated Use {@link IQDiscoInfoHandler} instead.
*/ */
@Deprecated
public List<ServerFeaturesProvider> getServerFeaturesProviders() { public List<ServerFeaturesProvider> getServerFeaturesProviders() {
List<ServerFeaturesProvider> answer = new ArrayList<>(); List<ServerFeaturesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) { for (Module module : modules.values()) {
...@@ -1340,12 +1369,14 @@ public class XMPPServer { ...@@ -1340,12 +1369,14 @@ public class XMPPServer {
} }
return answer; return answer;
} }
/** /**
* Returns a list with all the modules that provide "discoverable" identities. * Returns a list with all the modules that provide "discoverable" identities.
* *
* @return a list with all the modules that provide "discoverable" identities. * @return a list with all the modules that provide "discoverable" identities.
* @deprecated Use {@link IQDiscoInfoHandler} instead.
*/ */
@Deprecated
public List<ServerIdentitiesProvider> getServerIdentitiesProviders() { public List<ServerIdentitiesProvider> getServerIdentitiesProviders() {
List<ServerIdentitiesProvider> answer = new ArrayList<>(); List<ServerIdentitiesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) { for (Module module : modules.values()) {
...@@ -1362,7 +1393,9 @@ public class XMPPServer { ...@@ -1362,7 +1393,9 @@ public class XMPPServer {
* *
* @return a list with all the modules that provide "discoverable" items associated with * @return a list with all the modules that provide "discoverable" items associated with
* the server. * the server.
* @deprecated Use {@link IQDiscoItemsHandler} instead.
*/ */
@Deprecated
public List<ServerItemsProvider> getServerItemsProviders() { public List<ServerItemsProvider> getServerItemsProviders() {
List<ServerItemsProvider> answer = new ArrayList<>(); List<ServerItemsProvider> answer = new ArrayList<>();
for (Module module : modules.values()) { for (Module module : modules.values()) {
...@@ -1372,12 +1405,14 @@ public class XMPPServer { ...@@ -1372,12 +1405,14 @@ public class XMPPServer {
} }
return answer; return answer;
} }
/** /**
* Returns a list with all the modules that provide "discoverable" user identities. * Returns a list with all the modules that provide "discoverable" user identities.
* *
* @return a list with all the modules that provide "discoverable" user identities. * @return a list with all the modules that provide "discoverable" user identities.
* @deprecated Use {@link IQDiscoInfoHandler} instead.
*/ */
@Deprecated
public List<UserIdentitiesProvider> getUserIdentitiesProviders() { public List<UserIdentitiesProvider> getUserIdentitiesProviders() {
List<UserIdentitiesProvider> answer = new ArrayList<>(); List<UserIdentitiesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) { for (Module module : modules.values()) {
...@@ -1394,7 +1429,9 @@ public class XMPPServer { ...@@ -1394,7 +1429,9 @@ public class XMPPServer {
* *
* @return a list with all the modules that provide "discoverable" items associated with * @return a list with all the modules that provide "discoverable" items associated with
* users. * users.
* @deprecated Use {@link IQDiscoInfoHandler} instead.
*/ */
@Deprecated
public List<UserItemsProvider> getUserItemsProviders() { public List<UserItemsProvider> getUserItemsProviders() {
List<UserItemsProvider> answer = new ArrayList<>(); List<UserItemsProvider> answer = new ArrayList<>();
for (Module module : modules.values()) { for (Module module : modules.values()) {
......
...@@ -82,6 +82,7 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv ...@@ -82,6 +82,7 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
private Map<String, DiscoItemsProvider> serverNodeProviders = new ConcurrentHashMap<>(); private Map<String, DiscoItemsProvider> serverNodeProviders = new ConcurrentHashMap<>();
private IQHandlerInfo info; private IQHandlerInfo info;
private IQDiscoInfoHandler infoHandler; private IQDiscoInfoHandler infoHandler;
private List<UserItemsProvider> userItemsProviders = new ArrayList<>();
public IQDiscoItemsHandler() { public IQDiscoItemsHandler() {
super("XMPP Disco Items Handler"); super("XMPP Disco Items Handler");
...@@ -291,7 +292,27 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv ...@@ -291,7 +292,27 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
infoHandler.removeProvider(host); infoHandler.removeProvider(host);
removeProvider(host); removeProvider(host);
} }
}
/**
* Adds the items provided by the new service that implements the UserItemsProvider interface. This information will
* be used whenever a disco for items is made against users of the server.
*
* @param provider the UserItemsProvider that provides new user items.
*/
public void addUserItemsProvider( UserItemsProvider provider )
{
this.userItemsProviders.add( provider );
}
/**
* Removes the UserItemsProvider
*
* @param provider the UserItemsProvider that provides new user items.
*/
public void removeUserItemsProvider( UserItemsProvider provider )
{
this.userItemsProviders.remove( provider );
} }
/** /**
...@@ -409,9 +430,6 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv ...@@ -409,9 +430,6 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
@Override @Override
public void start() throws IllegalStateException { public void start() throws IllegalStateException {
super.start(); super.start();
for (ServerItemsProvider provider : XMPPServer.getInstance().getServerItemsProviders()) {
addServerItemsProvider(provider);
}
} }
@Override @Override
...@@ -503,22 +521,17 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv ...@@ -503,22 +521,17 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
return null; return null;
} }
if (name == null) { if (name == null) {
List<DiscoItem> answer = new ArrayList<>(); return getServerItems().iterator();
for (ClusteredServerItem item : serverItems.values()) {
answer.add(new DiscoItem(item.element));
}
return answer.iterator();
} }
else { else {
// If addressed to user@domain, add items from UserItemsProviders to // If addressed to user@domain, add items from UserItemsProviders to
// the reply. // the reply.
List<UserItemsProvider> itemsProviders = XMPPServer.getInstance().getUserItemsProviders(); if ( userItemsProviders.isEmpty()) {
if (itemsProviders.isEmpty()) {
// If we didn't find any UserItemsProviders, then answer a not found error // If we didn't find any UserItemsProviders, then answer a not found error
return null; return null;
} }
List<DiscoItem> answer = new ArrayList<>(); List<DiscoItem> answer = new ArrayList<>();
for (UserItemsProvider itemsProvider : itemsProviders) { for (UserItemsProvider itemsProvider : userItemsProviders ) {
// Check if we have items associated with the requested name // Check if we have items associated with the requested name
Iterator<Element> itemsItr = itemsProvider.getUserItems(name, senderJID); Iterator<Element> itemsItr = itemsProvider.getUserItems(name, senderJID);
if (itemsItr != null) { if (itemsItr != null) {
...@@ -582,4 +595,16 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv ...@@ -582,4 +595,16 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
return answer.iterator(); return answer.iterator();
} }
} }
/**
* Returns all server items.
* @return A collection of server items.
*/
public List<DiscoItem> getServerItems() {
List<DiscoItem> answer = new ArrayList<>();
for (ClusteredServerItem item : serverItems.values()) {
answer.add(new DiscoItem(item.element));
}
return answer;
}
} }
...@@ -1273,7 +1273,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1273,7 +1273,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
// Set us up to answer disco item requests // Set us up to answer disco item requests
XMPPServer.getInstance().getIQDiscoItemsHandler().addServerItemsProvider(this); XMPPServer.getInstance().getIQDiscoItemsHandler().addServerItemsProvider(this);
XMPPServer.getInstance().getIQDiscoInfoHandler().setServerNodeInfoProvider(this.getServiceDomain(), this); XMPPServer.getInstance().getIQDiscoInfoHandler().setServerNodeInfoProvider(this.getServiceDomain(), this);
XMPPServer.getInstance().getServerItemsProviders().add(this);
ArrayList<String> params = new ArrayList<>(); ArrayList<String> params = new ArrayList<>();
params.clear(); params.clear();
...@@ -1288,7 +1287,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1288,7 +1287,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
private void stop() { private void stop() {
XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this); XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this);
XMPPServer.getInstance().getIQDiscoInfoHandler().removeServerNodeInfoProvider(this.getServiceDomain()); XMPPServer.getInstance().getIQDiscoInfoHandler().removeServerNodeInfoProvider(this.getServiceDomain());
XMPPServer.getInstance().getServerItemsProviders().remove(this);
// Remove the route to this service // Remove the route to this service
routingTable.removeComponentRoute(getAddress()); routingTable.removeComponentRoute(getAddress());
broadcastShutdown(); broadcastShutdown();
......
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