Interface CacheStoreSessionListener

  • All Known Implementing Classes:
    CacheJdbcStoreSessionListener

    public interface CacheStoreSessionListener
    Cache store session listener that allows to implement callbacks for session lifecycle.

    The most common use case for session listeners is database connection and transaction management. Store can be invoked one or several times during one session, depending on whether it's executed within cache transaction or not. In any case, you have to create a connection when session is started and commit it or rollback when session is finished.

    Cache store session listener allows to implement this and other scenarios providing two callback methods:

    Implementations

    Ignite provides several out-of-the-box implementations of session listener (refer to individual JavaDocs for more details):
    • CacheJdbcStoreSessionListener - JDBC-based session listener. For each session it gets a new JDBC connection from provided DataSource and commits (or rolls back) it when session ends.
    • org.apache.ignite.cache.store.spring.CacheSpringStoreSessionListener - session listener based on Spring transaction management. It starts a new DB transaction for each session and commits (or rolls back) it when session ends. If there is no ongoing cache transaction, this listener is no-op.
    • org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListener - Hibernate-based session listener. It creates a new Hibernate session for each Ignite session. If there is an ongoing cache transaction, a corresponding Hibernate transaction is created as well.

    Configuration

    There are two ways to configure a session listener: For example, here is how global CacheJdbcStoreSessionListener can be configured in Spring XML configuration file:
     <bean class="org.apache.ignite.configuration.IgniteConfiguration">
         ...
    
         <property name="CacheStoreSessionListenerFactories">
             <list>
                 <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
                     <constructor-arg>
                         <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener">
                             <!-- Inject external data source. -->
                             <property name="dataSource" ref="jdbc-data-source"/>
                         </bean>
                     </constructor-arg>
                 </bean>
             </list>
         </property>
     </bean>
     
    • Method Detail

      • onSessionStart

        void onSessionStart​(CacheStoreSession ses)
        On session start callback.

        Called before any store operation within a session is invoked.

        Parameters:
        ses - Current session.
      • onSessionEnd

        void onSessionEnd​(CacheStoreSession ses,
                          boolean commit)
        On session end callback.

        Called after all operations within a session are invoked.

        Parameters:
        ses - Current session.
        commit - True if persistence store transaction should commit, false for rollback.