You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Alexander Klimetschek (JIRA)" <ji...@apache.org> on 2012/08/23 16:58:42 UTC
[jira] [Created] (SLING-2575) Helper for tracking a
multi-cardinality OSGi service reference
Alexander Klimetschek created SLING-2575:
--------------------------------------------
Summary: Helper for tracking a multi-cardinality OSGi service reference
Key: SLING-2575
URL: https://issues.apache.org/jira/browse/SLING-2575
Project: Sling
Issue Type: Improvement
Components: Commons
Reporter: Alexander Klimetschek
Priority: Minor
Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
There is the [ServiceTracker|http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
A typical manual approach can be seen in the [SlingPostServlet|http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java] in the register*() methods. Important is to handle thread-safeness.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
R: [jira] [Comment Edited] (SLING-2575) Utility for tracking a multi-cardinality OSGi service referente
Posted by al...@pico.it.
Sent from my BlackBerry® wireless device from WIND
-----Original Message-----
From: "Chetan Mehrotra (JIRA)" <ji...@apache.org>
Date: Fri, 19 Oct 2012 14:44:12
To: <de...@sling.apache.org>
Reply-To: dev@sling.apache.org
Subject: [jira] [Comment Edited] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13480049#comment-13480049 ]
Chetan Mehrotra edited comment on SLING-2575 at 10/19/12 2:44 PM:
------------------------------------------------------------------
Patch which adds a new getComparableForServiceRankingDesc method to ServiceUtil. See gist [1] for a sample demonstrating its use
https://gist.github.com/3918574
was (Author: chetanm):
Patch which adds a new getComparableForServiceRankingDesc method to ServiceUtil
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alexander Klimetschek updated SLING-2575:
-----------------------------------------
Attachment: SLING-2575-ServiceReferences.patch
Patch that adds a ServiceReferences class:
* follows mostly the proven approach of the SlingPostServlet
* thread-safety should be ensured (especially through the cached "objects" list), but please review this
* works only with osgi >= 4.1 as it relies on ServiceReference implementing the Comparable interface for the service ranking order (and by id if equal)
Here is sample code how you would use this (also in the javadoc):
@Reference(name = "myService", referenceInterface = MyService.class,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
private ServiceReferences<MyService> myServices = new ServiceReferences<MyService>("myService");
protected void activate(ComponentContext context) {
myServices.activate(context);
}
protected void deactivate(ComponentContext context) {
myServices.deactivate();
}
protected void bindMyService(ServiceReference provider) {
myServices.bind(provider);
}
protected void unbindMyService(ServiceReference provider) {
myServices.unbind(provider);
}
private void doSomething() {
MyService highest = myServices.first();
// ...
for (MyService s: myServices.get()) {
// ...
}
}
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Chetan Mehrotra (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chetan Mehrotra updated SLING-2575:
-----------------------------------
Attachment: SLING-2575-serviceutil-desc.patch
Patch which adds a new getComparableForServiceRankingDesc method to ServiceUtil
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Chetan Mehrotra (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13480049#comment-13480049 ]
Chetan Mehrotra edited comment on SLING-2575 at 10/19/12 2:44 PM:
------------------------------------------------------------------
Patch which adds a new getComparableForServiceRankingDesc method to ServiceUtil. See gist [1] for a sample demonstrating its use
https://gist.github.com/3918574
was (Author: chetanm):
Patch which adds a new getComparableForServiceRankingDesc method to ServiceUtil
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13504464#comment-13504464 ]
Carsten Ziegeler commented on SLING-2575:
-----------------------------------------
So we don't need to implement anything else in commons osgi?
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Chetan Mehrotra (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13482121#comment-13482121 ]
Chetan Mehrotra commented on SLING-2575:
----------------------------------------
The patch can be ignored as the same effect can be achieved by using Collections.reverseOrder().
To summarize one can use the approach used in gist [1] for simpler handling of multi-cardinality OSGi service reference
private Map<Comparable<Object>,AuthorizableAction> actionMap =
new ConcurrentSkipListMap<Comparable<Object>, AuthorizableAction>(Collections.reverseOrder());
[1] https://gist.github.com/3918574
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440409#comment-13440409 ]
Alexander Klimetschek commented on SLING-2575:
----------------------------------------------
> should not hold a sync lock when calling into the framework
You mean the ComponentContext.locateService() call? (I just note that with bind() calling register(), it syncs twice on "refs").
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440456#comment-13440456 ]
Alexander Klimetschek commented on SLING-2575:
----------------------------------------------
Another important question: can activate() and bindSomething() be called at the same time by different threads in the framework?
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13443087#comment-13443087 ]
Alexander Klimetschek edited comment on SLING-2575 at 8/28/12 10:48 PM:
------------------------------------------------------------------------
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility?
Although it IMHO has the disadvantage that it relies on o.a.sling.commons.osgi.ServiceUtil [0] re-implementing the same logic as ServiceReference.compareTo().
[0] http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java
was (Author: alexander.klimetschek):
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility?
(Although it IMHO has the disadvantage that it relies on [o.a.sling.commons.osgi.ServiceUtil|http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java] re-implementing the same logic as ServiceReference.compareTo()).
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13443087#comment-13443087 ]
Alexander Klimetschek edited comment on SLING-2575 at 8/28/12 10:47 PM:
------------------------------------------------------------------------
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility? (Although it IMHO has the disadvantage that it relies on [o.a.sling.commons.osgi.ServiceUtil|http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java] re-implementing the same logic as ServiceReference.compareTo()).
was (Author: alexander.klimetschek):
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility?
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Chetan Mehrotra (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13478685#comment-13478685 ]
Chetan Mehrotra commented on SLING-2575:
----------------------------------------
Interesting discussion. Did not knew about ServiceUtil. I have also struggled with handling of ordered multiple references so far with Declarative Service. This was one area where Bleuprint's sorted dynamic reference list [1] was pretty useful. However we can get similar support by using o.a.s.commons.osgi.ServiceUtil.getComparableForServiceRanking and JDK 6 ConcurrentSkipListMap. With this we need not require synchronized map.
@Reference(name = "AuthorizableAction",
policy = ReferencePolicy.DYNAMIC,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
referenceInterface = AuthorizableAction.class
)
public class MultiplexingAuthorizableAction extends AbstractAuthorizableAction{
private Map<Comparable<Object>,AuthorizableAction> actionMap =
new ConcurrentSkipListMap<Comparable<Object>, AuthorizableAction>();
...
private Collection<AuthorizableAction> getActions() {
return actionMap.values(); //Sorted list
}
private void bindAuthorizableAction(AuthorizableAction action,Map<String,Object> config){
actionMap.put(ServiceUtil.getComparableForServiceRanking(config), action);
}
private void unbindAuthorizableAction(AuthorizableAction action,Map<String,Object> config){
actionMap.remove(ServiceUtil.getComparableForServiceRanking(config));
}
}
For Alex's requirement of having a list sorted in reverse order (which is probably the more common usecase) we can modify the ServiceUtil to
- Provide a Compartor implementation which does the reverse and pass that on to ConcurrentSkipListMap as keys
- OR Have a new ServiceUtil.getDescendingComparableForServiceRanking(config)
[1] http://www.eclipse.org/gemini/blueprint/documentation/reference/1.0.1.RELEASE/html/service-registry.html#service-registry:refs:collection
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Chetan Mehrotra (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13504503#comment-13504503 ]
Chetan Mehrotra commented on SLING-2575:
----------------------------------------
Yup ... unless there is some issue with the proposed approach. Do you think the proposed solution would work fine in all cases ?
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Carsten Ziegeler resolved SLING-2575.
-------------------------------------
Resolution: Won't Fix
Looks good to, so let's close this one
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch, SLING-2575-serviceutil-desc.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440399#comment-13440399 ]
Carsten Ziegeler commented on SLING-2575:
-----------------------------------------
Haven't looked at the patch in detail, however the code should not hold a sync lock when calling into the framework (this is a bug in the post servlet as well).
Have a look at the AdapterManagerImpl which does syncing at a minimum level
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440603#comment-13440603 ]
Felix Meschberger commented on SLING-2575:
------------------------------------------
I think this is not required. Instead of using bind/unbind methods to receive the services, you can use the ComponentContext.locateServices(String) method get the sorted list of all "bound" services. You don't have to manage the list yourself.
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alexander Klimetschek updated SLING-2575:
-----------------------------------------
Description:
Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
[0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
[1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
was:
Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
There is the [ServiceTracker|http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
A typical manual approach can be seen in the [SlingPostServlet|http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java] in the register*() methods. Important is to handle thread-safeness.
Summary: Utility for tracking a multi-cardinality OSGi service reference (was: Helper for tracking a multi-cardinality OSGi service reference)
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13443087#comment-13443087 ]
Alexander Klimetschek commented on SLING-2575:
----------------------------------------------
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility?
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (SLING-2575) Utility for tracking a
multi-cardinality OSGi service reference
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13443087#comment-13443087 ]
Alexander Klimetschek edited comment on SLING-2575 at 8/28/12 10:48 PM:
------------------------------------------------------------------------
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility?
(Although it IMHO has the disadvantage that it relies on [o.a.sling.commons.osgi.ServiceUtil|http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java] re-implementing the same logic as ServiceReference.compareTo()).
was (Author: alexander.klimetschek):
What about integrating the activate/deactivate-less & map-instead-of-ServiceReference approach from https://fisheye6.atlassian.com/changelog/sling?cs=1377994 in the utility? (Although it IMHO has the disadvantage that it relies on [o.a.sling.commons.osgi.ServiceUtil|http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java] re-implementing the same logic as ServiceReference.compareTo()).
> Utility for tracking a multi-cardinality OSGi service reference
> ---------------------------------------------------------------
>
> Key: SLING-2575
> URL: https://issues.apache.org/jira/browse/SLING-2575
> Project: Sling
> Issue Type: Improvement
> Components: Commons
> Reporter: Alexander Klimetschek
> Priority: Minor
> Attachments: SLING-2575-ServiceReferences.patch
>
>
> Managing a SCR @Reference that's basically a list is very difficult when compared to the simple unary, static reference. It seems a typical use case is 0..n cardinality, dynamic policy and ordered by service ranking with the higher ranked ones first. This supports the use case to ask a list of services and have the first responding one win.
> There is the ServiceTracker [0], but its getServiceReferences() method does not return the list sorted in any way, only gives your references and not the typed object(s) and it's a bit cumbersome to use.
> A typical manual approach can be seen in the SlingPostServlet [1] in the register*() methods. Important is to handle thread-safeness.
> [0] http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html
> [1] http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira