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 {
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 {
* Returns 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() {
List<ServerFeaturesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) {
......@@ -1340,12 +1369,14 @@ public class XMPPServer {
}
return answer;
}
/**
* Returns 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() {
List<ServerIdentitiesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) {
......@@ -1362,7 +1393,9 @@ public class XMPPServer {
*
* @return a list with all the modules that provide "discoverable" items associated with
* the server.
* @deprecated Use {@link IQDiscoItemsHandler} instead.
*/
@Deprecated
public List<ServerItemsProvider> getServerItemsProviders() {
List<ServerItemsProvider> answer = new ArrayList<>();
for (Module module : modules.values()) {
......@@ -1372,12 +1405,14 @@ public class XMPPServer {
}
return answer;
}
/**
* Returns 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() {
List<UserIdentitiesProvider> answer = new ArrayList<>();
for (Module module : modules.values()) {
......@@ -1394,7 +1429,9 @@ public class XMPPServer {
*
* @return a list with all the modules that provide "discoverable" items associated with
* users.
* @deprecated Use {@link IQDiscoInfoHandler} instead.
*/
@Deprecated
public List<UserItemsProvider> getUserItemsProviders() {
List<UserItemsProvider> answer = new ArrayList<>();
for (Module module : modules.values()) {
......
......@@ -82,6 +82,7 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
private Map<String, DiscoItemsProvider> serverNodeProviders = new ConcurrentHashMap<>();
private IQHandlerInfo info;
private IQDiscoInfoHandler infoHandler;
private List<UserItemsProvider> userItemsProviders = new ArrayList<>();
public IQDiscoItemsHandler() {
super("XMPP Disco Items Handler");
......@@ -291,7 +292,27 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
infoHandler.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
@Override
public void start() throws IllegalStateException {
super.start();
for (ServerItemsProvider provider : XMPPServer.getInstance().getServerItemsProviders()) {
addServerItemsProvider(provider);
}
}
@Override
......@@ -503,22 +521,17 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
return null;
}
if (name == null) {
List<DiscoItem> answer = new ArrayList<>();
for (ClusteredServerItem item : serverItems.values()) {
answer.add(new DiscoItem(item.element));
}
return answer.iterator();
return getServerItems().iterator();
}
else {
// If addressed to user@domain, add items from UserItemsProviders to
// the reply.
List<UserItemsProvider> itemsProviders = XMPPServer.getInstance().getUserItemsProviders();
if (itemsProviders.isEmpty()) {
if ( userItemsProviders.isEmpty()) {
// If we didn't find any UserItemsProviders, then answer a not found error
return null;
}
List<DiscoItem> answer = new ArrayList<>();
for (UserItemsProvider itemsProvider : itemsProviders) {
for (UserItemsProvider itemsProvider : userItemsProviders ) {
// Check if we have items associated with the requested name
Iterator<Element> itemsItr = itemsProvider.getUserItems(name, senderJID);
if (itemsItr != null) {
......@@ -582,4 +595,16 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
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
// Set us up to answer disco item requests
XMPPServer.getInstance().getIQDiscoItemsHandler().addServerItemsProvider(this);
XMPPServer.getInstance().getIQDiscoInfoHandler().setServerNodeInfoProvider(this.getServiceDomain(), this);
XMPPServer.getInstance().getServerItemsProviders().add(this);
ArrayList<String> params = new ArrayList<>();
params.clear();
......@@ -1288,7 +1287,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
private void stop() {
XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this);
XMPPServer.getInstance().getIQDiscoInfoHandler().removeServerNodeInfoProvider(this.getServiceDomain());
XMPPServer.getInstance().getServerItemsProviders().remove(this);
// Remove the route to this service
routingTable.removeComponentRoute(getAddress());
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