Created

Jan 10, 2013

Using Event filters for handling JCR events through an event handler.

Posted by Nicolas Peltier

In a previous post, i was explaining how to handle events generally, with several solutions among which:

  • jcr observer
  • sling event handler

a distinction was made between both around the fact jcr observers are low level, but allow to do more. While this is still true :-) this POST will explain how to do a fine-grained jcr event listening through sling event handler (and take profit of the sling event handling framework for those events).

While in jcr, everything is content, in sling, everything is a resource, so instead of listening to node/property added/removed we'll listen to resource changed, through the 3 topics :

  1. SlingConstants.TOPIC_RESOURCE_ADDED,
  2. SlingConstants.TOPIC_RESOURCE_CHANGED,
  3. SlingConstants.TOPIC_RESOURCE_REMOVED

Now we should have a handler that listens for all the repository, for those -very common- events, which will certainly be a performance killer. Thus we need to filter out this by adding osgi event filtering

This EventConstants.EVENT_FILTER property takes LDAP filter syntax, and has a path attribute, so we can do e.g. (path=/content/my/root/*) or even (path=/content/my/root/*/myNode).

 

A sample code would then be :

@Component
@Service(value=EventHandler.class)
@Properties({
 @Property(name= EventConstants.EVENT_TOPIC,value= {SlingConstants.TOPIC_RESOURCE_ADDED,SlingConstants.TOPIC_RESOURCE_CHANGED, SlingConstants.TOPIC_RESOURCE_REMOVED}),
 @Property(name=EventConstants.EVENT_FILTER,value="(path=/content/my/root/*/myNode)")
})
public class ExampleServiceImpl implements EventHandler { 
 final String[] eventProps = { "resourceAddedAttributes", "resourceChangedAttributes", "resourceRemovedAttributes" };

 public void handleEvent(org.osgi.service.event.Event event) {
  for (String eventProp : eventProps){
   String[] props = (String[])event.getProperty(eventProp);
   …
 }		
}

Pros of this approach vs. Jcr Observer are : 

  • this is simpler.
  • this is cluster ready.
  • you have the user id information in it (userid attribute of the event).

A con i can see is that in the particular case of a bulk save done of N concerned resources, your handler will be called N times, and then if your handler does persist, you'll have a total of N (handler persistences) + 1 (bulk save) persistences done. While with a jcr observer, you can loop through all the changes of the transaction, and do another batch save, reducing the persistences to 2.

COMMENTS

  • By how can i make guys fall for me - 12:36 PM on Apr 04, 2014   Reply
    As always, if you have a question about WMSW that isn't answered in one of the posts on this What Men Secretly Want review site, I field questions at the following email: kaleyjuniper (at) gmail.com and will do my best to get back to you ASAP. Sometimes it may take me a few days, but if you put "What Men Secretly Want (or Be Irresistible) Question" in the title of your email, it will help me find it and respond quicker.
    • By Paket Pernikahan - 4:45 AM on Apr 06, 2014   Reply
      i really to say nice tools from adobe. i like it.
      • By surf wallpaper - 10:12 AM on Apr 09, 2014   Reply
        Nice information. Thank you for sharing it with us!
        • By Short Layered Hairstyles - 4:35 PM on Apr 10, 2014   Reply
          Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!
          • By pengertian kebugaran jasmani - 6:42 AM on Apr 15, 2014   Reply
            i love this content
          • By Cuci Sofa - 2:35 PM on Apr 04, 2014   Reply
            Thanks.
            • By Watch Movie Online Without Downloading. - 4:36 PM on Apr 04, 2014   Reply
              Nice information for<US>Today
              • By Jasa SEO - 4:07 AM on Apr 05, 2014   Reply
                Many Thanks.
                • By go ahead with this site - 4:12 PM on Apr 09, 2014   Reply
                  This is now so much updated. I was using the old version and now switched to this new version.
                • By pregnancy miracle pdf download - 9:32 AM on Apr 05, 2014   Reply

