cancel
Showing results for 
Search instead for 
Did you mean: 

Is controller in webscript framework asynchronous?

bilalsaeed
Confirmed Champ
Confirmed Champ

As per my observation controller in Alfresco Webscript isn't asynchronous. My view need to render dynamic data elements for that my controller need to be asynchronous. How can I achieve such behavior in Alfresco? I am working on JavaScript based webscript. 

5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator

Simply perform an AJAX in your client-side logic to call the web script when you need it instead of calling it (as I assumed you are doing right now) as part of the page render cycle. Since you have not provided any kind of context information about the use case and what technologies you are using on the client-side (Share YUI, Aikau, ADF, custom framework) it is a bit hard to give you more pointers without doing most of the work for you...

In my case client side is another webscript. It's a two way communication between two webscripts. One of my webscripts render the nodes from Alfresco using search api and other webscript is called by first webscript to post data to Alfresco and once the data is posted it callbacks the previous webscript. 

afaust
Legendary Innovator
Legendary Innovator

There should never be a two-way, direct communication between two web scripts. Usually the only communication between web scripts is when a Share-tier web script calls a Repository-tier web script. It sounds like both are located on the Repository-tier. Is there a problem that prevents you from just merging the functionality into a single web script? Alternatively - if you don't want to end up with a massive web script - you can extract your logic to library JS files or even into Java components (which typically have higher performance). If you need to do some part of your logic asynchronously, you might also want to look into converting your code into action-based components. Actions can be triggered for asynchronous execution (when the transaction completes) and can trigger other actions in their implementation, e.g. for follow-up logic that might now be handled in your "callback".

Logic just can't be merged into a single WS. As one WS is based on get requests and other one is handling post request made by first WS. Problem lies when get based WS is called it uses alfresco search based on particular path and become a victim of eventual consistency. If controller would be asynchronous it could update the view as soon as recently added node make itself available to search result. 

afaust
Legendary Innovator
Legendary Innovator

If eventual consistency is an issue and your operations require transactional consistency, then you should consider changing either your query or general approach to make use of transactionally safe queries. This might require splitting a query in one or two partial ones, introduction of metadata that can be queried e.g. instead of PATH, or just a simple rewrite of queries to activate exact matching instead of likeness / wildcards.

If none of the above is an option, you should think about other architectural approaches. A two-way communication / dependency can simply be resolved into multiple one-way communications ny introducing an orchestrator for the operation, e.g. as an external client.