[jboss-as7-dev] Naming Issues

Stuart Douglas stuart.w.douglas at gmail.com
Mon Apr 1 18:11:01 EDT 2013



Eduardo Martins wrote:
> Hi all, I have been looking at whole code of service based naming stores, and we have several more issues (beyond the injection without lookup), some which may motivate deep changes on the logic:
>
> 1. Subcontext created not stored
>
> InitialContext context = new InitialContext();
> context.createSubcontext("a");
> Context a = (Context) context.lookup("a");
>
> The lookup above fails, and this due to not creating sub contexts on the store. I discussed this briefly with David last week, seems a bug, but it could also be done this way as a feature. As it is now implemented, a context only exists if there a child entry.
> Obviously by not having sub contexts we also fail on managing sub contexts environments, it is always null, when it should start as the parent context's one, and store changes on its own.
>
> Note that this implementation choice was clearly made on purpose, there is no destroyContext() impl at all (other than name validation and check for writable store type).
> This implementation choice saves the storing of a few msc services, but that also means no dependencies to contexts will exist
>


There are some cases where contexts are explicitly bound, such as in the 
case of java:comp/env (which must be available for lookup even if it is 
empty). We should do the same thing here.

> 2. (Re)Bind without parent context
>
> Context a = null;
> InitialContext context = new InitialContext();
> try {
> 	a = (Context) context.lookup("a");
> } catch (NameNotFoundException e) {
> 	context.bind("a/b",new Object());
> }
>
> The bind above will succeed, i.e. we allow binds without parent context, but according to Context javadocs bind or rebind require that the parent context exists.
>


This was a deliberate decision. Unless it is actually causing someone 
problems we do not need to change this.

> 3. Linkrefs madness
>
> Currently the lookup logic, wrt links is more or less: lookup a msc service with the provided name, and if nothing found look for a parent msc service, which if exists and is a link then we try again with link value + remaining name. Then on bind we do not follow links, we bind directly to the provided name, so:
>
> InitialContext context = new InitialContext();
> context.bind("a1",new LinkRef("a2"));
> context.bind(new CompositeName("a2","b"),new Object());
> context.bind(new CompositeName("a1","b"),new Object());
> context.lookup(new CompositeName("a1","b"));
> context.lookup(new CompositeName("a2","b"));
>
> This will bind 2 values to the same "logic" name, and both lookups will work, yet return the different values. To fix this on bind we should first lookup the parent context, which if follows links correctly, would have failed context.bind(new CompositeName("a1","b"),new Object())
>
> There are also obvious link related issues on msc deps: if somehitng is bound using a name that contains a link, lookup deps will only work if use the name used in bind. Fixing this part may be scary, msc would need to know that when a link is bound, deps to both linksource/x and linktarget/y may become satisfied. Still on msc topic, rebind support is also a problem, since we can't change deps
>


This looks like we are not checking the parent context at all, which is 
something we should fix to prevent children being bound as children of 
other non-context bindings.

> 4. Other issues
>
> There are other issues, for instance rebind does unbind+bind, and this would mean that any state (such as env on the old entry) is lost, msc deps get screwed, etc. but I did not check these with testing yet, and we can probably target these later.
>


I am not sure what you mean here.

> 5. So, how do we fix all of this?
>
> Well, for a start should we fix it? I know some people may want to avoid these kind of changes, but naming is not quite something that is going away any soon, and imho our naming is broken at so many ways...


Not really. For the most part these are fairly minor issues, this same 
code has been in use for a long time now, if these were a major problems 
that required a complete redesign then we would have heard more complaints.

>
> IF we go for fixing it, start by adding and requiring the missing contexts, while at same time provide an option for create these automatically on bind, to be used on everything besides direct jndi app code, avoiding changes on binding code everywhere on AS projects.


I really don't think this is necessary. Even though this goes against 
the javadoc it is not causing problems for users, and it is basically a 
feature that makes JNDI binding a lot easier to use.


>
> And then reverse the bind/lookup logic wrt links, first lookup the parent, to follow links properly, and only then bind/lookup the terminal part of the name. Wrt implementation this would also mean that we probably would make it much faster by having each context with a map of terminal name childs, dunno about memory... Currently we have in each store a ConcurrentSkipListSet, and use lower/ceiling functionally to navigate through it.
>


We should probably be looking up each context when performing a bind. 
This should not require any underlying change in the data structures 
used, rather the name should just be separated into components, and then 
each component looked up. bind() performance is not a big deal, as it 
generally only happens at application startup.

> Wrt MSC,  we could for a start try to no fix all at once, as I have been saying to David, thus ignore the existent of links targets, BUT ensuring all understand the limitations for dependencies if links are used. Anyway I believe David wants to go further so I will just leave it for him to comment.
>

 >

I think we just need an extra namespace that ignores service 
dependencies, that it always looked up via straight JNDI lookup. We 
should also consider just using a lookup in LookupInjectionSource, but I 
would like to see how it impacts performance first.

Stuart

> --E
>
>


More information about the jboss-as7-dev mailing list