Data Grid With Space

Data Grid

Most of RDBMS meets the problem with such Single Point of Failure and Bottleneck when massive IO accesses to DB are done.
In some cases, large data to be updated in a bulk manner is required.

In GigaSpaces, Space is used as In-Memory Data Grid(IMDG). But in contrast to the limitation of the data capacity which most In-Memory DB products meet, Spaces can have unlimited data in the partitioned spaces.
As we know, IO access to IMDB is fast. Space as Data Grid can be accessed by massive IO, and the IO process with Spaces is also fast.

In the next example, we will see the usage of Space as IMDG and how easy to access and process data in space with the help of spring.

Space as Data Grid Overview

data-grid-with-space.jpg
  • Space is used as In-Memory Data Grid.
  • Application has JavaSpaces connections with space to do CRUD of data objects.

Space used as IMDG

In our example data-grid-with-space.zip, we see such space usage as IMDG.

Like with normal RDBMS, we can connect to space with JavaSpaces connection.
GigaSpaces supports not only JavaSpaces connection facility, but also Map(JCache), JDBC.

In our example, we have used GigaSpaces connector which is the improved connector of JavaSpaces.
In most enterprise application, DAO(Data Access Object) layer has responsiblity of accesing such Database.
Data access to space also happens in DAO like other enterprise applications.
Let's see more details in the next.

DAO to Space

From the example data-grid-with-space.zip, DAO interface and its implementation to space can be found in <data-grid-with-space>/src/main/java/com/ktf/khub/samples/grid/data/space/dao.

package com.ktf.khub.samples.grid.data.space.dao;
 
import java.util.Date;
import java.util.List;
 
import org.springframework.dao.DataAccessException;
 
import com.ktf.khub.samples.grid.data.space.domain.Event;
import com.ktf.khub.samples.grid.data.space.domain.Person;
 
public interface EventsDao {
 
    public String createAndStoreEvent(String title, Date theDate)
            throws DataAccessException;
 
    public String createAndStorePerson(String firstname, String lastname)
            throws DataAccessException;
 
    public List listEvents() throws DataAccessException;
 
    public List listPerson() throws DataAccessException;
 
    public Person loadPerson(String personId) throws DataAccessException;
 
    public Event loadEvent(String eventId) throws DataAccessException;
 
}

and its implementation is:

package com.ktf.khub.samples.grid.data.space.dao.space;
 
...
 
public class SpaceEventsDao implements EventsDao {    
 
    private GigaSpace gigaSpace;
 
    public void setGigaSpace(GigaSpace gigaSpace) {
        this.gigaSpace = gigaSpace;
    }
 
    public String createAndStoreEvent(String title, Date theDate)
            throws DataAccessException {
        Event theEvent = new Event();
        theEvent.setEventId(String.valueOf(new java.util.Date().getTime()));
        theEvent.setTitle(title);
        theEvent.setDate(theDate);        
 
        gigaSpace.write(theEvent, Lease.FOREVER, Long.MAX_VALUE, UpdateModifiers.WRITE_ONLY);
 
        return theEvent.getEventId();
    }
 
    public String createAndStorePerson(String firstname, String lastname)
            throws DataAccessException {
        Person thePerson = new Person();    
        thePerson.setPersonId(String.valueOf(new java.util.Date().getTime()));
        thePerson.setFirstname(firstname);
        thePerson.setLastname(lastname);
 
        gigaSpace.write(thePerson, Lease.FOREVER, Long.MAX_VALUE, UpdateModifiers.WRITE_ONLY);
 
        return thePerson.getPersonId();
    }
 
    public List listEvents() throws DataAccessException {
 
        Event template = new Event();
 
        Object[] eventArray = gigaSpace.readMultiple(template,
                Integer.MAX_VALUE, ReadModifiers.EXCLUSIVE_READ_LOCK);
 
        List result = Arrays.asList(eventArray);
 
        return result;
    }
 
    public Event loadEvent(String eventId) throws DataAccessException {
        Event template = new Event();
        template.setEventId(eventId);
 
        Event anEvent = gigaSpace.read(template, Long.MAX_VALUE,
                ReadModifiers.EXCLUSIVE_READ_LOCK);
 
        return anEvent;
    }
 
    public Person loadPerson(String personId) throws DataAccessException {
        Person template = new Person();
        template.setPersonId(personId);
 
        Person aPerson = gigaSpace.read(template, Long.MAX_VALUE,
                ReadModifiers.EXCLUSIVE_READ_LOCK);
 
        return aPerson;
    }
 
    public List listPerson() throws DataAccessException {
        Person template = new Person();
 
        Object[] eventArray = gigaSpace.readMultiple(template,
                Integer.MAX_VALUE, ReadModifiers.EXCLUSIVE_READ_LOCK);
 
        List result = Arrays.asList(eventArray);
 
        return result;
    }
}

As seen in DAO implementation, gigaSpace connector has been injected via spring xml configuration as you know.
Just in simple object way, data objects are processed with space.

For that DAO implementation, let's see the spring xml:

...
   <!--
    ============================================================
    DAO.
    ============================================================
    -->
    <bean id="spaceEventsDao"
        class="com.ktf.khub.samples.grid.data.space.dao.space.SpaceEventsDao">
        <property name="gigaSpace" ref="gigaSpace" />   
    </bean>
    ...
    <!--
    ============================================================
    Space.
    ============================================================
    -->      
    <os-core:giga-space id="gigaSpace" space="space"
        tx-manager="transactionManager" />            
    <os-core:space id="space" url="jini://*/*/cacheNode?useLocalCache&amp;groups=mykidong" 
              schema="default" /> 
...

In gigaSpace spring bean, space bean has been referenced which has space connection url like this jini://*/*/cacheNode?useLocalCache&groups=mykidong.

As seen above, it is very simple to get space connection with spring, and in DAO there is no additional complexity about connectivity in codes.

Required Softwares

Requred softwares to run our example are listed below:

Run example

To run our example, please download and unzip data-grid-with-space.zip.
Make sure that all the required libraries of Spring 2.5.x and GigaSpaces 6.0 are copied in <data-grid-with-space>/lib.

Open <data-grid-with-space>/bin/set-env.bat, modify the following lines:

rem ===================================================
rem set the GigaSpaces home.
rem ===================================================
@set JSHOMEDIR="D:\project\action-khub-samples\apps\3rd-parties\giga-spaces\GigaSpacesXAP6.5M8"

set the correct GigaSpaces installation directory.

Follow the next steps:

  • change to <data-grid-with-space> in the command, and type 'ant' to build our example.
  • run start-part-*.bat to run the partitioned spaces.
  • run start-jini-tx.bat to run jini transaction manager.
  • run run-app.bat to run the example.
  • run gs-ui-mykidong.bat to browse the entries in the spaces.

Conclusion

Space can be used as IMDG but with the capability of having large data.
As we experienced here, access to space is not different from accessing DB.
It is also interesting in object way like using data object template, the data object from space or to space can be taken or written.

Attachment

page tags: data grid imdb space spring
page_revision: 28, last_edited: 1208342035|%e %b %Y, %H:%M %Z (%O ago)
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License