                  A motivating discussion is definitely worth comment.I do think that you ought to publish more on this topic, it might not be a taboo matter but typically people do not discuss these subjects.To the next! Many thanks!!
                  • By Dog Grooming Singapore - 10:54 AM on Apr 05, 2014   Reply
                    Roy Tan & Nichelle Tan have been involved in pet care and the grooming trade
                    for more than 8 years. Both Roy Tan & Nichelle Tan are certified groomers
                    from the prestigious International Kennel Club of Taiwan (KCT).
                    • By sulfate free shampoo - 1:07 PM on Apr 05, 2014   Reply
                      A motivating discussion is definitely worth comment.I do think that you ought to publish more on this topic, it might not be a taboo matter but typically people do not discuss these subjects.To the next! Many thanks!!
                      • By Jasa SEO - 3:40 PM on Apr 05, 2014   Reply
                        Thanks.
                        • Wow! This can be one particular of the most beneficial blogs we have ever arrived across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your hard work.
                          • By Timber Merchants Liverpool - 7:30 AM on Apr 06, 2014   Reply
                            Zest is the secret of all beauty. There is no beauty that is attractive without zest.
                            • By christian h. girlfriend system - 11:25 AM on Apr 06, 2014   Reply
                              the Girlfriend Activation step-by-step system, no girl is out of your league so you can actually CHOOSE who you want to be with instead of settling for a girl you only kind of like because you think she won't reject you. As the author says.
                              • By ecift.com - 9:33 AM on Apr 17, 2014   Reply
                                Art education that is experienced during art classes for kids develops self-esteem, appreciation of the work of others, self-expression, cooperation with others, and critical thinking skills. Thanks for sharing such useful post with us.
                              • By i want my ex back how do i do it - 12:27 PM on Apr 07, 2014   Reply
                                New Michael Fiore Text Your Ex Back 2.0 System Brings Improved Results For Users. Michael Fiore has released his new Text Your Ex Back 2.0 system which teaches men and women how to use texts sent from a cell phone to turn positive experiences and memories into psychological triggers that elicit attraction and desire in an ex.Additional information on the Michael Fiore Text Your Ex Back guide can be found at http://www.prlog.org/11925915-new-michael-fiore-text-your-ex-back-20-system-brings-improved-results-for-users.html
                                • By final expense leads - 6:24 PM on Apr 07, 2014   Reply
                                  Nice tutorial . Really very helpful .Thank you.
                                  • By Seo Omega - 8:51 AM on Apr 09, 2014   Reply
                                    When you are looking forward to be the finest SEO expert in this internet industry then all you need is this SEO Omega. It will teach you all the tactics and secrets of the SEO world.
                                    • By Amazon fire TV Unbox review - 2:56 AM on Apr 10, 2014   Reply
                                      I look that you give great information forus Today
                                      • By venus factor system review - 5:18 AM on Apr 10, 2014   Reply
                                        Written for consumers by a consumer, this site includes a fun and informative Venus Factor System review and buyers guide that provides an insider's look at the program and answers frequently asked questions about John Barban's unique and highly popular 12-week system for helping women burn away fat and shape ultra-fit, super sexy bodies.
                                        • By Pakar SEO - 12:03 PM on Apr 10, 2014   Reply
                                          Thanks.
                                          • By Peluang Usaha Waralaba Loundry Kiloan - 9:54 AM on Apr 11, 2014   Reply
                                            Thanks.
                                                      • By strawberry blonde hair - 11:50 PM on Apr 11, 2014   Reply
                                                        Nice tutorial . Really very helpful .Thank you.
                                                        • By Strategi Pemasaran - 5:14 AM on Apr 12, 2014   Reply
                                                          Thanks.
                                                          • By Airul - 6:15 AM on Apr 12, 2014   Reply
                                                            Thanks.
                                                            • By Tidung - 6:44 AM on Apr 12, 2014   Reply
                                                              Thanks.
                                                              • By relatiegeschenk telefoon - 8:29 AM on Apr 12, 2014   Reply
                                                                I just wanted to add a comment here to mention thanks for you very nice ideas. I appreciate when I see well written material.
                                                                • By truth about cellulite - 5:44 AM on Apr 13, 2014   Reply
                                                                  Written for consumers by a consumer, this site includes a fun and informative Truth About Cellulite review and buyers guide that provides an insider's look at the program and answers frequently asked questions about Joey Atlas' unique and highly popular cellulite removal system.
                                                                  • By honey - 5:16 AM on Apr 14, 2014   Reply
                                                                    What beauty is, I know not, though it adheres to many things.
                                                                    <a href="http://www.empoweringhomebusiness.com">http://empoweringhomebusiness.com</a>|<a href="http://www.legalprecedence.com">http://legalprecedence.com</a>|<a href="http://www.electrischeautokopen.com">http://electrischeautokopen.com</a>|<a href="http://www.mobileeducationtools.com">http://mobileeducationtools.com</a>|<a href="http://www.numareshealth.com">http://numareshealth.com</a>
                                                                      • By Wooden Door Frames - 8:19 AM on Apr 14, 2014   Reply
                                                                        I am so happy to read this. This is the kind of manual that needs to be given
                                                                        and not the random misinformation that's at the other blogs. Thanks for sharing this.
                                                                        • By blonde hair colors - 2:15 PM on Apr 14, 2014   Reply
                                                                          i am so happy to read this. This is the kind of manual that needs to be given
                                                                          and not the random misinformation that's at the other blogs. Thanks for sharing this.
                                                                          • By blonde hair colors - 2:17 PM on Apr 14, 2014   Reply
                                                                            am so happy to read this. This is the kind of manual that needs to be given
                                                                            and not the random misinformation that's at the other blogs. Thanks for sharing this.
                                                                            • By bh uden ryg - 5:32 AM on Apr 15, 2014   Reply
                                                                              Your website is so cool. I am impressed by the info that you have on this site. It reveals how nicely you understand this subject.
                                                                              • By zelfklevende plak beha - 7:16 AM on Apr 15, 2014   Reply
                                                                                This is a very good story I wanted to read something like this approximately two months ago, please continue putting in here articles like those.
                                                                                • By ebook - 4:04 PM on Apr 15, 2014   Reply
                                                                                  Millionaire Magnet System: Adrian Adair Reveals His Simple, Rejection-Proof Attraction Formula For Meeting, Attracting, And Dating Super Successful (And Rich) Men... Written for consumers by a consumer, this fan site includes a fun and informative Millionaire Magnet review, ebook FAQ, and PDF download guide that provides an insider's look at the program and answers frequently asked questions about Adrian Adair's unique and highly popular dating and attraction guide. Please visit: https://www.rebelmouse.com/millionairemagnetreviews/ ...
                                                                                  • By Sydney SEO - 4:07 PM on Apr 15, 2014   Reply
                                                                                    SEO services from the best Australian SEO Company in Brisbane & Sydney. Please visit: http://www.ranklogix.com.au ...
                                                                                    • By SEO Company - 4:10 PM on Apr 15, 2014   Reply
                                                                                      SEO services from the best Australian SEO Company in Brisbane & Sydney. Please visit for more information: http://www.expertseoconsultant.com.au/ ...
                                                                                      • By Raspberry ketones video - 4:14 PM on Apr 15, 2014   Reply
                                                                                        Raspberry ketone has become a very popular weight loss solution, and is known as being one of the few all natural supplements for losing weight. Raspberry ketones has received plenty of major media coverage about the success consumers are having with losing weight. With the health craze that has swept the nation for some years now, all natural weight loss supplements are very big items, especially when they have shown to be effective like raspberry ketones. Raspberry ketones actually are is enzymes that help to promote burning fat by increasing the metabolism. please visit: http://www.youtube.com/watch?v=dnFag9Hsb5M ...
                                                                                        • By Buy Facebook Fans - 3:47 PM on Apr 16, 2014   Reply
                                                                                          Bottom line is, I didn't return to Apple to make a fortune. I've been very lucky in my life and already have one. When I was 25, my net worth was $100 million or so. I decided then that I wasn't going to let it ruin my life. There's no way you could ever spend it all, and I don't view wealth as something that validates my intelligence.
                                                                                          • By text your ex back reviews - 4:34 AM on Apr 17, 2014   Reply
                                                                                            Below you will find the important facts and figures I feel every consumer should know surrounding Kyle Leon's Somanabolic Muscle Maximizer book and advanced workout guide for building muscle and getting ripped.
                                                                                            • By Buy Vine Followers - 4:28 PM on Apr 17, 2014   Reply
                                                                                              Orders will be completed within 4 days. We are the social media professionals with years of experience. If you want an outstanding service at a low price, place your order.
                                                                                              • By capture his heart - 6:24 PM on Apr 17, 2014   Reply
                                                                                                The easy to implement concepts and techniques taught in the Capture His Heart system are designed to help you get inside a man's mind, body, and soul so you can make him fall in love with you, commit to you, and connect with you on a deep, emotional, and primal level.
                                                                                                • By علاج الادمان - 10:45 PM on Apr 17, 2014   Reply
                                                                                                  Nice tutorial . Really Thank you.
                                                                                                  • By zelfklevende plak beha - 5:57 AM on Apr 18, 2014   Reply
                                                                                                    I just read through the entire article of yours and it was quite good. This is a great article thanks for sharing this informative information. Its really good article i fully read this content..
                                                                                                    • By klebe bh - 10:35 AM on Apr 18, 2014   Reply
                                                                                                      Great info. I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing

                                                                                                      ADD A COMMENT