You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Costin Leau <co...@gmail.com> on 2005/09/29 09:46:35 UTC

Re[2]: shutting down repository obtained from jndi via spring

Thanks Aaron!

I looked over to JndiObjectFactoryBean and the main issue is that you
need an interface to which to cast to. I will check the forums is
adding class support is possible to implement in the future.
You can however bypass this (unless you want to use the SM support) by
creating just a wrapper bean that does manually a casting of the
repository class retrieved from the JNDI and calls destroy on it manually (this is what the
FactoryBean actually does).

I'd really like feedback on the project so if you discover any bugs or
have ideas for improvements add them please to SM JIRA
(http://opensource2.atlassian.com/projects/spring/browse/MOD).


> Checkout the RepositoryFactoryBean in the sandbox of the SpringModules
> project (https://springmodules.dev.java.net/). This factory bean takes care
> of shutting down the repository correctly. It also offers the jcrTemplate
> for simplifying many of the common JCR actions and an
> OpenSessionInViewFilter that will maintain an open JCR Session throughout
> the lifetime of a request.. I am using it in my webapp and it works great.

> Thanks to Costin Leau for this great addition to the SpringModules.

> --
> Aaron Jackson

> Here are the bean entries I added to my application context:

> <bean id="repository" class="
> org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
> <!-- normal factory beans params -->
> <property name="configuration"
> value="classpath:jackrabbit-repo.xml"/>
> <property name="homeDir" value="file:/repository"/>
> </bean>

> <bean id="jcrSessionFactory"
> class="org.springmodules.jcr.JcrSessionFactory
">>
> <property name="repository" ref="repository"/>
> <property name="credentials">
> <bean class="javax.jcr.SimpleCredentials">
> <constructor-arg index="0" value="bogus"/>
> <!-- create the credentials using a bean factory -->
> <constructor-arg index="1">
> <bean factory-bean="password"
> factory-method="toCharArray"/>
> </constructor-arg>
> </bean>
> </property>
> </bean>

> <!-- create the password to return it as a char[] -->
> <bean id="password" class="java.lang.String">
> <constructor-arg index="0" value="pass"/>
> </bean>

> <bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
> <property name="sessionFactory" ref="jcrSessionFactory"/>
> <property name="allowCreate" value="true"/>
> </bean>

> On 9/28/05, Brian Moseley <bc...@osafoundation.org> wrote:
>>
>> i know at least a few folks here use spring with jackrabbit, so i'm
>> asking this question here first in hopes that somebody has already
>> solved the problem.
>>
>> i'm using spring's JndiObjectFactoryBean to obtain the Repository i've
>> set up as a naming resource in tomcat.
>>
>> since updating to the latest jackrabbit source, i'm finding that a
>> normal server shutdown does not cause the repository to be shutdown. the
>> repository lock file is not removed, and i can not successfully reopen
>> the repository when restarting tomcat.
>>
>> i tried using a destroy method on my bean (see below), but i got an
>> error from DefaultListableBeanFactory that "Couldn't find a destroy
>> method named 'shutdown' on bean with name 'jcrRepository'".
>>
>> <bean id="jcrRepository"
>> class="org.springframework.jndi.JndiObjectFactoryBean"
>> destroy-method="shutdown">
>> <property name="jndiName">
>> <value>jcr/cosmo</value>
>> </property>
>> <property name="resourceRef">
>> <value>true</value>
>> </property>
>> </bean>
>>
>> destroy-method works fine in my test environment, where i instantiate
>> RepositoryImpl directly.
>>
>> <bean id="jcrRepositoryConfig"
>> class="org.apache.jackrabbit.core.config.RepositoryConfig"
>> factory-method="create">
>> <constructor-arg type="java.lang.String" index="0">
>> <value>@CONFIGFILEPATH@</value>
>> </constructor-arg>
>> <constructor-arg type="java.lang.String" index="1">
>> <value>@REPOSITORYHOMEDIRPATH@</value>
>> </constructor-arg>
>> </bean>
>>
>> <bean id="jcrRepository"
>> class="org.apache.jackrabbit.core.RepositoryImpl"
>> destroy-method="shutdown">
>> <constructor-arg>
>> <ref local="jcrRepositoryConfig"/>
>> </constructor-arg>
>> </bean>
>>
>> any suggestions? i *really* don't want to have to write a servlet
>> context listener to shut jackrabbit down. i have thus far managed to
>> keep jackrabbit-specific code out of the webapp and would like to keep
>> it that way.
>>
>> thanks!
>>



-- 
Best regards,
 Costin                            mailto:costin.leau@gmail.com


Re: shutting down repository obtained from jndi via spring

Posted by Alexandru Popescu <th...@gmail.com>.
#: Brian Moseley changed the world a bit at a time by saying on  10/5/2005 7:25 PM :#
> Tobias Bocanegra wrote:
> 
>> if it's just about the .lock file,
>> http://issues.apache.org/jira/browse/JCR-233 suggests a solution with
>> exclusive file locking. imo, this would be the best option (although
>> some FS might not support filelocks. encoutered this on some linux
>> NFS).
> 
> well, it's about both issues. i want to make sure the repository is 
> being shut down cleanly when my webapp and/or tomcat shuts down. i 
> expect a clean shutdown to deal with the lock file appropriately. i am 
> not too interested in how the lock file is implemented ;)
> 

The patch for 120 should assure that in case of a normal/clean shutdown the .lock files are removed. 
However I think it may be a good idea to use also the 233 patch.

./alex
--
.w( the_mindstorm )p.


Re: shutting down repository obtained from jndi via spring

Posted by Emmanouil Batsis <ma...@geekologue.com>.
On Wednesday 05 October 2005 22:34, Brian Moseley wrote:
> yeah, i can do that, but it breaks "webapp encapsulation". deploying my
> webapp is no longer as simple as setting up the repository as a global
> naming resource and then having an implementation-agnostic webapp.

Same problem for me; i'm writing a ContextListener to initialize the repo on 
webapp startup and close it on shutdown. Using reflection to check for a 
shutdown() method in the repo implementation is the best way i have come up 
with to avoid using jackrabbit packages. I havent tried it yet and i am not 
sure i always want to actually shutdown the repo along with the webapp but 
that is another issue...

> perhaps the ultimately most correct approach to this is to add a
> shutdown method to javax.jcr.Repository.

+1 but i would not expect that to pop up soon. 

Manos

Re: shutting down repository obtained from jndi via spring

Posted by Edgar Poce <ed...@gmail.com>.
Hi brian

Brian Moseley wrote:
> yeah, i can do that, but it breaks "webapp encapsulation". deploying my 
> webapp is no longer as simple as setting up the repository as a global 
> naming resource and then having an implementation-agnostic webapp.

I've just found that Tomcat includes a LifeCycleListener that listens 
engine, host and context lifecycle events. I guess that a custom 
LifeCycleListener would be the right way to start and shutdown 
jackrabbit in tomcat.

br,
edgar


Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Edgar Poce wrote:

> I attached it to my previous post. You can also download it from
> http://issues.apache.org/jira/browse/JCR-243. I don't experience this
> problem with my configuration, so please let me know if it works

heya. thanks, i'm sure that will work - if i configure spring to know 
that the object i'm looking up in jndi is a BindableRepository rather 
than a javax.jcr.Repository.

yeah, i can do that, but it breaks "webapp encapsulation". deploying my 
webapp is no longer as simple as setting up the repository as a global 
naming resource and then having an implementation-agnostic webapp.

perhaps the ultimately most correct approach to this is to add a 
shutdown method to javax.jcr.Repository.

Re: shutting down repository obtained from jndi via spring

Posted by Edgar Poce <ed...@gmail.com>.
Hi Alexandru

On 10/5/05, Alexandru Popescu <th...@gmail.com> wrote:
> >  the problem with the spring configuration is that the JNDI instance
> > doesn't expose the shutdown method, so you can't call it from Spring.
> > i attach a patch that fixes it. Please give it a try and let me know
> > if it works.
> >
>
> where do you attach it? ;-)

