cancel
Showing results for 
Search instead for 
Did you mean: 

[Resolved] NodeService doesn't return actual information

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

I need your help to find a bug in my action Smiley Happy

In the action, I want to create one directory, check it exists, if not, I created. To do that :


NodeRef nodeOnDisk = nodeService.getChildByName(parentDirectoy,
               ContentModel.ASSOC_CONTAINS, nameDirectory);
if (nodeOnDisk != null) {
   …
} else {
   FileInfo fileInfo = fileFolderService.create(parentDirectoy,
                  nameDirectory, ContentModel.TYPE_FOLDER);
All work good if I start action with one file. But if I try to use this action in parallel (send two 2 files to start, which will created the same directory). The nodeService say (for the 2 actions) that the directory (nameDirectory) doesn't exist, but after the fileFolderService generate a error because the directory exist. When a action is running, all of the other wait (I use the synchronisation with lock) :
Start 2 action (action_A and actionB) :

(This is a temporal schema)
action_A  ……………………………………. action_B   
begin (get the nodeService)…………………..begin (get the nodeService)
create directory……………………………….wait
finished, signal other action to start    
………………………………………………..awake
………………………………………………..create directory (and error appears)

I think that the nodeService have old information about the store. Has someone an idea to have actual information about nodeService (or another way to do this) ? :?:


More info : The creation directory si done with this kind of transaction :

boolean resultCreateDirectory = transactionService
                     .getRetryingTransactionHelper()
                     .doInTransaction(
                           new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>() {
                              public Boolean execute()
                                    throws Throwable {
                                 CREATE OF DIRECTORY
                              }
                           });
            }

Thanks
4 REPLIES 4

jayjayecl
Confirmed Champ
Confirmed Champ
How do you trigger those actions ?

dranakan
Champ on-the-rise
Champ on-the-rise
Thanks JayJayECL for your reply

I add files by the CIFS. A rule is define on the directory.

jayjayecl
Confirmed Champ
Confirmed Champ
Could you provide us with the full code of the ActionExecuter ?

thank you Smiley Happy

dranakan
Champ on-the-rise
Champ on-the-rise
ok, I have found… The problem was that the commit of the first transaction (in action_A) was not well done…

To add files, i have done like this :
WRONG CODE

Boolean result = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>(){
    public Boolean execute() throws Throwable {
            
      boolean success= methodAddFiles(var);
               if (!success){
                  // Retry and rollback if always problem
                  throw  new IllegalStateException("Problem during adding files");
               }
               return true;
    }  
});
And after one modification :

Boolean result = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>(){
    public Boolean execute() throws Throwable {
            
     boolean success= methodAddFiles(var);
               if (!success){
                  // Retry and rollback if always problem
                  throw  new IllegalStateException("Problem during adding files");
               }
               return true;
    }  
//LOOK HERE
}, false, true);

For details about what do this code, have a look here : http://forums.alfresco.com/en/viewtopic.php?f=4&t=13023#p68351