ResourceChangeListener strange behaviour
Hello,
I have a simple scenario - a node in the repository that we want to 'observe' and perform some action in case this node changes. ResourceChangeListener (https://sling.apache.org/apidocs/sling9/org/apache/sling/api/resource/observation/ResourceChangeListener.html) looked very promising, however I ran into couple of problems.
1) Sample component declaration (simplified)
(
service = ResourceChangeListener.class,
immediate = true,
property = {
ResourceChangeListener.PATHS + "=/apps/globallink-adaptor/config/repositories/blueprint",
ResourceChangeListener.PATHS + "=/apps/globallink-adaptor/config/repositories/blueprint-xf",
ResourceChangeListener.CHANGES + "=ADDED",
ResourceChangeListener.CHANGES + "=CHANGED",
ResourceChangeListener.CHANGES + "=REMOVED",
}
)
@ServiceDescription("Custom change listener")
public class CustomListener implements ResourceChangeListener {
public void onChange(List<ResourceChange> changeList) {
for (ResourceChange resourceChange : changeList){
LOGGER.info("==> Caught change. Change type: {}, Change target: {}, UserID: {}", resourceChange.getType(), resourceChange.getPath(), resourceChange.getUserId() );
}
}
2) And now the problems:
- whenever I change the 'observed' node(s) I can see the listeners triggers number of times (between 1 - 4, I haven't found any pattern), visible in the log
2022-07-08 16:38:39.577 INFO [obfuscated] ==> Caught change. Change type: CHANGED, Change target: /apps/globallink-adaptor/config/repositories/blueprint-xf, UserID: admin
2022-07-08 16:38:39.579 INFO [obfuscated] ==> Caught change. Change type: CHANGED, Change target: /apps/globallink-adaptor/config/repositories/blueprint-xf, UserID: admin
2022-07-08 16:38:39.581 INFO [obfuscated] ==> Caught change. Change type: CHANGED, Change target: /apps/globallink-adaptor/config/repositories/blueprint-xf, UserID: admin
2022-07-08 16:38:39.585 INFO [obfuscated] ==> Caught change. Change type: CHANGED, Change target: /apps/globallink-adaptor/config/repositories/blueprint-xf, UserID: admin
- in my code I'm performing certain operations like getting ResourceResolver from service user, for some of these triggers (all caused by a single change) this seems to fail without any reason in the logs why that would be so
- if I make an update to my code and push changes to local AEM, changes are NOT always propagated into executed code (perhaps some caching?). I can see that for example when I modify the message being logged, AEM keeps on logging as per the original code. Additionally when I'm debugging via remote java app I sometimes get the warning in my IDE that source code does not match the executed code.
When I raised this to the Adobe support I got l was told they did not support customization (yes, very helpful). I was wondering if anyone here has run into similar behaviour?
Thanks!