I attached it to my previous post. You can also download it from
http://issues.apache.org/jira/browse/JCR-243. I don't experience this
problem with my configuration, so please let me know if it works

br,
edgar

>
> ./alex
> --
> .w( the_mindstorm )p.
>
> > No matter whether it's exclusive or not, the lock file is a different
> > topic and AFAIK it's working as expected, it's letting you know that
> > jackrabbit is not shutting down properly.
> >
> > br,
> > edgar
>
>

Re: shutting down repository obtained from jndi via spring

Posted by Alexandru Popescu <th...@gmail.com>.
#: Edgar Poce changed the world a bit at a time by saying on  10/5/2005 8:03 PM :#
> Hi
> 
> On 10/5/05, Brian Moseley <bc...@osafoundation.org> wrote:
>> well, it's about both issues. i want to make sure the repository is
>> being shut down cleanly when my webapp and/or tomcat shuts down. i
>> expect a clean shutdown to deal with the lock file appropriately. i am
>> not too interested in how the lock file is implemented ;)
>>
> 
>  the problem with the spring configuration is that the JNDI instance
> doesn't expose the shutdown method, so you can't call it from Spring.
> i attach a patch that fixes it. Please give it a try and let me know
> if it works.
> 

where do you attach it? ;-)

./alex
--
.w( the_mindstorm )p.

