XAP

Archive Handler

The Archive Container can be configured to work against Cassandra (without writing any extra code). The ArchiveOperationHandler interface abstracts the Big-Data storage from the Archive Container. The Cassandra Archive Operation Handler implements this interface by serializing space objects into Cassandra.

Library Dependencies

The Cassandra Archive Operation Handler uses the Hector Library for communicating with the Cassandra cluster. Include the following in your pom.xml

<dependency>
    <groupId>org.apache.cassandra</groupId>
    <artifactId>cassandra-clientutil</artifactId>
    <version>1.1.6</version>
</dependency>

<dependency>
    <groupId>org.apache.cassandra</groupId>
    <artifactId>cassandra-thrift</artifactId>
    <version>1.1.6</version>
</dependency>

<dependency>
    <groupId>org.hectorclient</groupId>
    <artifactId>hector-core</artifactId>
    <version>1.1-2</version>
</dependency>
<dependency>
    <groupId>org.apache.cassandra</groupId>
    <artifactId>cassandra-clientutil</artifactId>
    <version>1.1.6</version>
</dependency>

<dependency>
    <groupId>org.apache.cassandra</groupId>
    <artifactId>cassandra-thrift</artifactId>
    <version>1.1.6</version>
</dependency>

<dependency>
    <groupId>org.hectorclient</groupId>
    <artifactId>hector-core</artifactId>
    <version>1.1-2</version>
    <exclusions>
        <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.6</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.6.6</version>
</dependency>

Setup

<os-archive-cassandra:cassandra-archive-handler id="cassandraArchiveHandler"
  giga-space="gigaSpace"
  hosts="127.0.0.1"
  port="9160"
  keyspace="mykeyspace"
  write-consistency="QUORUM"
/>

<bean id="cassandraArchiveHandler" class="org.openspaces.persistency.cassandra.archive.CassandraArchiveOperationHandler">
    <property name="gigaSpace" ref="gigaSpace"/>
    <property name="hosts" value="127.0.0.1" />
    <property name="port" value="9160" />
    <property name="keyspace" value="mykeyspace" />
    <property name="writeConsistency" value="QUORUM" />
</bean>

ArchiveOperationHandler cassandraArchiveHandler =
    new CassandraArchiveOperationHandlerConfigurer()
    .gigaSpace(gigaSpace)
    .hosts("127.0.0.1")
    .port(9160)
    .keyspace("mykeyspace")
    .writeConsistency(CassandraConsistencyLevel.QUORUM)
    .create();

// To free the resources used by the archive container make sure you close it properly.
// A good life cycle event to place the destroy() call would be within the @PreDestroy or DisposableBean#destroy() method.

archiveContainer.destroy();

Properties of the CassandraArchiveOperationHandler

Property Description
gigaSpace GigaSpace reference used for type descriptors. see Archive Container
hosts Comma separated list of Cassandra host names or ip addresses
port Cassandra port. By default uses 9160
keyspace Cassandra keyspace
propertyValueSerializer see Property Value Serializer.
flattenedPropertiesFilter see Flattened Properties Filter.
columnFamilyNameConverter see Column Family Name Converter.

Property Value Serializer

By default when serializing object/document properties to column values, the following serialization logic is applied:

  • If the type of the value to be serialized matches a primitive type in Cassandra it will be serialized as defined by the Cassandra primitive type serialization protocol.
  • Otherwise, the value will be serialized using standard java Object serialization mechanism.

It is possible to override this default behavior by providing a custom implementation of PropertyValueSerializer. This interface is defined by these 2 methods:

ByteBuffer toByteBuffer(Object value);
Object fromByteBuffer(ByteBuffer byteBuffer);

Properties will only be serialized by the custom serializer if their type does not match a primitive type in Cassandra.

Known Limitations