You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Mike Hummel <mh...@mikehummel.de> on 2013/09/30 21:52:21 UTC

[DISCUSS] Generic ServiceMap for ServiceResolver

Hi,

with ResourceAccessSecurity there's the first service depending on the
ServiceResolver and loaded by the ServiceTracker. For further services we
should use a generic way to handle this.

Another goal is that we can implement operations in this way for different
ServiceResolver in a generic way. For example default operations like
'move' 'copy' 'checkout' 'checkin' can then be implemented for different
Resources (jcr, mongodb).

On next step it can be used by the post servlet to access it via REST.

I implemented a try like this

public interface ServiceMap {


 /**

 * Return the instance of the Service for the requested interface

 *

 * @param requestedInterface The Service or null if not found

 * @return

 */

<T> T getService(Class<T> requestedInterface);

 }

public interface ResourceResolver {

…

    /**

     * Return the service map for this resolver.

     *

     * @return

     */

    ServiceMap getServiceMap();

}

To use a service use

ResourceAccessSecurity  service =
resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);

or maybe

MoveOperation  service =
resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
service.move(resource,targetPath);

Ok, what's the goal?

1. We do not need to change resource providers if we initiate a new service
for resources
2. A generic way to access operations if the service implement an
Operation-Interface via REST / Post-Servlet

What do you think?

Mike

Re: [DISCUSS] Generic ServiceMap for ServiceResolver

Posted by Carsten Ziegeler <cz...@apache.org>.
You can do: resourceResolver.adaptTo(YourService.class)

Regards
Carsten


2013/10/4 Mike Hummel <mh...@mikehummel.de>

> Yes, I already thought about the same implemented with the adapter. But the
> Adapter should return an object representing the resources information. The
> ServiceMap should be used to provide services for the resource.
>
> If you can show me a way to do the same using adaptTo() then this
> discussion would be obsolete. Lets use the ResourceAccessSecurity example I
> see this options:
>
> 1. as discussed ResourceAccessSecurity ras =
>
> resource.getResourceResolver().getServices().getService(ResourceAccessSecurity.class);
>
> 2. direct via adaptTo() ResourceAccessSecurity ras =
> (ResourceAccessSecurity)resource.adaptTo(ResourceAccessSecurity.class)
>
> 3. via ServiceMap and adaptTo() ResourceAccessSecurity ras =
>
> ((ServiceMap)resource.adaptTo(ServiceMap.class)).getService(ResourceAccessSecurity.class)
>
> To have a clear coding I would prefer option 1. Number 2 is short but I'm
> not sure how much overhead it is to implement an adapter for every service.
>
>
>
>
>
> 2013/10/2 Carsten Ziegeler <cz...@apache.org>
>
> > Ok, so you're basically suggesting an extension mechanism comparable to
> the
> > adapter pattern?
> >
> > Carsten
> >
> >
> > 2013/10/2 Mike Hummel <mh...@mikehummel.de>
> >
> > > In my understanding the service registry is not able to differ between
> > the
> > > resource implementations like mongo or jcr. If the operation is
> provided
> > > from the resource provider it is specialised for the underlying
> > > implementation.
> > >
> > > This is what you need for ResourceSecurityAccess or manipulating rights
> > on
> > > the resource - without knowledge of the underlying data store.
> > >
> > >
> > > 2013/10/1 Carsten Ziegeler <cz...@apache.org>
> > >
> > > > Hi,
> > > >
> > > > I'm not sure I completely understand your proposal. What's the
> > difference
> > > > to looking up the MoveOperation (or other services) directly from the
> > > > service registry?
> > > >
> > > > Carsten
> > > >
> > > >
> > > > 2013/9/30 Mike Hummel <mh...@mikehummel.de>
> > > >
> > > > > Hi,
> > > > >
> > > > > with ResourceAccessSecurity there's the first service depending on
> > the
> > > > > ServiceResolver and loaded by the ServiceTracker. For further
> > services
> > > we
> > > > > should use a generic way to handle this.
> > > > >
> > > > > Another goal is that we can implement operations in this way for
> > > > different
> > > > > ServiceResolver in a generic way. For example default operations
> like
> > > > > 'move' 'copy' 'checkout' 'checkin' can then be implemented for
> > > different
> > > > > Resources (jcr, mongodb).
> > > > >
> > > > > On next step it can be used by the post servlet to access it via
> > REST.
> > > > >
> > > > > I implemented a try like this
> > > > >
> > > > > public interface ServiceMap {
> > > > >
> > > > >
> > > > >  /**
> > > > >
> > > > >  * Return the instance of the Service for the requested interface
> > > > >
> > > > >  *
> > > > >
> > > > >  * @param requestedInterface The Service or null if not found
> > > > >
> > > > >  * @return
> > > > >
> > > > >  */
> > > > >
> > > > > <T> T getService(Class<T> requestedInterface);
> > > > >
> > > > >  }
> > > > >
> > > > > public interface ResourceResolver {
> > > > >
> > > > > …
> > > > >
> > > > >     /**
> > > > >
> > > > >      * Return the service map for this resolver.
> > > > >
> > > > >      *
> > > > >
> > > > >      * @return
> > > > >
> > > > >      */
> > > > >
> > > > >     ServiceMap getServiceMap();
> > > > >
> > > > > }
> > > > >
> > > > > To use a service use
> > > > >
> > > > > ResourceAccessSecurity  service =
> > > > >
> > > > >
> > > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);
> > > > >
> > > > > or maybe
> > > > >
> > > > > MoveOperation  service =
> > > > >
> > > > >
> > > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
> > > > > service.move(resource,targetPath);
> > > > >
> > > > > Ok, what's the goal?
> > > > >
> > > > > 1. We do not need to change resource providers if we initiate a new
> > > > service
> > > > > for resources
> > > > > 2. A generic way to access operations if the service implement an
> > > > > Operation-Interface via REST / Post-Servlet
> > > > >
> > > > > What do you think?
> > > > >
> > > > > Mike
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Carsten Ziegeler
> > > > cziegeler@apache.org
> > > >
> > >
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
> >
>