> No matter whether it's exclusive or not, the lock file is a different
> topic and AFAIK it's working as expected, it's letting you know that
> jackrabbit is not shutting down properly.
> 
> br,
> edgar


Re: shutting down repository obtained from jndi via spring

Posted by Edgar Poce <ed...@gmail.com>.
Hi

On 10/5/05, Brian Moseley <bc...@osafoundation.org> wrote:
> well, it's about both issues. i want to make sure the repository is
> being shut down cleanly when my webapp and/or tomcat shuts down. i
> expect a clean shutdown to deal with the lock file appropriately. i am
> not too interested in how the lock file is implemented ;)
>

 the problem with the spring configuration is that the JNDI instance
doesn't expose the shutdown method, so you can't call it from Spring.
i attach a patch that fixes it. Please give it a try and let me know
if it works.

No matter whether it's exclusive or not, the lock file is a different
topic and AFAIK it's working as expected, it's letting you know that
jackrabbit is not shutting down properly.

br,
edgar

Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Tobias Bocanegra wrote:

> if it's just about the .lock file,
> http://issues.apache.org/jira/browse/JCR-233 suggests a solution with
> exclusive file locking. imo, this would be the best option (although
> some FS might not support filelocks. encoutered this on some linux
> NFS).

well, it's about both issues. i want to make sure the repository is 
being shut down cleanly when my webapp and/or tomcat shuts down. i 
expect a clean shutdown to deal with the lock file appropriately. i am 
not too interested in how the lock file is implemented ;)

Re: shutting down repository obtained from jndi via spring

Posted by Tobias Bocanegra <to...@day.com>.
> > The addShutdownHook is still there, but also the static blocks meant for
> > pre-loading the classes. On my machine working with the latest SVN trunk
> > the .lock files are correctly deleted.
>
> hm, i have the latest svn trunk as well, and the lock file is not being
> removed. i don't see any static blocks in RepositoryImpl though.

if it's just about the .lock file,
http://issues.apache.org/jira/browse/JCR-233 suggests a solution with
exclusive file locking. imo, this would be the best option (although
some FS might not support filelocks. encoutered this on some linux
NFS).

Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Alexandru Popescu wrote:

> Brian the static blocks are not in the RepositoryImpl itself. Look at 
> JCR-120 and the suggested patch there. It is integrated, or at least I 
> have found it in my trunk. I have even added some sout statements in the 
> shutdown method and this is called and I am sure .lock files are 
> removed, as it was really annoying for me ;-).

heh, right. ok, i see those. however, i'm still not getting the lock 
files removed - perhaps for the reason mentioned by jukka in comment #6 
of JCR-120.

Re: shutting down repository obtained from jndi via spring

Posted by Alexandru Popescu <th...@gmail.com>.
#: Brian Moseley changed the world a bit at a time by saying on  10/5/2005 6:41 PM :#
> Alexandru Popescu wrote:
> 
>> The addShutdownHook is still there, but also the static blocks meant for 
>> pre-loading the classes. On my machine working with the latest SVN trunk 
>> the .lock files are correctly deleted.
> 
> hm, i have the latest svn trunk as well, and the lock file is not being 
> removed. i don't see any static blocks in RepositoryImpl though.
> 
> i can rig up a debugger to see if specific code is being executed - what 
> should i be looking for?
> 
> i got a little confused by all the discussion earlier in the thread and 
> am not sure if a solution was ever found that wouldn't require me to 
> encode jackrabbit-specific code or configuration within my webapp.
> 
> sorry to seem spacy on this subject. this particular week it's difficult 
> for me to pay close attention to all the various threads on my various 
> mailing lists :/
> 

Brian the static blocks are not in the RepositoryImpl itself. Look at JCR-120 and the suggested 
patch there. It is integrated, or at least I have found it in my trunk. I have even added some sout 
statements in the shutdown method and this is called and I am sure .lock files are removed, as it 
was really annoying for me ;-).

hth,

./alex
--
.w( the_mindstorm )p.


Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Alexandru Popescu wrote:

