[
https://issues.apache.org/jira/browse/SLING-2185?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13086992#comment-13086992
]
Bertrand Delacretaz commented on SLING-2185:
--------------------------------------------
Thanks for your patch!
To avoid using a timer, I suggest a different pattern to refresh the list of
services dynamically, here's an example:
public FooBackend getFooBackend(String id) throws IllegalArgumentException {
maybeReloadList();
final FooBackend result = FooBackends.get(id);
if(result == null) {
throw new IllegalArgumentException("FooBackend having id=" + id + "
not found");
}
return result;
}
private synchronized void maybeReloadList() {
if(tracker.getTrackingCount() != trackingCount) {
final Map<String, FooBackend> newMap = new HashMap<String,
FooBackend>();
final Object [] svc = tracker.getServices();
if(svc != null) {
for(Object o : svc) {
final FooBackend cb = (FooBackend)o;
newMap.put(cb.getId(), cb);
}
}
FooBackends = newMap;
trackingCount = tracker.getTrackingCount();
log.info("Reloaded FooBackend services: {}", FooBackends.values());
}
}
This will even take service ordering into account, as
ServiceTracker.getTrackingCount() changes any time a change to a relevant
service happens.
Not also that you do not need to implement the Comparator<ServiceReference>
yourself, as specified at
http://www.osgi.org/javadoc/r4v42/org/osgi/framework/ServiceReference.html
comparing ServiceReferences does take the service ranking into account.
> Provide a way to configure IOManager/PropertyManager handlers at runtime.
> -------------------------------------------------------------------------
>
> Key: SLING-2185
> URL: https://issues.apache.org/jira/browse/SLING-2185
> Project: Sling
> Issue Type: Improvement
> Components: JCR
> Affects Versions: JCR Webdav 2.1.0
> Reporter: Timothee Maret
> Priority: Minor
> Attachments: io-handler-service.patch
>
>
> Currently, the handlers for the IOManager and PropertyManager instances are
> defined in the org.apache.sling.jcr.webdav.impl.helper.SlingResourceConfig
> class.
> This is not flexible and make it difficult to add project specific handlers
> in the configuration.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira