[hibernate-dev] Getting notified when session factory is completely set up
Gunnar Morling
gunnar at hibernate.org
Tue Feb 11 06:55:32 EST 2014
No, at least not in the case of DatastoreProvider.
I think it depends on the specific service and when it is requested for the
first time. DatastoreProvider is retrieved for the first time while the SF
initialization is still in progress (via entity persister -> grid dialect
-> datastore provider). At this time the half-constructed factory is passed
to StartStoppable#startService().
2014/2/11 Davide D'Alto <daltodavide at gmail.com>
> > I can "inject" the SF into a DatastoreProvider by having it implement
> said StartStoppable contract. But as pointed out before the SF is not yet
> completely initialized at this point. So I e.g. can't access the entity
> persisters.
>
> Isn't the SessionFactory already created by the time
> StartStoppable#startService is called?
>
>
> On Tue, Feb 11, 2014 at 11:26 AM, Gunnar Morling <gunnar at hibernate.org>wrote:
>
>> 2014/2/11 Davide D'Alto <daltodavide at gmail.com>
>>
>>> > Yes, that helps indeed. Implementing my validation routine in such an
>>> observer works. I guess if needed, I even could implement support for the
>>> suggested service contract in OGM with help of an observer.
>>>
>>> In OGM, we used to have a SessionFactoryObserver but we removed it in
>>> favor of the SessionFactoryServiceInitiator.
>>> https://hibernate.atlassian.net/browse/OGM-299
>>>
>>>
>> But do we have a DatastoreProvider which actually makes use of the SF?
>>
>> I can "inject" the SF into a DatastoreProvider by having it implement
>> said StartStoppable contract. But as pointed out before the SF is not yet
>> completely initialized at this point. So I e.g. can't access the entity
>> persisters.
>>
>> I couldn't find any "real" implementation of StartStoppable (besides a
>> testing one); it might actually make sense to re-implement the support for
>> this contract using an observer, which would expose a fully-initialized SF
>> to such implementations.
>>
>> The problem I'm having atm. only relates to CouchDB, so for the time
>> being I think I'm going to add an observer just to this module.
>>
>>
>>
>>>
>>>
>>> On Tue, Feb 11, 2014 at 10:05 AM, Gunnar Morling <gunnar at hibernate.org>wrote:
>>>
>>>> 2014/2/11 Hardy Ferentschik <hardy at hibernate.org>
>>>>
>>>> > Hi,
>>>> >
>>>> > not sure whether this could work in your use case, but in Search we
>>>> use a
>>>> > SessionFactoryObserver.
>>>> > We register the observer in Integrator#integrate with the
>>>> > SessionFactoryImplementor.
>>>> > Once the SessionFactory is completely build you get a callback into
>>>> > SessionFactoryObserver#sessionFactoryCreated().
>>>> >
>>>> > In Search we had the case that we did not want to complete
>>>> bootstrapping
>>>> > at the integrator phase. Instead we defer
>>>> > this until the SessionFactory is completely build.
>>>> >
>>>> > Hope it helps.
>>>> >
>>>>
>>>> Yes, that helps indeed. Implementing my validation routine in such an
>>>> observer works. I guess if needed, I even could implement support for
>>>> the
>>>> suggested service contract in OGM with help of an observer.
>>>>
>>>> Thanks!
>>>>
>>>>
>>>> >
>>>> > --Hardy
>>>>
>>>> >
>>>> >
>>>> >
>>>> > On 11 Jan 2014, at 09:38, Gunnar Morling <gunnar at hibernate.org>
>>>> wrote:
>>>> >
>>>> > > Hi,
>>>> > >
>>>> > > Is there a way for services (living in the SF-scoped registry) to
>>>> get
>>>> > > notified when the session factory has been set up and perform some
>>>> action
>>>> > > using that completely initialized factory?
>>>> > >
>>>> > > Upon invocation of initiateService() of
>>>> SessionFactoryServiceInitiator
>>>> > > implementations, the passed factory is still under construction
>>>> (the call
>>>> > > originates from SessionFactoryImpl<init>), so I can't access all
>>>> members.
>>>> > > The same holds true for the StartStoppable contract in OGM which
>>>> also
>>>> > sees
>>>> > > a session factory under construction.
>>>> > >
>>>> > > Now I could store the passed reference in a field and execute the
>>>> > required
>>>> > > logic (some sort of validation) later on. I only have no meaningful
>>>> hook
>>>> > to
>>>> > > trigger such action exactly once. So I'd have to manage a flag to
>>>> make
>>>> > sure
>>>> > > the action is only performed once.
>>>> > >
>>>> > > Is there a better way to achieve this?
>>>> > >
>>>> > > Would it make sense to provide an additional contract to notify
>>>> services
>>>> > > about session factory lifecycle events:
>>>> > >
>>>> > > public interface SessionFactoryLifecycleAware extends Service {
>>>> > >
>>>> > > void
>>>> onSessionFactoryLifecycleEvent(SessionFactoryImplementor sfi,
>>>> > > Event event);
>>>> > >
>>>> > > public enum Event { POST_START, PRE_STOP }
>>>> > > }
>>>> > >
>>>> > > ?
>>>> > >
>>>> > > Thanks,
>>>> > >
>>>> > > --Gunnar
>>>> > > _______________________________________________
>>>> > > hibernate-dev mailing list
>>>> > > hibernate-dev at lists.jboss.org
>>>> > > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>> >
>>>> >
>>>> _______________________________________________
>>>> hibernate-dev mailing list
>>>> hibernate-dev at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>>
>>>
>>>
>>
>
More information about the hibernate-dev
mailing list