-- 
Carsten Ziegeler
cziegeler@apache.org

Re: [DISCUSS] Generic ServiceMap for ServiceResolver

Posted by Mike Hummel <mh...@mikehummel.de>.
Yes, I already thought about the same implemented with the adapter. But the
Adapter should return an object representing the resources information. The
ServiceMap should be used to provide services for the resource.

If you can show me a way to do the same using adaptTo() then this
discussion would be obsolete. Lets use the ResourceAccessSecurity example I
see this options:

1. as discussed ResourceAccessSecurity ras =
resource.getResourceResolver().getServices().getService(ResourceAccessSecurity.class);

2. direct via adaptTo() ResourceAccessSecurity ras =
(ResourceAccessSecurity)resource.adaptTo(ResourceAccessSecurity.class)

3. via ServiceMap and adaptTo() ResourceAccessSecurity ras =
((ServiceMap)resource.adaptTo(ServiceMap.class)).getService(ResourceAccessSecurity.class)

To have a clear coding I would prefer option 1. Number 2 is short but I'm
not sure how much overhead it is to implement an adapter for every service.





2013/10/2 Carsten Ziegeler <cz...@apache.org>

> Ok, so you're basically suggesting an extension mechanism comparable to the
> adapter pattern?
>
> Carsten
>
>
> 2013/10/2 Mike Hummel <mh...@mikehummel.de>
>
> > In my understanding the service registry is not able to differ between
> the
> > resource implementations like mongo or jcr. If the operation is provided
> > from the resource provider it is specialised for the underlying
> > implementation.
> >
> > This is what you need for ResourceSecurityAccess or manipulating rights
> on
> > the resource - without knowledge of the underlying data store.
> >
> >
> > 2013/10/1 Carsten Ziegeler <cz...@apache.org>
> >
> > > Hi,
> > >
> > > I'm not sure I completely understand your proposal. What's the
> difference
> > > to looking up the MoveOperation (or other services) directly from the
> > > service registry?
> > >
> > > Carsten
> > >
> > >
> > > 2013/9/30 Mike Hummel <mh...@mikehummel.de>
> > >
> > > > Hi,
> > > >
> > > > with ResourceAccessSecurity there's the first service depending on
> the
> > > > ServiceResolver and loaded by the ServiceTracker. For further
> services
> > we
> > > > should use a generic way to handle this.
> > > >
> > > > Another goal is that we can implement operations in this way for
> > > different
> > > > ServiceResolver in a generic way. For example default operations like
> > > > 'move' 'copy' 'checkout' 'checkin' can then be implemented for
> > different
> > > > Resources (jcr, mongodb).
> > > >
> > > > On next step it can be used by the post servlet to access it via
> REST.
> > > >
> > > > I implemented a try like this
> > > >
> > > > public interface ServiceMap {
> > > >
> > > >
> > > >  /**
> > > >
> > > >  * Return the instance of the Service for the requested interface
> > > >
> > > >  *
> > > >
> > > >  * @param requestedInterface The Service or null if not found
> > > >
> > > >  * @return
> > > >
> > > >  */
> > > >
> > > > <T> T getService(Class<T> requestedInterface);
> > > >
> > > >  }
> > > >
> > > > public interface ResourceResolver {
> > > >
> > > > …
> > > >
> > > >     /**
> > > >
> > > >      * Return the service map for this resolver.
> > > >
> > > >      *
> > > >
> > > >      * @return
> > > >
> > > >      */
> > > >
> > > >     ServiceMap getServiceMap();
> > > >
> > > > }
> > > >
> > > > To use a service use
> > > >
> > > > ResourceAccessSecurity  service =
> > > >
> > > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);
> > > >
> > > > or maybe
> > > >
> > > > MoveOperation  service =
> > > >
> > > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
> > > > service.move(resource,targetPath);
> > > >
> > > > Ok, what's the goal?
> > > >
> > > > 1. We do not need to change resource providers if we initiate a new
> > > service
> > > > for resources
> > > > 2. A generic way to access operations if the service implement an
> > > > Operation-Interface via REST / Post-Servlet
> > > >
> > > > What do you think?
> > > >
> > > > Mike
> > > >
> > >
> > >
> > >
> > > --
> > > Carsten Ziegeler
> > > cziegeler@apache.org
> > >
> >
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>

