Set OSGi Component properties dynamically using OCD - Use case with Sling ResourceChangeListener
This post demonstrates the use of Object Class Definition(OCD) in setting the OSGi component properties.
In general, per OSGi R6 annotations and above, we can set OSGi component properties via
- property attribute of @Component annotation (Static values) or
- Dynamically using @ObjectClassDefinition together with @AttributeDefinition (property amends in run time via Config Admin or /system/console/configMgr)
- AttributeDefinition should be framed such that it evaluates to the property name correctly (underscores are converted to dots/period)
- Association of OCD with OSGi component happens via annotation named @Designate
Example : Component properties like service.ranking and in case of specific implementations like say WorkflowProcess, we set property named process.label and for EventHandler, it is EventConstants.EVENT_TOPIC and examples add on in a similar fashion for any OSGi Component for that matter.
In order to illustrate this, I would like to consider Sling ResourceChangeListener which expects the PATHS (mandatory property) to which it should listen to and optional CHANGES (added/removed/changed) and PROPERTY_NAMES_HINT (property name on the resource)
Now for amending properties dynamically via Config Admin, we can create OCD in a separate file or within the same OSGi component.
In this case, ResourceChangeListener.PATHS is a field for the constant value - resource.paths. Hence @AttributeDefinition would be resource_paths(). Same way for other two properties.
Complete code snippet :
On a long run, if we are to move to AEM as a Cloud service, this use case of dynamically amending properties via Config Admin/run time changes will not be applicable. However, if there is a situation of run mode specific OSGi component properties needs, then we can create OSGi config like we usually do for custom properties. (code level changes/ no run time)
Using the same example,
- Generic config listens for change of jcr:lastModified property on specified Asset resource.
- Author listens for change of cq:lastModified property on specified Page resource
I had a chance to respond to similar query in the Community, sharing the respective thread for reference - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/multiple-paths-handling-in-eventhandler-not-working/m-p/426921




https://beautyplus.rauabm.org.in
ReplyDeleteCoin Development Company Coin Development Company is a trusted partner in cryptocurrency development, offering expert team, tailored solutions, innovative technology, security, and comprehensive support. We specialize in coin creation, token development, smart contracts, and blockchain consulting. Our team focuses on staying ahead of the curve, ensuring your coin stands out in the market, and providing ongoing maintenance and updates to keep your coin running smoothly.
ReplyDelete"This is a very insightful post! Understanding how to use OCD dynamically with OSGi components makes customization much easier."
ReplyDeleteSpices Distributorship
Chinese Restaurant Franchise
"Thanks for explaining the process with such clarity. Sling ResourceChangeListener integration is a great example!"
ReplyDeleteCentrifugal Blowers
Rotary Air Locks in India
"I was looking for a practical use case of dynamically setting OSGi properties—this article is perfect!"
ReplyDeletestructural-steel tubes distributors gurgaon
MS sheet distributors in Indore
"Great article! Can you also elaborate on how this approach compares to using static configurations?"
ReplyDeletetubular screw conveyorfeeder in rudrapur
vibro sifter gyro screens in rudrapur
"Dynamic property setting in OSGi opens up so many possibilities. Thanks for sharing this example!"
ReplyDeletecyclone type dust collector ludhiana
axial flow fans bawal
"The step-by-step breakdown is very helpful. It simplifies an otherwise complex topic."
ReplyDeleteFranchise show Delhi
modular office furniture gurgaon
"Would love to see more real-world examples of where this method can be applied."
ReplyDeletecnc wood cutting machine in delhi
industiral conveyor
"This post clarified a lot of confusion I had about OSGi Component configurations. Thanks!"
ReplyDeleteoven conveyor system manufacturer
PVC Conveyor belt Manufacturer
"Amazing write-up! Can this method also be applied to non-Sling-related OSGi components?"
ReplyDeletemezzanine floor faridabad
heady duty rack bhiwadi
"Dynamic OCD settings are a game-changer for developers. Thanks for highlighting this use case."
ReplyDeletecantilever rack jaipur
slotted angle rack mumbai
"I appreciate the detailed explanation. Could you add a section on common pitfalls and how to avoid them?"
ReplyDeleteRack Manufacturer in India
cantilever rack
"Very well written! The example with Sling ResourceChangeListener made the concept clear."
ReplyDeletemezzanine floor
mobile compactor in noida
"This is exactly what I needed for my project. Thank you for such a clear and concise guide!"
ReplyDeleteindustrial rack In gurgaon
industrial storage rack in ghaziabad
"Fantastic post! How does this impact performance in large-scale applications?"
ReplyDeleteCentrifugal Blowers
Distributorship Opportunities
"I learned something new today. Thank you for making dynamic OSGi properties so accessible."
ReplyDeletePickle Distributorship
Ice Cream Parlour Franchise
The LDPE shrink film has one of the most significant manners in providing good holding force along with good tear resistance and stretching ability. The shrinkage rate is considered moderate, shrinkage is not as dramatic as polyolefin, yet LDPE will still conform tightly to different shapes and sizes of packages.
ReplyDeleteFamily Tree Now is a powerful online platform designed to help individuals discover, organize, and preserve their family history with ease. It enables users to explore ancestral connections, build detailed family trees, and access publicly available records to better understand their lineage. With an intuitive interface and research-focused tools, FamilyTreeNow simplifies genealogical exploration for beginners and experienced researchers alike, making it easier to trace relationships, uncover historical insights, and document family stories across generations. You can also create family tree by using Family Tree Maker.
ReplyDeleteThis is a very informative and well-explained article for anyone researching the Noida real estate market. Noida has rapidly developed into one of the most attractive destinations in Delhi NCR for both homebuyers and investors, particularly because of its excellent connectivity, upcoming infrastructure, commercial growth, and availability of premium residential developments. Buyers searching for luxury apartments in Noida now have several options across prime sectors, while those looking for ultra luxury flats near Noida Expressway can benefit from the growing demand and strong connectivity offered by this corridor. For families, professionals, and investors, a ready to move property in Noida can also be an attractive choice because it allows buyers to inspect the actual property, amenities, location, and surrounding infrastructure before making a decision. Similarly, buyers specifically looking for a 3 BHK luxury apartment in Noida should compare factors such as carpet area, floor plan, amenities, developer reputation, connectivity, and future appreciation potential. The premium segment has also seen increasing interest in luxury apartments in Noida above 3 crore, especially among buyers who want spacious residences, high-end amenities, premium locations, and a lifestyle-oriented community. From an investment perspective, selecting the best investment property in Noida requires careful research into location, upcoming infrastructure, rental demand, capital appreciation, developer track record, and overall project potential. Professional guidance can make the process easier by helping buyers compare projects, understand pricing, verify property details, and identify opportunities according to their budget and investment objectives. Propseekers Realty provides real estate advisory services for buyers and investors exploring premium residential and commercial properties across Noida, Noida Expressway, and other emerging areas of Delhi NCR. Overall, the combination of infrastructure development, premium housing projects, connectivity, and growing investment potential makes Noida an important market for anyone considering luxury real estate in NCR.
ReplyDelete