hk2
  1. hk2
  2. HK2-88

Add the ability to have local services

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.*
    • Fix Version/s: 2.1.*
    • Component/s: None
    • Labels:
      None

      Description

      It would be nice to be able to mark a service (or more accurately, a Descriptor) as producing a "local" service. A "local" service would be one that is NOT visible to any children of the ServiceLocator. While this would not be a fool-proof way of protecting those services from the children, it would provide a functional level of isolation that would be of interest in some parent/child relationships.

      In fact, ServiceLocator and DynamicConfigurationService themselves would be considered "local", so that code with only access to the child service locator could not accidentally add services to the parent, or be able to see the "local" services of the parent by getting the parent ServiceLocator!

        Issue Links

          Activity

          Hide
          Marek Potociar added a comment -

          The local service should be really visible only to the locator in which it was defined. So it should not be visible to children AND parent.

          Show
          Marek Potociar added a comment - The local service should be really visible only to the locator in which it was defined. So it should not be visible to children AND parent .
          Hide
          jwells added a comment -

          Well, the parent already cannot see the services defined only in the child locator.

          Show
          jwells added a comment - Well, the parent already cannot see the services defined only in the child locator.
          Hide
          Marek Potociar added a comment -

          So how would I expose a service to be visible by the parent (I really mean globally, not just a parent) if I wanted to? (IOW, how would I achieve opposite of "local"?)

          Show
          Marek Potociar added a comment - So how would I expose a service to be visible by the parent (I really mean globally, not just a parent) if I wanted to? (IOW, how would I achieve opposite of "local"?)
          Hide
          jwells added a comment -

          I am also not sure if the word "local" is the correct one. Marek and I discussed "private" but that sounded (to me) like it had some security implications. We may need to work on the proper word for describing this type of service.

          Show
          jwells added a comment - I am also not sure if the word "local" is the correct one. Marek and I discussed "private" but that sounded (to me) like it had some security implications. We may need to work on the proper word for describing this type of service.
          Hide
          jwells added a comment -

          You would need access to the parent service locator. If you could get that then you could add the service to the parent service locator, which would then become visible to all the children of that locator.

          Show
          jwells added a comment - You would need access to the parent service locator. If you could get that then you could add the service to the parent service locator, which would then become visible to all the children of that locator.
          Hide
          Marek Potociar added a comment -

          Just to summarize what we discussed off-line:

          • locators should be organized in a parent-child hierarchy
          • there should be 2 binding types:
            1. "shared" - visible to the binding locator instance and all bindings defined in it as well as all children locators
            2. "local" -visible only to the binding locator instance and all bindings defined in it
          • "global" services could be modelled by binding the service in a root locator - HK2 should expose an convenience API for that
          • there are use cases for "private global" services (administration etc.). These could be modeled as "local" root services assuming the direct access to root locator instance is restricted (via SecurityManager or similar mechanism). This way only privileged code could access these services.
          Show
          Marek Potociar added a comment - Just to summarize what we discussed off-line: locators should be organized in a parent-child hierarchy there should be 2 binding types: "shared" - visible to the binding locator instance and all bindings defined in it as well as all children locators "local" -visible only to the binding locator instance and all bindings defined in it "global" services could be modelled by binding the service in a root locator - HK2 should expose an convenience API for that there are use cases for "private global" services (administration etc.). These could be modeled as "local" root services assuming the direct access to root locator instance is restricted (via SecurityManager or similar mechanism). This way only privileged code could access these services.
          Hide
          jwells added a comment -

          There is a new enumeration called DescriptorVisibility that can currently take two values, NORMAL and LOCAL. Descriptors now take this as a field (with the default being NORMAL).

          Normal descriptors can be seen by the ServiceLocator in which it is bound and by all children of that ServiceLocator. Local descriptors can only be seen by the ServiceLocator in which is it bound, and not by any of its children.

          Also added is the @Visibility annotation, which allows the setting of the visibility when using automatic analysis or when using the hk2-inhabitant-generator.

          The ServiceLocator and DynamicConfigurationService services themselves were changed to be LOCAL services.

          Global services are created by binding services into parent service locators. This is handled at a higher layer (e.g., GlassFish).

          Show
          jwells added a comment - There is a new enumeration called DescriptorVisibility that can currently take two values, NORMAL and LOCAL. Descriptors now take this as a field (with the default being NORMAL). Normal descriptors can be seen by the ServiceLocator in which it is bound and by all children of that ServiceLocator. Local descriptors can only be seen by the ServiceLocator in which is it bound, and not by any of its children. Also added is the @Visibility annotation, which allows the setting of the visibility when using automatic analysis or when using the hk2-inhabitant-generator. The ServiceLocator and DynamicConfigurationService services themselves were changed to be LOCAL services. Global services are created by binding services into parent service locators. This is handled at a higher layer (e.g., GlassFish).

            People

            • Assignee:
              jwells
              Reporter:
              jwells
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: