GigaSpaces fully supports the Spring Framework, and can be plugged in very easily without changing your existing code.
The Existing Architecture
Your existing Hibernate-based database integration probably looks like the following: the application uses Hibernate to persist its data directly to the database.
Step 1: Getting a Free Distributed Two-Level Cache
You can very easily replace your existing Hibernate cache provider, typically EHCache, with GigaSpaces. This gives you a powerful distributed cache with multiple clients.
Benefits:
Powerful distributed cache - multiple clients, each client's updates can be accessed by all other clients
Step 2: Scaling Up Your Database by Adding a Data Grid
If you need to scale up your database, you can use GigaSpaces as an In-Memory Data Grid. Your application communicates with the Data Grid using the Spring-based OpenSpaces framework (or alternatively, using the simple JavaSpaces API or Map API interfaces). On the back-end, GigaSpaces persists the data to your existing database using your existing Hibernate O/R mapping.
Benefits:
Database scalability through partitioning and data distribution - enables higher data volumes and higher throughput with low latency
Better decoupling between your application and the database - no need to hard-wire Hibernate and database concepts into your code and runtime environment
Event-driven model enables notifications when data is modified
Database access can be synchronous or asynchronous - the GigaSpaces Mirror Service allows data to be persisted to the database asynchronously, without a performance penalty
Beyond the Data Grid: Scaling Out Your Application Using Space-Based Architecture
To gain ultimate scalability for your application, you can package your business logic together with the GigaSpaces space - which provides not only data but also messaging functionality. This creates a Processing Unit which is completely self sufficient (not dependent on a database, messaging server or any central component), meaning that you to duplicate it as many times as necessary without increasing complexity.
This approach is called Space Based Architecture, and the way to achieve it is the Spring-based OpenSpaces platform, which allows you to deploy your application as a set of services encased in a Processing Unit.
This section provides instructions on switching your existing Hibernate local cache, typically EhCache, with GigaSpaces. This will give you a powerful distributed cache with multiple clients and advanced clustering.
To switch your Hibernate cache provider to GigaSpaces and use GigaSpaces distributed caching:
This step is different if you are managing your Hibernate configuration using Spring (refer to the Spring documentation, ORM Data Access*** , section 12.2.2), or directly using hibernate.properties or hibernate.cfg.xml. Select the relevant tab below.
Spring Configuration
Spring Configuration
Edit your SessionFactory Setup. This is the section inside your Spring Application Context File that controls the relevant Hibernate configuration (refer to the Spring documentation, ORM Data Access , section 12.2.2). Add or modify the following properties under <property name="hibernateProperties">:
• Set hibernate.cache.provider_class to org.openspaces.hibernate.cache.SimpleMapCacheProvider:
Set or add the cache usage (the cache concurrency strategy) in your mapping resource file (*.hbm.xml files) to read-only, read-write or nonstrict-read-write:
Launch your application. The application should instantiate a local cache based on an embedded GigaSpaces space.
If you want to use GigaSpaces as a distributed cache, select the distributed topology that interests you from the tabs below.
Master-Local Cache
Master-Local Cache Topology
In this topology each application has a lightweight, embedded cache, which is initially empty. The first time data is read, it is loaded from a master cache to the local cache (lazy load); the next time the same data is read, it is loaded quickly from the local cache. Later on data is either updated from the master or evicted from the cache.
To use the master-local topology:
Set your gigaspaces.hibernate.cache.url property to
Copy <GigaSpaces Root>\lib\hibernate\hibernate3.jar and <GigaSpaces Root>\lib\common\commons-logging.jar into the <GigaSpaces Root>\lib\ext folder.
Copy dom4j.jar from Hibernate distribution package into the <GigaSpaces Root>\lib\ext foler.
Run <GigaSpaces Root>\bin\gs-all.bat (.sh) to start a GigaSpaces container manager (GSM) and a container (GSC) for the master GigaSpaces space. Wait to see the following output in both GSM and GSC console windows:
INFO [org.jini.rio.cybernode]: Registered to a ProvisionManager
Run <GigaSpaces root>\bin\gs.bat pudeploy ..\deploy\templates\datagrid to deploy the master space Wait to see the following output (below the output shown in the previous step) in both GSM and GSC console windows:
FINE [org.jini.rio.monitor.services]: [..\deploy\templates\datagrid:
..\deploy\templates\datagrid.PU] service provisioned, .....
Run your application.
Partitioned Master-Local Cache
Partitioned Master-Local Cache Topology
In this topology, data is split between two spaces (partitions) according to an index field defined in the data. An algorithm, defined in the load-balancing policy, maps values of the index field to specific partitions.
Copy <GigaSpaces Root>\lib\hibernate\hibernate3.jar and <GigaSpaces Root>\lib\common\commons-logging.jar into the <GigaSpaces Root>\lib\ext folder.
Copy dom4j.jar from Hibernate distribution package into the <GigaSpaces Root>\lib\ext folder.
Run <GigaSpaces Root>\bin\gsm.bat (.sh) to start a container manager (GSM).
Run <GigaSpaces Root>\bin\gsc.bat (.sh) to start a container (GSC) for the master space.
Run <GigaSpaces Root>\bin\gsc.bat (.sh) to start an additional container (GSC).
Wait to see the following output in the two GSC output windows:
INFO [org.jini.rio.cybernode]: Registered to a ProvisionManager
Run <GigaSpaces Root>\bin\gs pudeploy -cluster schema=partitioned total_members=2,0 ../deploy/templates/datagrid to run a cluster of two partitioned master spaces.
Wait to see the following output in the first GSC console window:
FINE [org.jini.rio.cybernode]: /datagrid.PU [1]: advertised
and the following output in the second GSC console window:
FINE [org.jini.rio.cybernode]: /datagrid.PU [2]: advertised
Run your application.
Embedded Replicated Cache
Embedded Replicated Cache Topology
This topology consists of two or more space instances with replication between them, allowing two or more applications to work with their own dedicated data store, while working on the same data as the other applications.
This section provides instructions on adding the GigaSpaces In-Memory Data Grid to your Hibernate database integration. This will allow you to scale up your central database by distributing and partitioning the data. Your application will communicate directly with GigaSpaces, and GigaSpaces will persist the data in the background to your existing database, using your existing O/R mapping. Persistency and data retrieval can be done synchronously, using the GigaSpaces Read/Write-Through mechanism, or asynchronously, using the GigaSpaces Mirror Service.
To add the GigaSpaces In-Memory Data Grid:
These instructions assume you are managing your Hibernate configuration using Spring. Refer to the Spring documentation, ORM Data Access to learn how to do this.
If you haven't done so already, download the GigaSpaces eXtreme Application Platform (Product InfoDownload Page) or GigaSpaces XAP Enterprise Data Grid (Product InfoDownload Page). Note that you cannot use the Community Edition for this purpose, because a Data Grid requires more than one GigaSpaces server node.
Edit your SessionFactory Setup. This is the section in your Spring Application Context File that controls the relevant Hibernate configuration (refer to the Spring documentation, ORM Data Access , section 12.2.2).
Add or modify the following properties under <property name="hibernateProperties">:
Set hibernate.cache.provider_class to org.hibernate.cache.NoCacheProvider (no cache provider):
Modify your application to handle data using GigaSpaces' Spring-based Open Spaces framework, instead of the Hibernate API. Keep in mind that GigaSpaces will continue to persist data to your existing database using your existing O/R mapping.
If you prefer to access GigaSpaces directly using one of the supported APIs, refer to the JavaSpaces or Map sections.
Deploy the GigaSpaces Data Grid in the topology of your choice. A partitioned topology is particularly useful for scaling up to increase the throughput of your database.
Choose how GigaSpaces should access the database:
If you want data to be synchronously read and written to the database by the Data Grid, refer to the External Data Source section.
If you want data to be asynchronously mirrored between the Data Grid and and the database, refer to the Mirror Service section.
Launch your application. The application writes and reads data to/from the GigaSpaces In-Memory Data Grid; the data is persisted in the background to your existing database using Hibernate.