Qualified exports/opens and services

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Qualified exports/opens and services

Nicolai Parlog
 Hi!

First of all, happy new year, everybody.

I got a question regarding qualified exports/opens and services. I
thought I once read a proposal that a service consumer that some
packages are exported or opened to could "forward" those privileges to
the service providers.

As an example, think about JPA and Hibernate (and ignore the ludicrous
module names):

* app code might `opens com.example.dto to jpa`
* when app calls `EntityManager`, it locates Hibernate in module
  `hibernate` as JPA implementation
* `hibernate` can now reflect over `com.example.dto`

That feature doesn't exist, right?

 so long ... Nicolai



--

PGP Key:
    http://keys.gnupg.net/pks/lookup?op=vindex&search=0xCA3BAD2E9CCCD509

Web:
    http://codefx.org
        a blog about software development
    https://www.sitepoint.com/java
        high-quality Java/JVM content
    http://do-foss.de
        Free and Open Source Software for the City of Dortmund

Twitter:
    https://twitter.com/nipafx
Reply | Threaded
Open this post in threaded view
|

Re: Qualified exports/opens and services

David Lloyd
On Thu, Jan 4, 2018 at 8:18 AM, Nicolai Parlog <[hidden email]> wrote:

>  Hi!
>
> First of all, happy new year, everybody.
>
> I got a question regarding qualified exports/opens and services. I
> thought I once read a proposal that a service consumer that some
> packages are exported or opened to could "forward" those privileges to
> the service providers.
>
> As an example, think about JPA and Hibernate (and ignore the ludicrous
> module names):
>
> * app code might `opens com.example.dto to jpa`
> * when app calls `EntityManager`, it locates Hibernate in module
>   `hibernate` as JPA implementation
> * `hibernate` can now reflect over `com.example.dto`
>
> That feature doesn't exist, right?

Hi Nicolai,

You may want to refer to the thread here:
http://mail.openjdk.java.net/pipermail/jigsaw-dev//2017-November/013315.html

Essentially a module may delegate a private Lookup to itself, or a
module may do so on behalf of another module.  To use your example,
the module called "jpa" would have to internally create a private
Lookup on "com.example.dto" and hand it over to the "hibernate"
module, which would then be able to use it to reflect on private
members of "com.example.dto".

That said, the java.lang.invoke.MethodHandles#privateLookupIn() method
leaves a little to be desired as it requires a class from the target
module; it would be nice if there was a variant which accepted a
Module...
--
- DML
Reply | Threaded
Open this post in threaded view
|

Re: Qualified exports/opens and services

Alan Bateman
On 04/01/2018 14:25, David Lloyd wrote:

> :
> Hi Nicolai,
>
> You may want to refer to the thread here:
> http://mail.openjdk.java.net/pipermail/jigsaw-dev//2017-November/013315.html
>
> Essentially a module may delegate a private Lookup to itself, or a
> module may do so on behalf of another module.  To use your example,
> the module called "jpa" would have to internally create a private
> Lookup on "com.example.dto" and hand it over to the "hibernate"
> module, which would then be able to use it to reflect on private
> members of "com.example.dto".
I suspect Nicolai is looking for Module addOpens:

"API Note: This method can be used for cases where a consumer module
uses a qualified opens to open a package to an API module but where the
reflective access to the members of classes in the consumer module is
delegated to code in another module. Code in the API module can use this
method to open the package in the consumer module to the other module."

but you are right that using Lookup objects would work well here. No
need to open any package, instead have the consumer module pass a Lookup
object as a capability to the framework, the framework passes to the
trusted service provider.

>
> That said, the java.lang.invoke.MethodHandles#privateLookupIn() method
> leaves a little to be desired as it requires a class from the target
> module; it would be nice if there was a variant which accepted a
> Module...
There wouldn't be a lookup class in that case so it would be a different
kinda of lookup object.

-Alan
Reply | Threaded
Open this post in threaded view
|

Re: Qualified exports/opens and services

Nicolai Parlog
 Hi Alan, David,

thanks for your replies, both are very helpful! :)

 so long ... Nicolai



On 04.01.2018 16:06, Alan Bateman wrote:
> On 04/01/2018 14:25, David Lloyd wrote:
>> : Hi Nicolai,
>>
>> You may want to refer to the thread here:
>> http://mail.openjdk.java.net/pipermail/jigsaw-dev//2017-November/013315.html
>>
>>
>>
>>
Essentially a module may delegate a private Lookup to itself, or a

>> module may do so on behalf of another module.  To use your
>> example, the module called "jpa" would have to internally create
>> a private Lookup on "com.example.dto" and hand it over to the
>> "hibernate" module, which would then be able to use it to reflect
>> on private members of "com.example.dto".
> I suspect Nicolai is looking for Module addOpens:
>
> "API Note: This method can be used for cases where a consumer
> module uses a qualified opens to open a package to an API module
> but where the reflective access to the members of classes in the
> consumer module is delegated to code in another module. Code in the
> API module can use this method to open the package in the consumer
> module to the other module."
>
> but you are right that using Lookup objects would work well here.
> No need to open any package, instead have the consumer module pass
> a Lookup object as a capability to the framework, the framework
> passes to the trusted service provider.
>
>>
>> That said, the java.lang.invoke.MethodHandles#privateLookupIn()
>> method leaves a little to be desired as it requires a class from
>> the target module; it would be nice if there was a variant which
>> accepted a Module...
> There wouldn't be a lookup class in that case so it would be a
> different kinda of lookup object.
>
> -Alan
>

--

PGP Key:
    http://keys.gnupg.net/pks/lookup?op=vindex&search=0xCA3BAD2E9CCCD509

Web:
    http://codefx.org
        a blog about software development
    https://www.sitepoint.com/java
        high-quality Java/JVM content
    http://do-foss.de
        Free and Open Source Software for the City of Dortmund

Twitter:
    https://twitter.com/nipafx