Calling isWired() prior to publishing a property

Something I noticed when looking at some composite applications is many components blindly publish a property. In some cases this may be fine because there may be generic listeners but in the world of declarative wires (the user assembler chooses communication) you may want to optimize the runtime by seeing if any components are wired to you before publishing your property. This will save a lot of CPU cycles since checking for a wire is a lot quicker then publishing a property onto the queue – which goes through a lot more validation.

Here is a snippet of code you may want to checkout. It checks to see if a specific property for a given owner instance is wired to another component prior to constructing its value and posting the property change.

PropertyBroker broker = PropertyBrokerFactory.getBroker();

if (broker.isWired(prop)){
JSONObject jsonObj = new JSONObject();
jsonObj.append("event", name);
jsonObj.append("", id);

PropertyValue pv = PropertyFactory.createPropertyValue(prop, jsonObj.toString());
broker.changedProperties(new PropertyValue[] { pv }, id);

Tags: : : :


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.