You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Andrus Adamchik (JIRA)" <ji...@apache.org> on 2013/06/29 15:51:20 UTC

[jira] [Reopened] (CAY-1559) Use Lifecycle Annotations as markers on PersistentObject methods

     [ https://issues.apache.org/jira/browse/CAY-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik reopened CAY-1559:
----------------------------------

      Assignee: Andrus Adamchik

Reopening this Jira. I have a project with 419 entities. Ran it in profiler, with and without this change. To eliminate the differences due to lazy class loading, I added this code before checking for callbacks:

for(ObjEntity e  : cayenneRuntime.getChannel().getEntityResolver().getObjEntities()) {
	e.getJavaClass().getSuperclass();
}

The result is that annotation checking made the first call to ER.getCallbackRegistry() 300x slower. The actual hotspots differed in my YourKit profiles. It was either Class.getDeclaredMethods() to Method.getAnnotations(), but the overall slowdown was always consistent between the tests.

Cayenne fast startup times (due to its model-driven design) is one of our big advantages over the competition. I don't want to give up on this easily. So I will be unrolling my commit until we find a better strategy (such as skipping the _Class and/or maybe making cllback annotation processing an optional strategy enabled via DI property?). 

(Can't unroll it right away due to repo migration to Git and the repo being read-only ATM)

                
> Use Lifecycle Annotations as markers on PersistentObject methods
> ----------------------------------------------------------------
>
>                 Key: CAY-1559
>                 URL: https://issues.apache.org/jira/browse/CAY-1559
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library
>    Affects Versions: 3.1M3, 3.1 (final), Short term future, Undefined future
>            Reporter: Mike M Pestorich
>            Assignee: Andrus Adamchik
>            Priority: Trivial
>              Labels: annotations, listener
>             Fix For: 3.2M2
>
>         Attachments: LifecycleAnnotationMarker.patch
>
>
> In my current project I have various abstract classes that my persistent objects inherit from. While experimenting with various new ways of using lifecycle listeners and their corresponding annotations available in 3.1, I found myself wanting to annotate a method on one of those abstract classes (say with @PostAdd) and have it act as a callback on all of its subclasses. Out of the box, I could get this to work the way I wanted by doing something like:
> public class SomeAbstractPersistantObject {
>     ...
>     @PostAdd(SomeAbstractPersistantObject.class)
>     public void onPostAdd(Object object)
>     {
>         object.getObjectId() ... 
>     }
> }
> And then later on registering the listener by doing something like:
> serverRuntime.getDataDomain().getEntityResolver().getCallbackRegistry().addListener(new SomePersistentObject());
> The problem was that I didn't what to have to instantiate an object just to register it, or for that matter even have to register the listener in the first place. My callback is already part of the PersistentObject that it applies to and as such should "just work" for that object or anything that extends it. I wanted to be able to do something like:
> public class SomeAbstractPersistantObject {
>     ...
>     @PostAdd
>     public void onPostAdd()
>     {
>         this.getObjectId() ... 
>     }
> }
> And that's it. Listeners/Callbacks defined in this manner are registered when lazy initialization of the callback registry occurs within the EntityResolver. All I have to do now is annotate a method within the persistent object that I want it to act on and don't have to worry about anything else.
> I don't know if this sort of thing would be useful to anyone but I have attached a patch that I believe does just that. I have been using it for a couple of days now and it seems to be working as intended without breaking the other available means of using lifecycle listeners.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira