You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by lists <li...@digby.net> on 2005/08/25 16:37:15 UTC

ClassCastException when getting Repository from InitialContext (Sorry if this is a repost)

Hi,

Another query:

I've set up Jackrabbit to run in Tomcat 5.5 and have set up the resource 
in server.xml and context.xml. All looks good. I can get the 
BindableRepository back from the context, but I can't cast it to a 
javax.jcr.Repository.

The weird thing is, if I cast to an object, I can see that is is a 
BindableRepository, I can see that one of the interfaces it implements 
is Repository, i.e.

InitialContext context = new InitialContext();
Context environment = (Context) context.lookup("java:comp/env");
Object repository = (Object) environment.lookup("jcr/repository");
out.println(repository.getClass().getGenericInterfaces()[0]);

gives "interface javax.jcr.Repository"

But

out.println(repository instanceof javax.jcr.Repository);

gives false

And the cast causes a ClassCastException. Can anyone shed any light on 
this? Is it something to do with the BindableRepository having default 
access?

Many thanks,

Digby


Re: 'Lock obtain timed out' and redo log

Posted by Marcel Reutegger <ma...@gmx.net>.
Dave Sag wrote:
> how exactly do you make sure that jackrabbit is stopped.  we have  been 
> getting this same warning after running unit tests of our code.

RepositoryImpl.shutdown() will shutdown everything smoothly.

There is also a safety net built into the RepositoryImpl class which is 
basically a shutdown hook that is registered. but it seems that there 
are cases where that hook is not called.

anyway, explicitly calling shutdown() is in my opinion the prefered way 
to stop the repository.

regards
  marcel

Re: 'Lock obtain timed out' and redo log

Posted by Dave Sag <ds...@visualitylife.com>.
On 26/08/2005, at 10:10 AM, Marcel Reutegger wrote:
> The search index is tied to a workspace. therefore closing a  
> session has no effect on the index.
> To prevent messages like above you have to make sure that  
> jackrabbit is stopped properly when your server shuts down.


how exactly do you make sure that jackrabbit is stopped.  we have  
been getting this same warning after running unit tests of our code.

dave


Re: 'Lock obtain timed out' and redo log

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Christine,

Christine Morineau wrote:
> Sometimes, I get a  javax.jcr.RepositoryException: Lock obtain timed out
> when for exemple the application try to add a Node in the workspace. My
> repository seems to be unreachable.

There are two reasons why this can happen.

- you are using a an old build jackrabbit (svn < 216142 / juli 13). the 
indicated revision contains a fix in case a commit lock is left behind.

- two repositories instances are running on the same directory

> I also get the message 'found uncommited redo log...' (and even twice).

this happens when the jvm quits without shutting down jackrabbit. If you 
get the message you mentioned twice, that means you have two workspaces 
or jackrabbit instances with uncommited index changes. usually the 
search index can easily recover from this situation, unless the 
underlying workspace data is corrupt.

> I presume that my search index is not closed properly. But how to close it
> properly?

That's usually the duty of the application server or servlet engine, 
which manages resources.

> Is a session.logout() enough and where should i put it?

The search index is tied to a workspace. therefore closing a session has 
no effect on the index.
To prevent messages like above you have to make sure that jackrabbit is 
stopped properly when your server shuts down.

regards
  marcel

'Lock obtain timed out' and redo log

Posted by Christine Morineau <ch...@bull.net>.
Hi all,

Sometimes, I get a  javax.jcr.RepositoryException: Lock obtain timed out
when for exemple the application try to add a Node in the workspace. My
repository seems to be unreachable.

Do you know why I get this error and what to do not to have it again.
The trace of the error is at the end.

I also get the message 'found uncommited redo log...' (and even twice).
I presume that my search index is not closed properly. But how to close it
properly?
Is a session.logout() enough and where should i put it?

Thanks
regards
christine


javax.jcr.RepositoryException: Lock obtain timed out: Lock@commit.lock: Lock
obtain timed out: Lock@
commit.lock: Lock obtain timed out: Lock@commit.lock
        at
org.apache.jackrabbit.core.SearchManager.<init>(SearchManager.java:124)
        at
org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.getSearchManager(Rep
ositoryImpl.j
ava:1130)
        at
org.apache.jackrabbit.core.RepositoryImpl.getSearchManager(RepositoryImpl.ja
va:536)
        at
org.apache.jackrabbit.core.RepositoryImpl.initWorkspace(RepositoryImpl.java:
398)
        at
org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:293)
        at
org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:344)
        at
org.apache.jackrabbit.core.jndi.BindableRepository.init(BindableRepository.j
ava:116)
        at
org.apache.jackrabbit.core.jndi.BindableRepository.create(BindableRepository
.java:104)
        at
org.apache.jackrabbit.core.jndi.RegistryHelper.registerRepository(RegistryHe
lper.java:57)

        at bsoa.resourceAdapter.RepositoryResourceAdapter.start(Unknown
Source)
        at org.objectweb.jonas.resource.Rar.processRar(Rar.java:546)
        at
org.objectweb.jonas.resource.ResourceServiceImpl.createResourceAdapter(Resou
rceServiceImp
l.java:639)
        at
org.objectweb.jonas.resource.ResourceServiceImpl.doStart(ResourceServiceImpl
.java:489)
        at
org.objectweb.jonas.service.AbsServiceImpl.start(AbsServiceImpl.java:80)
        at
org.objectweb.jonas.service.ServiceManager.startServices(ServiceManager.java
:336)
        at org.objectweb.jonas.server.Server.start(Server.java:499)
        at org.objectweb.jonas.server.Server.main(Server.java:169)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.objectweb.jonas.server.Bootstrap.main(Bootstrap.java:97)
