use of org.apache.sling.jcr.resource.internal.JcrResourceListener in project sling by apache.
the class JcrResourceProvider method unregisterListeners.
/**
* Unregister all observation listeners.
*/
private void unregisterListeners() {
logger.debug("Unregistering resource listeners...");
for (final Closeable c : this.listeners.values()) {
try {
logger.debug("Removing listener for {}", ((JcrResourceListener) c).getConfig().getPaths());
c.close();
} catch (final IOException e) {
// ignore this as the method above does not throw it
}
}
this.listeners.clear();
if (this.listenerConfig != null) {
try {
this.listenerConfig.close();
} catch (final IOException e) {
// ignore this as the method above does not throw it
}
this.listenerConfig = null;
}
logger.debug("Unregistered resource listeners");
}
use of org.apache.sling.jcr.resource.internal.JcrResourceListener in project sling by apache.
the class JcrResourceProvider method updateListeners.
/**
* Update observation listeners.
*/
private void updateListeners() {
if (this.listenerConfig == null) {
this.unregisterListeners();
this.registerListeners();
} else {
logger.debug("Updating resource listeners...");
final Map<ObserverConfiguration, Closeable> oldMap = new HashMap<>(this.listeners);
this.listeners.clear();
try {
for (final ObserverConfiguration config : this.getProviderContext().getObservationReporter().getObserverConfigurations()) {
// check if such a listener already exists
Closeable listener = oldMap.remove(config);
if (listener == null) {
logger.debug("Registering listener for {}", config.getPaths());
listener = new JcrResourceListener(this.listenerConfig, config);
} else {
logger.debug("Updating listener for {}", config.getPaths());
((JcrResourceListener) listener).update(config);
}
this.listeners.put(config, listener);
}
} catch (final RepositoryException e) {
throw new SlingException("Can't create the JCR event listener.", e);
}
for (final Closeable c : oldMap.values()) {
try {
logger.debug("Removing listener for {}", ((JcrResourceListener) c).getConfig().getPaths());
c.close();
} catch (final IOException e) {
// ignore this as the method above does not throw it
}
}
logger.debug("Updated resource listeners");
}
}
use of org.apache.sling.jcr.resource.internal.JcrResourceListener in project sling by apache.
the class JcrResourceProvider method registerListeners.
/**
* Register all observation listeners.
*/
private void registerListeners() {
if (this.repository != null) {
logger.debug("Registering resource listeners...");
try {
this.listenerConfig = new JcrListenerBaseConfig(this.getProviderContext().getObservationReporter(), this.repository);
for (final ObserverConfiguration config : this.getProviderContext().getObservationReporter().getObserverConfigurations()) {
logger.debug("Registering listener for {}", config.getPaths());
final Closeable listener = new JcrResourceListener(this.listenerConfig, config);
this.listeners.put(config, listener);
}
} catch (final RepositoryException e) {
throw new SlingException("Can't create the JCR event listener.", e);
}
logger.debug("Registered resource listeners");
}
}
Aggregations