You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Osipov, Michael" <mi...@siemens.com> on 2012/04/17 09:38:08 UTC
Availability of a resource in a realm
Hi folks,
I have a resource declared in my context.xml (not a resource link). I want to retrieve that resource as soon as possible in my realm. I tried start() and init() but it seems like that at this time the InitialContext is not available. So at what time can I expect the context being "complete"?
I am on Tomcat 6.0.35
With best regards,
Michael Osipov
RE: Availability of a resource in a realm
Posted by "Osipov, Michael" <mi...@siemens.com>.
Konstantin Kolinko wrote:
> 2012/4/18 Osipov, Michael <mi...@siemens.com>:
>> Konstantin Kolinko wrote:
>>> 2012/4/17 Osipov, Michael <mi...@siemens.com>:
>>>> Hi folks,
>>>>
>>>> I have a resource declared in my context.xml (not a resource link).
>>>> I want to retrieve that resource as soon as possible in my realm. I
>>>> tried start() and init() but it seems like that at this time the
>>>> InitialContext is not available. So at what time can I expect the
>>>> context being "complete"?
>>>>
>>>> I am on Tomcat 6.0.35
>>>>
>>>
>>> Look at DataSourceRealm for an example.
>>>
>>> IIRC, what is seen as InitialContext depends on the value of
>>> Thread.getContextClassLoader() when InitialContext instance is
>>> created.
>>
>> I have found the spot. Thanks!
>> You have the same approach as me. Prior authentication you retrieve
>> the resource. But, I do cache the resource object you don't. Are
>> there any implications? How costly is a recurring lookup?
>
> Personally, I'd cache the DataSource obtained through the lookup. I
> think it is oversight, though maybe it makes the realm more manageable
> through JMX.
A doCache property would be nice though I do not use this realm.
> During first releases of Tomcat 7 there was some discussion about
> objects created by factories in JNDI. Tomcat approach was to cache the
> created object and return it for further lookups. Some recent JavaEE
> spec required a new instance of the object to be created on each
> lookup. We updated implementation in early Tomcat 7 releases to
> match the recent spec, but had to revert on users' demands, making it
> configurable. See "singleton" attribute
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
>
> If each lookup created a new DataSource instance it would certainly be
> expensive.
>
> I'd say that DataSourceRealm does not create new InitialContext
> instance, so that avoids some initialization overhead. I do not know
> how expensive is the lookup itself.
Thanks for the insight. I ended up init my object like this:
protected synchronized void initDirContextSource()
throws NamingException {
if (dirContextSource == null) {
Context context = null;
if (localDirContextSource) {
context = ContextBindings.getClassLoader();
context = (Context) context.lookup("comp/env");
} else {
StandardServer server = (StandardServer) ServerFactory.getServer();
context = server.getGlobalNamingContext();
}
dirContextSource = (DirContextSource) context.lookup(dirContextSourceName);
}
}
Which is called by getPrincipal.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Availability of a resource in a realm
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/4/18 Osipov, Michael <mi...@siemens.com>:
> Konstantin Kolinko wrote:
>> 2012/4/17 Osipov, Michael <mi...@siemens.com>:
>>> Hi folks,
>>>
>>> I have a resource declared in my context.xml (not a resource link).
>>> I want to retrieve that resource as soon as possible in my realm. I
>>> tried start() and init() but it seems like that at this time the
>>> InitialContext is not available. So at what time can I expect the
>>> context being "complete"?
>>>
>>> I am on Tomcat 6.0.35
>>>
>>
>> Look at DataSourceRealm for an example.
>>
>> IIRC, what is seen as InitialContext depends on the value of
>> Thread.getContextClassLoader() when InitialContext instance is
>> created.
>
> I have found the spot. Thanks!
> You have the same approach as me. Prior authentication you retrieve the resource. But, I do cache the resource object you don't. Are there any implications? How costly is a recurring lookup?
Personally, I'd cache the DataSource obtained through the lookup. I
think it is oversight, though maybe it makes the realm more manageable
through JMX.
During first releases of Tomcat 7 there was some discussion about
objects created by factories in JNDI. Tomcat approach was to cache the
created object and return it for further lookups. Some recent JavaEE
spec required a new instance of the object to be created on each
lookup. We updated implementation in early Tomcat 7 releases to
match the recent spec, but had to revert on users' demands, making it
configurable. See "singleton" attribute
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
If each lookup created a new DataSource instance it would certainly be
expensive.
I'd say that DataSourceRealm does not create new InitialContext
instance, so that avoids some initialization overhead. I do not know
how expensive is the lookup itself.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Availability of a resource in a realm
Posted by "Osipov, Michael" <mi...@siemens.com>.
Konstantin Kolinko wrote:
> 2012/4/17 Osipov, Michael <mi...@siemens.com>:
>> Hi folks,
>>
>> I have a resource declared in my context.xml (not a resource link).
>> I want to retrieve that resource as soon as possible in my realm. I
>> tried start() and init() but it seems like that at this time the
>> InitialContext is not available. So at what time can I expect the
>> context being "complete"?
>>
>> I am on Tomcat 6.0.35
>>
>
> Look at DataSourceRealm for an example.
>
> IIRC, what is seen as InitialContext depends on the value of
> Thread.getContextClassLoader() when InitialContext instance is
> created.
I have found the spot. Thanks!
You have the same approach as me. Prior authentication you retrieve the resource. But, I do cache the resource object you don't. Are there any implications? How costly is a recurring lookup?
With best regards,
Michael Osipov
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Availability of a resource in a realm
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/4/17 Osipov, Michael <mi...@siemens.com>:
> Hi folks,
>
> I have a resource declared in my context.xml (not a resource link). I want to retrieve that resource as soon as possible in my realm. I tried start() and init() but it seems like that at this time the InitialContext is not available. So at what time can I expect the context being "complete"?
>
> I am on Tomcat 6.0.35
>
Look at DataSourceRealm for an example.
IIRC, what is seen as InitialContext depends on the value of
Thread.getContextClassLoader() when InitialContext instance is
created.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org