[keycloak-dev] Use default methods in Provider and ProviderFactory
Marek Posolda
mposolda at redhat.com
Fri Mar 10 03:23:57 EST 2017
Another related thing: Many of our providers (eg.
DefaultJpaConnectionProviderFactory) are using the "lazyInit" pattern
when some initialization is done at the time when ProviderFactory.create
is called for the first time. Maybe we can add some support into the
framework itself and directly add another empty method like "lazyInit"
or "beforeFirstCreate" to the ProviderFactory interface?
Marek
On 10/03/17 09:20, Marek Posolda wrote:
> +1
>
> On a slightly related note, I wonder if we can also improve our
> ProviderEvents? Registering listener for the event, which usually
> looks like:
>
> @Override
> public void postInit(KeycloakSessionFactory factory) {
> factory.register(new ProviderEventListener() {
> @Override
> public void onEvent(ProviderEvent event) {
> if (event instanceof RealmModel.ClientCreationEvent) {
> RealmModel.ClientCreationEvent typedEvent =
> (RealmModel.ClientCreationEvent) event;
> doSomething(typedEvent);
> }
> }
> });
> }
>
>
> can be simplified and prettyfied to something like:
>
>
> @ProviderEventListener
> public void doSomething(RealmModel.ClientCreationEvent typedEvent,
> KeycloakSessionFactory factory) {
>
> }
>
> I think the impl will be pretty easy. At startup, framework will just
> lookup for @ProviderEventListener annotated methods of registered
> KeycloakSessionFactory implementations. It can also detect the event
> type according to first argument of method and automatically register
> the listener for it.
>
> This will allow us to remove method "postInit" altogether as it's
> mostly used just for registering event listeners though.
>
> Marek
>
> On 09/03/17 12:28, Stian Thorgersen wrote:
>> The life-cycle methods on providers and provider factories (init,
>> postInit,
>> close) are frequently not used, but providers have to add empty
>> methods. To
>> reduce the amount of boilerplate in a provider I propose changing the
>> following to have empty default methods:
>>
>> ProviderFactory:
>> * init
>> * postInit
>> * close
>>
>> Provider:
>> * close
>> _______________________________________________
>> keycloak-dev mailing list
>> keycloak-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/keycloak-dev
>
>
More information about the keycloak-dev
mailing list