Recommended use of getExtensionList

11 views
Skip to first unread message

Baptiste Mathus

unread,
Feb 1, 2015, 12:32:26 PM2/1/15
to jenkin...@googlegroups.com

Hi all,
Currently adding an extension point to my plugin, I was wondering if I should try and cache the results of getExtensionList() at some point (I read one good place may be in postInitialize()).

In that case though, if some plugin gets installed without restarting the server, I guess I won't have the potential new registered extensions. That bothers me a bit.

Is there some recommended pattern/way to be a good citizen in this area (I.e. handling extensions from the plugins in general)?

One solution here would be to never cache the results and always call getExtensionList(). Is this something reasonable? (In my case, for *every* build of the Jenkins instance...). Seems a bit wasteful at first sight.

Or is there some maybe an extension point to implement to be notified of new extension registrations? :)

Thanks for your advice.

Cheers

-- Baptiste

Ulli Hafner

unread,
Feb 2, 2015, 7:49:04 AM2/2/15
to jenkin...@googlegroups.com
Am 01.02.2015 um 18:32 schrieb Baptiste Mathus <m...@batmat.net>:

Hi all,
Currently adding an extension point to my plugin, I was wondering if I should try and cache the results of getExtensionList() at some point (I read one good place may be in postInitialize()).

In that case though, if some plugin gets installed without restarting the server, I guess I won't have the potential new registered extensions. That bothers me a bit.

Is there some recommended pattern/way to be a good citizen in this area (I.e. handling extensions from the plugins in general)?

One solution here would be to never cache the results and always call getExtensionList(). Is this something reasonable?

Yes, I think this is reasonable to always call getExtensionList(). Isn’t that list already cached by Jenkins? So it would not hurt to call that method multiple times... 

(In my case, for *every* build of the Jenkins instance...). Seems a bit wasteful at first sight.

Or is there some maybe an extension point to implement to be notified of new extension registrations? :)

Thanks for your advice.

Cheers

-- Baptiste


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANWgJS4%3D5a%3Dwr%3DU-Ube1f9FDGcN1NjFuki-Jp6QSiKLax58S2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Baptiste Mathus

unread,
Feb 2, 2015, 7:59:14 AM2/2/15
to jenkin...@googlegroups.com
Hi Ulli,

In the meantime, I dug a bit more, and actually I seem to understand that even if you keep a reference to ExtensionList in your plugin, ExtensionLists would be refreshed if new extensions are detected [1].
I'd like to get it confirmed though, either here or by also reading more core code and testing it from a plugin behaviour perspective.

If so, I suppose plugins should/could always keep the ExtensionList refs they need since there's no risk of not being up-to-date this way. I'll update the dev docs with that information once sure.

Cheers

-- Baptiste



For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Ulli Hafner

unread,
Feb 2, 2015, 9:20:27 AM2/2/15
to jenkin...@googlegroups.com
Am 02.02.2015 um 13:58 schrieb Baptiste Mathus <bma...@batmat.net>:

Hi Ulli,

In the meantime, I dug a bit more, and actually I seem to understand that even if you keep a reference to ExtensionList in your plugin, ExtensionLists would be refreshed if new extensions are detected [1].
I'd like to get it confirmed though, either here or by also reading more core code and testing it from a plugin behaviour perspective.

If so, I suppose plugins should/could always keep the ExtensionList refs they need since there's no risk of not being up-to-date this way. I'll update the dev docs with that information once sure.


Hmm, I’m not sure if that is ok. Since it is not explicitly described in the API that the returned list will be automatically updated you should not rely on it. (I think it is quite dangerous that Jenkins returns the internal state here rather than a read-only view or a copy of the existing list. So if someone decides to hide the internal structure and hand out only a copy than your code will break...)  

signature.asc

Stephen Connolly

unread,
Feb 2, 2015, 4:22:22 PM2/2/15
to jenkin...@googlegroups.com


On Monday, February 2, 2015, Baptiste Mathus <bma...@batmat.net> wrote:
Hi Ulli,

In the meantime, I dug a bit more, and actually I seem to understand that even if you keep a reference to ExtensionList in your plugin, ExtensionLists would be refreshed if new extensions are detected [1].
I'd like to get it confirmed though, either here or by also reading more core code and testing it from a plugin behaviour perspective.

If so, I suppose plugins should/could always keep the ExtensionList refs they need since there's no risk of not being up-to-date this way. I'll update the dev docs with that information once sure.

If you do that, then there is no opertunity to change the implementation behaviour.

I would say just look it up each time. It's the safer pattern
 
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANWgJS5_b0qxG73PCyA3Qi28-YGpm97PTN%3DYB1Q41k4dA9Y1Ag%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Sent from my phone

Baptiste Mathus

unread,
Feb 3, 2015, 11:43:22 AM2/3/15
to jenkin...@googlegroups.com

OK, thanks for the feedback. I'll do it that way. BuildTriggerBadge 2.0 is on its way :-).

Reply all
Reply to author
Forward
0 new messages