in gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java [482:540]
public void childEvent(final RemoteConfigurationRegistryClient client, final Type type, final String path) {
final String subPath = StringUtils.substringAfter(path, BASE_SUB_NODE);
final String[] subPathParts = StringUtils.split(subPath, '/');
// Possible values are:
// - /knox/security/topology/cluster
// - /knox/security/topology/cluster/alias
// - /knox/security/topology/cluster/tokens/tokenSubNode/alias
final String cluster = subPathParts.length > 1 ? subPathParts[0] : "";
final boolean tokenSubNode = subPath.contains(TOKENS_SUB_NODE_NAME);
String alias = "";
if (tokenSubNode) {
alias = subPathParts.length == 4 ? subPathParts[3] : "";
} else {
alias = subPathParts.length == 2 ? subPathParts[1] : "";
}
switch (type) {
case REMOVED:
try {
/* remove listener */
client.removeEntryListener(path);
if (!alias.isEmpty()) {
for (RemoteTokenStateChangeListener changeListener : remoteTokenStateChangeListeners) {
changeListener.onRemoved(alias);
}
if (shouldUseLocalAliasService) {
LOG.removeAliasLocally(cluster, alias);
localAliasService.removeAliasForCluster(cluster, alias);
}
}
} catch (final Exception e) {
LOG.errorRemovingAliasLocally(cluster, alias, e.toString());
}
break;
case ADDED:
/* do not set listeners on cluster name but on respective aliases */
if (!alias.isEmpty()) {
try {
client.addEntryListener(path, new RemoteAliasEntryListener(cluster, alias, localAliasService));
} catch (final Exception e) {
LOG.errorAddingRemoteAliasEntryListener(cluster, alias, e.toString());
}
} else if (!BASE_SUB_NODE.equals(path)) {
/* Add a child listener for the cluster */
LOG.addRemoteListener(path);
try {
client.addChildEntryListener(path, new RemoteAliasChildListener(remoteAliasService));
} catch (Exception e) {
LOG.errorAddingRemoteListener(path, e.toString());
}
}
break;
//TODO: UPDATED??
}
}