On Tue, Dec 09, 2003 at 12:22:48PM -0800, David Jencks wrote:
> 
> On Tuesday, December 9, 2003, at 10:40 AM, David Blevins wrote:
> 
> >On Mon, Dec 08, 2003 at 09:43:39PM -0800, David Jencks wrote:
> >>I'm sorry, I don't understand all about jndi.
> >>
> >>Could you give an example of what this is for, and how it differs from
> >>binding into the read only context refs whose targets are in say the
> >>jmx context?
> >
> >The ReadOnlyContext is used by the OpenEJB nova containers, so there 
> >is no jmx anything going on.
> 
> At least when deployed in geronimo, ejb-refs, ejb-links, and 
> resource-refs are done by binding a reference into the jmx jndi 
> context.  A name in this context essentially is an object name + 
> operation name, and the the lookup is done by returning the result of 
> the operation.

Sure.  The context I'm constructing the ReadOnlyContext with is essentially the 
"env" part of java:comp/env, so no jmx references are being used in the ENC of 
a bean.

> 
> > The situation is that I need to add another Context implementation, 
> >one built by OpenEJB, into the ReadOnlyContext of an EJBContainer.
> >
> >Doing this by instantiating the ReadOnlyContext with a Map, where one 
> >of the values is the non-ReadOnlyContext context object.  Lookups to 
> >the respective name need to be delegated to that context object.
> 
> Would you get the same effect by listing the OpenEJB context and 
> binding everything you found into the ReadOnly context?

I would have liked to have done that, but there is support in the OpenEJB 
context implementation similar to what you mention about jmx with the 
ReadOnlyContext.  Most of what is bound are special objects that will get you 
what you want dynamically.

> So, is a typical name you might look up something like
> java:/comp/env/geronimo/read/only/openejb/context/actualobject
> 
> where the "context shift" occurs between 'only' and 'openejb'?

That would be accurate, but as I mention the "env" part is where the shift 
occurs (again, this only applies to OpenEJB running without Geronimo).

> And... If I write some kind of mutable context, that say looked up 
> connection factories in jmx based on knowing most of their object name 
> and the operation to use, I could bind this into the ReadOnlyContext?

Let me rephrase your sentence a bit; you can *construct* a ReadOnlyContext with 
anything in the Map that you like, but you can never *bind* anything.  But, 
yes, the ReadOnlyContext will now delegate to any Context objects in it's Map 
if a lookup against the treeBindings fails.  So you can construct a 
ReadOnlyContext with a Map containing any sort of Context implementation you 
wish.

I'll add that interestingly enough the "bindings" object in the ReadOnlyContext 
was not used at all during lookups, only for calls to "list" and 
"listBindings."  I've simply added support for the bindings in the "lookup" 
method as well.

The first part of the name is stripped off, a lookup is done against the 
bindings Map.  If the object retreived is _not_ a Context instance, it is 
returned.  If the object retreived _is_ a Context instance, a lookup is 
performed on it using the remaining path name.

Using your example above 
(java:comp/env/geronimo/read/only/openejb/context/actualobject), there would 
have to be a ReadOnlyContext with a Map that looked like this:

  "openejb" => [EMAIL PROTECTED]

... when that IvmContext instance is found it would be asked to lookup 
"context/actualObject"

Here is the new code again as a refresher:

    // Split out the first name of the path
    // and look for it in the bindings map.
    CompositeName path = new CompositeName(name);
    
    if (path.size() == 0) {
        return this;
    } else {
        Object obj = bindings.get(path.get(0));
        if (obj == null){
            throw new NameNotFoundException(name);
        } else if (obj instanceof Context && path.size() > 1){
            Context subContext = (Context) obj;
            obj = subContext.lookup(path.getSuffix(1));
        }
        return obj;
    }

A lot of explanation for just a few lines of code, but you're worth the time.  
Be warned though, I will be picking your brain shortly on the topic of 
container deployment.

Thanks
David Blevins

> 
> many thanks
> david jencks
> 
> >
> >-David Blevins
> >
> >>
> >>Thanks
> >>david jencks
> >>
> >>On Monday, December 8, 2003, at 09:03 PM, [EMAIL PROTECTED] wrote:
> >>
> >>>dblevins    2003/12/08 21:03:49
> >>>
> >>> Modified:    modules/core/src/java/org/apache/geronimo/naming/java
> >>>                       ReadOnlyContext.java
> >>> Log:
> >>> Added support to do lookups from other Context implementations.  In
> >>>other words,
> >>> sub-contexts under the context which aren't ReadOnlyContext
> >>>implementations.
> >>>
> >>> Revision  Changes    Path
> >>> 1.7       +23 -3
> >>>incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/
> >>>java/ReadOnlyContext.java
> >>>
> >>> Index: ReadOnlyContext.java
> >>> ===================================================================
> >>> RCS file:
> >>>/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/
> >>>geronimo/naming/java/ReadOnlyContext.java,v
> >>> retrieving revision 1.6
> >>> retrieving revision 1.7
> >>> diff -u -r1.6 -r1.7
> >>> --- ReadOnlyContext.java  16 Nov 2003 05:24:38 -0000      1.6
> >>> +++ ReadOnlyContext.java  9 Dec 2003 05:03:49 -0000       1.7
> >>> @@ -87,7 +87,7 @@
> >>>   * resolution phase performed by the JVM takes considerably longer,
> >>>so for
> >>>   * optimum performance lookups should be coded like:</p>
> >>>   * <code>
> >>> - *   Context componentContext = new
> >>>InitialContext().lookup("java:comp");
> >>> + *   Context componentContext = (Context)new
> >>>InitialContext().lookup("java:comp");
> >>>   *   String envEntry = (String)
> >>>componentContext.lookup("env/myEntry");
> >>>   *   String envEntry2 = (String)
> >>>componentContext.lookup("env/myEntry2");
> >>>   * </code>
> >>> @@ -122,7 +122,11 @@
> >>>      }
> >>>
> >>>      ReadOnlyContext(Hashtable env) {
> >>> +        if (env == null) {
> >>> +            this.env = new Hashtable();
> >>> +        } else {
> >>>          this.env = new Hashtable(env);
> >>> +        }
> >>>          this.bindings = Collections.EMPTY_MAP;
> >>>          this.treeBindings = Collections.EMPTY_MAP;
> >>>      }
> >>> @@ -159,8 +163,24 @@
> >>>                      throw new NamingException("scheme " + scheme +
> >>>" not recognized");
> >>>                  }
> >>>                  return ctx.lookup(name);
> >>> +            } else {
> >>> +                // Split out the first name of the path
> >>> +                // and look for it in the bindings map.
> >>> +                CompositeName path = new CompositeName(name);
> >>> +
> >>> +                if (path.size() == 0) {
> >>> +                    return this;
> >>> +                } else {
> >>> +                    Object obj = bindings.get(path.get(0));
> >>> +                    if (obj == null){
> >>> +                        throw new NameNotFoundException(name);
> >>> +                    } else if (obj instanceof Context &&
> >>>path.size() > 1){
> >>> +                        Context subContext = (Context) obj;
> >>> +                        obj = subContext.lookup(path.getSuffix(1));
> >>> +                    }
> >>> +                    return obj;
> >>> +                }
> >>>              }
> >>> -            throw new NameNotFoundException(name);
> >>>          }
> >>>          if (result instanceof LinkRef) {
> >>>              LinkRef ref = (LinkRef) result;
> >>>
> >>>
> >>>
> >>>
> >

Reply via email to