cancel
Showing results for 
Search instead for 
Did you mean: 

ContentServicePolicies.OnContentReadPolicy implementation

jmliege
Champ in-the-making
Champ in-the-making
Hi,

I've managed to trap when a content is being read through the implementation of the interface ContentServicePolicies.OnContentReadPolicy like the following…


public MyClass implements ContentServicePolicies.OnContentReadPolicy
{

   private PolicyComponent policyComponent;

   private NodeService nodeService;

   public static QName CONTENT_READ =                     QName.createQName(NamespaceService.ALFRESCO_URI,"onContentRead");
    
   //Setters for PolicyComponent & NodeService.
   public void set…..
   …..
   …..

   public void init()
  {
      this.policyComponent.bindClassBehaviour(CONTENT_READ,
                                      MyModel.ASPECT_TEST,
                    new JavaBehavior(this,"onContentRead"));
   }
  

   public void onContentRead(NodeRef nodeRef)
  {
         nodeService.setProperty(nodeRef,ContentModel.PROP_NAME,"test");
   }

}

Everything is fine until I reach the nodeService.setProperty()

I always have an IndexerException… with the message :"the indexer is unable to accept more work : the indexer is preparing to commit".

In fact, it seems that changing properties, writing content (in another content node), … logically crashes as there are many event triggered at the same time…

I don't know what i 'm able to do (permit) exactly.Is it really normal ?

To summarize: What are the limitations of this onContentReadPolicy?

EDIT: I think i will try to do it with speficiying the NotificationFrequency with a value of TRANSACTION_COMMIT… and not on EVERY_EVENT.

Thanks for any help.

JMarc
1 REPLY 1

jmliege
Champ in-the-making
Champ in-the-making
First of all, the index problem is not.
In fact, the code must be surrounded by a dummy try/catch as this Index exception will always be triggered.

Still i had an unexpected crash after, but this one came out of my bean definition.

My db was corrupted after those crashes (even when i delete the node, it remains in the database under archive store)


<bean id="myBean" class="org.test.MyClass" init-method="init">
       <property name="nodeService">
          <ref bean="NodeService"/>
       </property>
       <property name="policyComponent">
          <ref bean="policyComponent"/>
       </property>
       <property name="authenticationComponent">
          <ref bean="authenticationComponent"/>
       </property>
    </bean> 
[code]

You can see a reference to the 'NodeService' bean…it's a mistake, I should have used the following :  :oops:

[code]
<property name="nodeService">
          <ref bean="nodeService"/>
</property>

Yes, the lowercase version of 'nodeService' must be injected instead of the Uppercase version.

As far as I understood (from support), the 'NodeService' wraps a transaction on every function call, the 'nodeService' version not.

My problem can be resume as a clash between transactions.

Hope it will helps for other.

Best regards.