Re: [DISCUSS] Generic ServiceMap for ServiceResolver

Posted by Carsten Ziegeler <cz...@apache.org>.
Ok, so you're basically suggesting an extension mechanism comparable to the
adapter pattern?

Carsten


2013/10/2 Mike Hummel <mh...@mikehummel.de>

> In my understanding the service registry is not able to differ between the
> resource implementations like mongo or jcr. If the operation is provided
> from the resource provider it is specialised for the underlying
> implementation.
>
> This is what you need for ResourceSecurityAccess or manipulating rights on
> the resource - without knowledge of the underlying data store.
>
>
> 2013/10/1 Carsten Ziegeler <cz...@apache.org>
>
> > Hi,
> >
> > I'm not sure I completely understand your proposal. What's the difference
> > to looking up the MoveOperation (or other services) directly from the
> > service registry?
> >
> > Carsten
> >
> >
> > 2013/9/30 Mike Hummel <mh...@mikehummel.de>
> >
> > > Hi,
> > >
> > > with ResourceAccessSecurity there's the first service depending on the
> > > ServiceResolver and loaded by the ServiceTracker. For further services
> we
> > > should use a generic way to handle this.
> > >
> > > Another goal is that we can implement operations in this way for
> > different
> > > ServiceResolver in a generic way. For example default operations like
> > > 'move' 'copy' 'checkout' 'checkin' can then be implemented for
> different
> > > Resources (jcr, mongodb).
> > >
> > > On next step it can be used by the post servlet to access it via REST.
> > >
> > > I implemented a try like this
> > >
> > > public interface ServiceMap {
> > >
> > >
> > >  /**
> > >
> > >  * Return the instance of the Service for the requested interface
> > >
> > >  *
> > >
> > >  * @param requestedInterface The Service or null if not found
> > >
> > >  * @return
> > >
> > >  */
> > >
> > > <T> T getService(Class<T> requestedInterface);
> > >
> > >  }
> > >
> > > public interface ResourceResolver {
> > >
> > > …
> > >
> > >     /**
> > >
> > >      * Return the service map for this resolver.
> > >
> > >      *
> > >
> > >      * @return
> > >
> > >      */
> > >
> > >     ServiceMap getServiceMap();
> > >
> > > }
> > >
> > > To use a service use
> > >
> > > ResourceAccessSecurity  service =
> > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);
> > >
> > > or maybe
> > >
> > > MoveOperation  service =
> > >
> > >
> >
> resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
> > > service.move(resource,targetPath);
> > >
> > > Ok, what's the goal?
> > >
> > > 1. We do not need to change resource providers if we initiate a new
> > service
> > > for resources
> > > 2. A generic way to access operations if the service implement an
> > > Operation-Interface via REST / Post-Servlet
> > >
> > > What do you think?
> > >
> > > Mike
> > >
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
> >
>