> The addShutdownHook is still there, but also the static blocks meant for 
> pre-loading the classes. On my machine working with the latest SVN trunk 
> the .lock files are correctly deleted.

hm, i have the latest svn trunk as well, and the lock file is not being 
removed. i don't see any static blocks in RepositoryImpl though.

i can rig up a debugger to see if specific code is being executed - what 
should i be looking for?

i got a little confused by all the discussion earlier in the thread and 
am not sure if a solution was ever found that wouldn't require me to 
encode jackrabbit-specific code or configuration within my webapp.

sorry to seem spacy on this subject. this particular week it's difficult 
for me to pay close attention to all the various threads on my various 
mailing lists :/

Re: shutting down repository obtained from jndi via spring

Posted by Alexandru Popescu <th...@gmail.com>.
#: Brian Moseley changed the world a bit at a time by saying on  10/5/2005 3:15 AM :#
> Alexandru Popescu wrote:
> 
>> The fix for JCR-120 is already in the trunk, if this is the one you are 
>> looking for.
> 
> is it? i still see addShutdownHook in RepositoryImpl, and i *just* updated.
> 

The addShutdownHook is still there, but also the static blocks meant for pre-loading the classes. On 
my machine working with the latest SVN trunk the .lock files are correctly deleted.

./alex
--
.w( the_mindstorm )p.


Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Alexandru Popescu wrote:

> The fix for JCR-120 is already in the trunk, if this is the one you are 
> looking for.

is it? i still see addShutdownHook in RepositoryImpl, and i *just* updated.

Re: shutting down repository obtained from jndi via spring

Posted by Alexandru Popescu <th...@gmail.com>.
#: Brian Moseley changed the world a bit at a time by saying on  10/5/2005 2:10 AM :#
> Brian Moseley wrote:
>> Costin Leau wrote:
>> 
>>> Ofc, the support is already there, I just had to take a close look at
>>> the docs: you can set out expectedType to RepositoryImpl and that
>>> should do the trick (it is part of JndiObjectLocator which is a parent
>>> of JndiObjectFactoryBean).
>> 
>> 
>> ahh.. right on. thanks all.
> 
> this turns out to not be a great solution for me, since i'm trying to be 
> repository vendor agnostic in my spring config. for that reason, using a 
> jackrabbit repository factory bean is not a great solution either, nor 
> is a servlet context listener.
> 
> i hope one of the other suggestions for fixing the lock file is 
> implemented soon, cos it's really stuffing me up right now. everytime i 
> deploy my jcr-using webapp i have to shut down tomcat, rm the lock file 
> manually, and restart tomcat. and we have to script that in production. 
> ouch.
> 

The fix for JCR-120 is already in the trunk, if this is the one you are looking for.

./alex
--
.w( the_mindstorm )p.


Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Brian Moseley wrote:
> Costin Leau wrote:
> 
>> Ofc, the support is already there, I just had to take a close look at
>> the docs: you can set out expectedType to RepositoryImpl and that
>> should do the trick (it is part of JndiObjectLocator which is a parent
>> of JndiObjectFactoryBean).
> 
> 
> ahh.. right on. thanks all.

this turns out to not be a great solution for me, since i'm trying to be 
repository vendor agnostic in my spring config. for that reason, using a 
jackrabbit repository factory bean is not a great solution either, nor 
is a servlet context listener.

i hope one of the other suggestions for fixing the lock file is 
implemented soon, cos it's really stuffing me up right now. everytime i 
deploy my jcr-using webapp i have to shut down tomcat, rm the lock file 
manually, and restart tomcat. and we have to script that in production. 
ouch.

Re: shutting down repository obtained from jndi via spring

Posted by Brian Moseley <bc...@osafoundation.org>.
Costin Leau wrote:

> Ofc, the support is already there, I just had to take a close look at
> the docs: you can set out expectedType to RepositoryImpl and that
> should do the trick (it is part of JndiObjectLocator which is a parent
> of JndiObjectFactoryBean).

ahh.. right on. thanks all.

Re[3]: shutting down repository obtained from jndi via spring

Posted by Costin Leau <co...@gmail.com>.
> I looked over to JndiObjectFactoryBean and the main issue is that you
> need an interface to which to cast to. I will check the forums is
> adding class support is possible to implement in the future.
Ofc, the support is already there, I just had to take a close look at
the docs: you can set out expectedType to RepositoryImpl and that
should do the trick (it is part of JndiObjectLocator which is a parent
of JndiObjectFactoryBean).


-- 
Best regards,
 Costin                            mailto:costin.leau@gmail.com