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>2.0.11</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.11</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
- The CassandraArchiveHandler has the following known limitations:
- The archiver must not write two different entries with the same ID. This would corrupt the entry in Cassandra.
- Only Space Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model. Documents are supported. You can still write POJOs to the space, but
the @EventTemplate
used for taking objects from the space must be aSpaceDocument
. - The archiver is thread safe
- The archiver is idempotent as long as there are no two threads that are writing two different objects with the same space ID.
- Both fixed and dynamic space properties are serialized with the same
propertyValueSerializer
.