-- 
Carsten Ziegeler
cziegeler@apache.org

Re: [DISCUSS] Generic ServiceMap for ServiceResolver

Posted by Mike Hummel <mh...@mikehummel.de>.
In my understanding the service registry is not able to differ between the
resource implementations like mongo or jcr. If the operation is provided
from the resource provider it is specialised for the underlying
implementation.

This is what you need for ResourceSecurityAccess or manipulating rights on
the resource - without knowledge of the underlying data store.


2013/10/1 Carsten Ziegeler <cz...@apache.org>

> Hi,
>
> I'm not sure I completely understand your proposal. What's the difference
> to looking up the MoveOperation (or other services) directly from the
> service registry?
>
> Carsten
>
>
> 2013/9/30 Mike Hummel <mh...@mikehummel.de>
>
> > Hi,
> >
> > with ResourceAccessSecurity there's the first service depending on the
> > ServiceResolver and loaded by the ServiceTracker. For further services we
> > should use a generic way to handle this.
> >
> > Another goal is that we can implement operations in this way for
> different
> > ServiceResolver in a generic way. For example default operations like
> > 'move' 'copy' 'checkout' 'checkin' can then be implemented for different
> > Resources (jcr, mongodb).
> >
> > On next step it can be used by the post servlet to access it via REST.
> >
> > I implemented a try like this
> >
> > public interface ServiceMap {
> >
> >
> >  /**
> >
> >  * Return the instance of the Service for the requested interface
> >
> >  *
> >
> >  * @param requestedInterface The Service or null if not found
> >
> >  * @return
> >
> >  */
> >
> > <T> T getService(Class<T> requestedInterface);
> >
> >  }
> >
> > public interface ResourceResolver {
> >
> > …
> >
> >     /**
> >
> >      * Return the service map for this resolver.
> >
> >      *
> >
> >      * @return
> >
> >      */
> >
> >     ServiceMap getServiceMap();
> >
> > }
> >
> > To use a service use
> >
> > ResourceAccessSecurity  service =
> >
> >
> resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);
> >
> > or maybe
> >
> > MoveOperation  service =
> >
> >
> resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
> > service.move(resource,targetPath);
> >
> > Ok, what's the goal?
> >
> > 1. We do not need to change resource providers if we initiate a new
> service
> > for resources
> > 2. A generic way to access operations if the service implement an
> > Operation-Interface via REST / Post-Servlet
> >
> > What do you think?
> >
> > Mike
> >
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>

Re: [DISCUSS] Generic ServiceMap for ServiceResolver

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

I'm not sure I completely understand your proposal. What's the difference
to looking up the MoveOperation (or other services) directly from the
service registry?

Carsten


2013/9/30 Mike Hummel <mh...@mikehummel.de>

> Hi,
>
> with ResourceAccessSecurity there's the first service depending on the
> ServiceResolver and loaded by the ServiceTracker. For further services we
> should use a generic way to handle this.
>
> Another goal is that we can implement operations in this way for different
> ServiceResolver in a generic way. For example default operations like
> 'move' 'copy' 'checkout' 'checkin' can then be implemented for different
> Resources (jcr, mongodb).
>
> On next step it can be used by the post servlet to access it via REST.
>
> I implemented a try like this
>
> public interface ServiceMap {
>
>
>  /**
>
>  * Return the instance of the Service for the requested interface
>
>  *
>
>  * @param requestedInterface The Service or null if not found
>
>  * @return
>
>  */
>
> <T> T getService(Class<T> requestedInterface);
>
>  }
>
> public interface ResourceResolver {
>
> …
>
>     /**
>
>      * Return the service map for this resolver.
>
>      *
>
>      * @return
>
>      */
>
>     ServiceMap getServiceMap();
>
> }
>
> To use a service use
>
> ResourceAccessSecurity  service =
>
> resource.getResourceResolver().getServiceMap().getService(ResourceAccessSecurity.class);
>
> or maybe
>
> MoveOperation  service =
>
> resource.getResourceResolver().getServiceMap().getService(MoveOperation.class);
> service.move(resource,targetPath);
>
> Ok, what's the goal?
>
> 1. We do not need to change resource providers if we initiate a new service
> for resources
> 2. A generic way to access operations if the service implement an
> Operation-Interface via REST / Post-Servlet
>
> What do you think?
>
> Mike
>



-- 
Carsten Ziegeler
cziegeler@apache.org