Caused by: java.io.IOException: Lock obtain timed out: Lock@commit.lock
        at org.apache.lucene.store.Lock.obtain(Lock.java:58)
        at org.apache.lucene.store.Lock$With.run(Lock.java:108)
        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:228)
        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:213)
        at
org.apache.jackrabbit.core.query.lucene.AbstractIndex.getIndexWriter(Abstrac
tIndex.java:1
47)
        at
org.apache.jackrabbit.core.query.lucene.AbstractIndex.addDocument(AbstractIn
dex.java:102)

        at
org.apache.jackrabbit.core.query.lucene.MultiIndex.addNodePersistent(MultiIn
dex.java:477)

        at
org.apache.jackrabbit.core.query.lucene.MultiIndex.<init>(MultiIndex.java:20
9)
        at
org.apache.jackrabbit.core.query.lucene.SearchIndex.doInit(SearchIndex.java:
83)
        at
org.apache.jackrabbit.core.query.AbstractQueryHandler.init(AbstractQueryHand
ler.java:39)
        at
org.apache.jackrabbit.core.SearchManager.<init>(SearchManager.java:122)
        ... 21 more
java.io.IOException: Lock obtain timed out: Lock@commit.lock
        at org.apache.lucene.store.Lock.obtain(Lock.java:58)
        at org.apache.lucene.store.Lock$With.run(Lock.java:108)
        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:228)
        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:213)
        at
org.apache.jackrabbit.core.query.lucene.AbstractIndex.getIndexWriter(Abstrac
tIndex.java:1
47)
        at
org.apache.jackrabbit.core.query.lucene.AbstractIndex.addDocument(AbstractIn
dex.java:102)

        at
org.apache.jackrabbit.core.query.lucene.MultiIndex.addNodePersistent(MultiIn
dex.java:477)

        at
org.apache.jackrabbit.core.query.lucene.MultiIndex.<init>(MultiIndex.java:20
9)
        at
org.apache.jackrabbit.core.query.lucene.SearchIndex.doInit(SearchIndex.java:
83)
        at
org.apache.jackrabbit.core.query.AbstractQueryHandler.init(AbstractQueryHand
ler.java:39)
        at
org.apache.jackrabbit.core.SearchManager.<init>(SearchManager.java:122)
        at
org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.getSearchManager(Rep
ositoryImpl.j
ava:1130)
        at
org.apache.jackrabbit.core.RepositoryImpl.getSearchManager(RepositoryImpl.ja
va:536)
        at
org.apache.jackrabbit.core.RepositoryImpl.initWorkspace(RepositoryImpl.java:
398)
        at
org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:293)
        at
org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:344)
        at
org.apache.jackrabbit.core.jndi.BindableRepository.init(BindableRepository.j
ava:116)
        at
org.apache.jackrabbit.core.jndi.BindableRepository.create(BindableRepository
.java:104)
        at
org.apache.jackrabbit.core.jndi.RegistryHelper.registerRepository(RegistryHe
lper.java:57)

        at bsoa.resourceAdapter.RepositoryResourceAdapter.start(Unknown
Source)
        at org.objectweb.jonas.resource.Rar.processRar(Rar.java:546)
        at
org.objectweb.jonas.resource.ResourceServiceImpl.createResourceAdapter(Resou
rceServiceImp
l.java:639)
        at
org.objectweb.jonas.resource.ResourceServiceImpl.doStart(ResourceServiceImpl
.java:489)
        at
org.objectweb.jonas.service.AbsServiceImpl.start(AbsServiceImpl.java:80)
        at
org.objectweb.jonas.service.ServiceManager.startServices(ServiceManager.java
:336)
        at org.objectweb.jonas.server.Server.start(Server.java:499)
        at org.objectweb.jonas.server.Server.main(Server.java:169)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.objectweb.jonas.server.Bootstrap.main(Bootstrap.java:97)


Re: ClassCastException when getting Repository from InitialContext (Sorry if this is a repost)

Posted by Tobias Bocanegra <to...@gmail.com>.
hi Digby,
the problem is, that the classloader that creates the repository uses
another jcr-1.0.jar than the classloader that looks up the repository.

make sure that the jcr-1.0.jar is located in the
$CATALINA_HOME/shared/lib. then all classloaders should use this one.

cheers, tobi

On 8/25/05, lists <li...@digby.net> wrote:
> Hi,
> 
> Another query:
> 
> I've set up Jackrabbit to run in Tomcat 5.5 and have set up the resource
> in server.xml and context.xml. All looks good. I can get the
> BindableRepository back from the context, but I can't cast it to a
> javax.jcr.Repository.
> 
> The weird thing is, if I cast to an object, I can see that is is a
> BindableRepository, I can see that one of the interfaces it implements
> is Repository, i.e.
> 
> InitialContext context = new InitialContext();
> Context environment = (Context) context.lookup("java:comp/env");
> Object repository = (Object) environment.lookup("jcr/repository");
> out.println(repository.getClass().getGenericInterfaces()[0]);
> 
> gives "interface javax.jcr.Repository"
> 
> But
> 
> out.println(repository instanceof javax.jcr.Repository);
> 
> gives false
> 
> And the cast causes a ClassCastException. Can anyone shed any light on
> this? Is it something to do with the BindableRepository having default
> access?
> 
> Many thanks,
> 
> Digby
> 
> 


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97 
-----------------------------------------------< http://www.day.com >---