Aspecio: aspect-oriented programming meets the OSGi service model
Aspect-oriented programming is a paradigm meant to provide "horizontal" modularity: by encapsulating cross-cutting concerns such as access control or performance metrics away from business logic, it was supposed to be a new tool for developers that would not only prevent copy-paste and guard methods, but allow to stack semantic models on top of single-concern implementations.
The early excitement somewhat faded when the freedom provided by rich aspect languages proved to make understanding of code and its debugging harder because of scattered logic and altered bytecode. Today in the Java world, it is used mostly in a lighter form in the Spring framework, but it has traditionally been difficult to integrate properly with OSGi.
When OSGi R5 introduced the ServiceHook API, one of its promises was to enable OSGi-powered implementations of aspect frameworks. Aspecio[1] is such a framework, taking an opinionated approach to aspects to make them predictable while giving a lot of control to developers and keeping the overhead minimal:
Fully OSGi-compliant: Interceptors are services, dynamism is fully supported ;
Define your aspects in plain Java ;
Works with any OSGi component framework, such as Declarative Services, Blueprint, or plain OSGi core APIs ;
Minimal overhead: on-demand bytecode generation, no primitive boxing or Method#invoke, and a "pay only for what you use" approach through a Java 8 mixin-like advice definition API ;
Reasonably easy to debug: no change to existing bytecode, generated proxies are very thin and expose a well-documented behavior.
The OSGi service model is so versatile that aspects could feel useless at first glance; it turns out they are a handy and complementary tool in OSGi application design.
In this talk, I will present Aspecio and what we can accomplish by mixing the OSGi service model with aspects, and demonstrate how anyone can add aspects to any OSGi application in a few minutes without refactoring existing code.
Simon Chemouil