cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with behaviors called several times

eric_k
Champ in-the-making
Champ in-the-making

Hello,

I have been tasked to develop a feature that sends mail to specific users when a document has been modified.
Essentially, I use behavior policies and aspects. Aspect 'subscribable' is used.
I register the event-handler like this :

policyComponent.bindClassBehaviour(
    NodeServicePolicies.OnUpdateNodePolicy.QNAME,
    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "subscribable"),
    new JavaBehaviour(this, "onUpdateNode", NotificationFrequency.TRANSACTION_COMMIT));

My event-handler is like this :
    public void onUpdateNode(NodeRef docNodeRef) {
    ...
    }


My implementation is very close to what is proposed in :
- Reference manual,
- Jeff Potts' tutorial on behaviors.

My issue is : For a simple update (e.g. upload of a new version), the event-handler is called several times.

Why are there several notifications ?

I use Alfresco CE 5.0.d.

Thanks in advance for your help !

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

In this case the user is using the notification frequency TRANSACTION_COMMIT which should ensure the policy is only called once (per affected node) at the end of the transaction regardless of how often the node is updated during the transaction.

View answer in original post

6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator

OnUpdateNodePolicy behaviours will be called every time you add/remove aspect ,set node type,add/remove/update property . So please check your operation carefully whether your operation fall into those categories

afaust
Legendary Innovator
Legendary Innovator

In this case the user is using the notification frequency TRANSACTION_COMMIT which should ensure the policy is only called once (per affected node) at the end of the transaction regardless of how often the node is updated during the transaction.

openpj
Elite Collaborator
Elite Collaborator

If you are using Alfresco Share probably when you drop new content, Share will update the node for creating new association instances for thumbnail and preview content.

eric_k
Champ in-the-making
Champ in-the-making

Thanks for your answers,

As Axel said, with the notification frequency TRANSACTION_COMMIT, I expect the event-handler to be called only once.

That is not what I see in the logs.

eric_k
Champ in-the-making
Champ in-the-making

Hello,

For those who are interesed in policies and behaviors, I made tests with following behaviors. I wanted to knwo what behaviors are triggered by document related events.

- ContentServicePolicies.OnContentUpdatePolicy

- ContentServicePolicies.OnContentPropertyUpdatePolicy

- NodeServicePolicies.OnUpdateNodePolicy

- NodeServicePolicies.OnUpdatePropertiesPolicy

The table shows the results :

afaust
Legendary Innovator
Legendary Innovator

One note of caution: This only applies to an unmodified. uncustomized installation of Alfresco without any custom rules, behaviours, web scripts and/or services set up that could in turn trigger additional behaviours with the changes they are applying to nodes. There is no guarantee for this observation to hold true between different Alfresco versions either as behaviour of Alfresco web scripts / APIs for Share UI actions may be changed due to feature changes or simple bug fixes.