You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by vinshar <vi...@gmail.com> on 2016/01/09 18:15:27 UTC

SoreSessionListener, cacheLoaderFactory, cacheWriterFactory implementation examples

Hi,

I there any example that i can refer to understand following
1) Example implementation of loader / writer factories for hibernate / JPA
and JDBC
2) Example implementation of SoreSessionListener and what a session means
here? In a JDBC or hibernate based implementation, What will be a
CacheStoreSession classes relationship with DB connections or a Hibernate
Session. 
2) If i create a cache from client node where i specify these loaders in my
configuration then how this information is relayed across other client and
server nodes? If my loader or Writer implementation is JPA based with
Hibernate as implementation then my loader or writer implementation will
perhaps have a embedded EntityManager or EntityManagerFactory. How this all
works in a distributed environment? If i create cache from one client node
with readthrough enabled then What happens if another client node tries to
get an object from same cache and there is a cache miss? Do i need to put
JARs containing cacheLoaderFactory and cacheWriterFactory classes? 

Regards,
Vinay Sharma



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/SoreSessionListener-cacheLoaderFactory-cacheWriterFactory-implementation-examples-tp2462.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: SoreSessionListener, cacheLoaderFactory, cacheWriterFactory implementation examples

Posted by vkulichenko <va...@gmail.com>.
Hi Vinay,

See my answers below.


vinshar wrote
> 1) Cache configuration is defined on a server node and cache was created
> as part of this server node start operation. Cache is read through and
> write through. I Define cache loader factory and Cache writer Factory in
> this configuration. I guess my loader factory implementation class should
> be on all server nodes in this case? is this right? 
> 2) Create a near cache for above mentioned cache on a client node. Now do
> i need loader and writer factory implementation classes on client node as
> well? i think not.

The configuration is broadcasted to all nodes. This is required, for
example, for transactional caches, because they update the store from the
client node, not from the server. With atomic cache this can be
workarounded, but by default you will need to deploy classes on all nodes.


vinshar wrote
> 3) Make a get operation which is a miss on near cache. I think i should
> get value from Server node if it exists there in this case.
> 4) Make another get which is a miss on near cache as well as a miss on
> cache on server node. I think in this case Server node will use Loader
> factory to load object in cache and send it to client node. is this right?

This is correct.


vinshar wrote
> 5) What happens if i call getAndPut on near cache on client node?

It will return you the current value, update the entry with the new one and
call CacheStore.write(). It will be cached in the local near cache as well.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/SoreSessionListener-cacheLoaderFactory-cacheWriterFactory-implementation-examples-tp2462p2503.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: SoreSessionListener, cacheLoaderFactory, cacheWriterFactory implementation examples

Posted by vinshar <vi...@gmail.com>.
Hi Val,


vkulichenko wrote
> "As for configuration, you will have to deploy cache reader/writer
> implementation classes on all nodes. Note that you provide Factory in
> configuration instead of reader/writer instance, so it created only on the
> node where it will be used. This allows to make reader/writer
> non-serializable."

What happens in below scenario
1) Cache configuration is defined on a server node and cache was created as
part of this server node start operation. Cache is read through and write
through. I Define cache loader factory and Cache writer Factory in this
configuration. I guess my loader factory implementation class should be on
all server nodes in this case? is this right? 
2) Create a near cache for above mentioned cache on a client node. Now do i
need loader and writer factory implementation classes on client node as
well? i think not.
3) Make a get operation which is a miss on near cache. I think i should get
value from Server node if it exists there in this case.
4) Make another get which is a miss on near cache as well as a miss on cache
on server node. I think in this case Server node will use Loader factory to
load object in cache and send it to client node. is this right?
5) What happens if i call getAndPut on near cache on client node?




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/SoreSessionListener-cacheLoaderFactory-cacheWriterFactory-implementation-examples-tp2462p2498.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: SoreSessionListener, cacheLoaderFactory, cacheWriterFactory implementation examples

Posted by vkulichenko <va...@gmail.com>.
Vinay,

As a first step I would recommend to refer to cache store examples provided
in Ignite: JDBC-based [1], Spring-based [2] and Hibernate-based [3]. They
all are pretty similar and demonstrate similar functionality, but
implemented using different tools. Note that corresponding session listeners
are already implemented and provided out of the box.
BTW, I think JPA/JTA-based implementation could be also useful, I create a
ticket for this [4].

In general, store session scope depends on cache atomicity mode. In ATOMIC
cache a new session is always created for each operation, while in
TRANSACTIONAL cache it spawns all operations in a single transaction. The
latter allows you to commit/rollback DB transaction along with the cache
transaction and therefore maintain transactional consistency between cache
and the DB.

As for configuration, you will have to deploy cache reader/writer
implementation classes on all nodes. Note that you provide Factory in
configuration instead of reader/writer instance, so it created only on the
node where it will be used. This allows to make reader/writer
non-serializable.

[1]
https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc
[2]
https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring
[3]
https://github.com/apache/ignite/tree/master/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate
[4] https://issues.apache.org/jira/browse/IGNITE-2345

Let us know if you have more questions.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/SoreSessionListener-cacheLoaderFactory-cacheWriterFactory-implementation-examples-tp2462p2477.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.