Hello,
On Wed, Jan 21, 2009 at 06:13:54PM +0100, Alexander Klimetschek wrote:
> Could you post the code for the T1...T3 steps? Maybe something is not
> synchronized there... (just a guess).
>
I created a stripped version where i was able to reproduce the Exception.
My client Code looks like this:
InitialContext ic = new InitialContext();
ItemTest test = (ItemTest)
ic.lookup("item-state-ear-SNAPSHOT/ItemTestBean/remote");
for(int i = 1;i<10;i++){ //often occures the second or third
time
test.createFolder("folderA", false);
test.createFolder("folderA/folderZ", false);
test.remove("folderA", true);
}
It works sometimes and sometimes not.
While remote debugging i noticed that:
SharedItemStateManager line 644 is reached (jackrabbit-core-1.5.0).
This Exception causes also a log statement in jboss' server.log but due
to transaction handling isn't thrown up to the client caller.
My EJB looks like this:[0]
An ear with this EJB and Interface can be found here:
http://www.speutel.de/~moritz/jackrabbit/item-state-ear-SNAPSHOT.ear
Sources here:
http://www.speutel.de/~moritz/jackrabbit/item-state-ejb-SNAPSHOT-sources.jar
http://www.speutel.de/~moritz/jackrabbit/item-state-apis-SNAPSHOT-sources.jar
I also loged some information about the ItemState in the remove method:
00:42:14,499 INFO [ItemTestBean] createFolder:/default/dmsroot/folder3
00:42:14,694 INFO [ItemTestBean] createFolder:/default/dmsroot/folder3/folder
00:42:14,756 INFO [ItemTestBean] state:
org.apache.jackrabbit.core.state.nodest...@b167ca
00:42:14,756 INFO [ItemTestBean] isStale: true
00:42:14,756 INFO [ItemTestBean] state.getModCount: 0
state.overlay.getModeCount: 1
00:42:14,756 INFO [ItemTestBean] state.hashCode: 11626442 ,overlay.hashCode:
1383648
Regards
Moritz
[0]
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ItemTestBean implements ItemTest{
private final static Logger log = Logger.getLogger(ItemTestBean.class);
@Resource(mappedName = "java:jcr/local")
private Repository repository;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void initRepository(){
Session session = null;
try {
session = repository.login(new
SimpleCredentials("rebbert","rebbert".toCharArray()));
Node root = session.getRootNode();
root.addNode("default").addNode("dmsroot", "nt:folder");
session.save();
} catch (Exception e) {
e.printStackTrace();
}finally{
session.logout();
}
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void createFolder(String path, boolean parents) throws Exception
{
Session session = null;
try{
session = repository.login(new
SimpleCredentials("rebbert","rebbert".toCharArray()));
Node root =
session.getRootNode().getNode("default").getNode("dmsroot");
//create parents if needed
String[] split = path.split("/");
Node tmp = root;
for (int i = 0; i < split.length; i++) {
if(tmp.hasNode(split[i])){
if(!isValidFolder(tmp.getNode(split[i])))
throw new
Exception("Can not create directory. Element "+i+" of "+path +"did not exist or
is not a valid");
}else{
if(!(parents || i ==
(split.length -1)))
throw new
Exception("Can not create directory. Element "+i+" of "+path+"isn't last
element nor createParents is set true.");
Node newFolder =
tmp.addNode(split[i],"nt:folder");
log.info("createFolder:"+newFolder.getPath());
}
tmp = tmp.getNode(split[i]);
}
session.save();
} catch (Exception e) {
throw new Exception("createFolder could not be
executed.",e);
}finally{
if(session != null)
session.logout();
}
}
protected boolean isValidFolder(Node node){
try {
return node.isNodeType("nt:folder");
} catch (RepositoryException e) {
return false;
}
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void remove(String path, boolean recursive) throws Exception {
Session session = null;
try{
session = repository.login(new
SimpleCredentials("rebbert","rebbert".toCharArray()));
Node node = getNode( path, session);
// NodeImpl nodeimpl = (NodeImpl)node;
// Method m =
node.getClass().getSuperclass().getDeclaredMethod("getItemState");
// m.setAccessible(true);
// ItemState state = (ItemState)m.invoke(node);
// log.info("state: "+state);
// log.info("isStale: "+state.isStale());
// log.info("state.getModCount:
"+state.getModCount()+" state.overlay.getModeCount:
"+state.getOverlayedState().getModCount());
// log.info("state.hashCode: "+state.hashCode()+"
,overlay.hashCode: "+state.getOverlayedState().hashCode());
if(isValidFolder(node) &&
node.getNodes().getSize() > 0 && !recursive)
throw new Exception("Unable to remove.
Folder isn't empty. To remove set recursive = true",null);
node.remove();
session.save();
} catch (Exception e) {
throw new Exception("Remove could not be executed.",e);
}finally{
if(session != null)
session.logout();
}
}
protected Node getNode( String path, Session session) throws Exception{
try {
Node dmsroot =
session.getRootNode().getNode("default").getNode("dmsroot");
return dmsroot.getNode(path);
} catch (PathNotFoundException e ){
return null;
} catch (RepositoryException e) {
throw new Exception("Error in fetching information from
repository.",e);
}
}
}