ConfigurationA Cassandra based implementation of the Space Synchronization Endpoint. Library dependenciesThe Cassandra Space Synchronization Endpoint uses the Hector Library For communicating with the Cassandra cluster.
hector using log4j
<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> hector using java.util.logging <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> SetupAn example of how the Cassandra Space Synchronization Endpoint can be configured within a mirror.
Spring
<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os-core="http://www.openspaces.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.openspaces.org/schema/core http://www.openspaces.org/schema/9.5/core/openspaces-core.xsd"> <bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> <bean id="hectorClient" class="org.openspaces.persistency.cassandra.HectorCassandraClientFactoryBean"> <!-- comma separated seed list --> <property name="hosts" value="${cassandra.host}" /> <!-- cassandra rpc communication port --> <property name="port" value="${cassandra.port}" /> <!-- keyspace name to work with --> <property name="keyspaceName" value="${cassandra.keyspace}" /> </bean> <bean id="cassandraSpaceSyncEndpoint" class="org.openspaces.persistency.cassandra.CassandraSpaceSynchronizationEndpointFactoryBean"> <!-- configured above --> <property name="hectorClient" ref="hectorClient" /> </bean> <os-core:mirror id="mirror" url="/./mirror-service" space-sync-endpoint="cassandraSpaceSyncEndpoint"> <os-core:source-space name="space" partitions="${numOfPartitiones}" backups="${numOfBackups}"/> </os-core:mirror> </beans> Code HectorCassandraClient hectorClient = new HectorCassandraClientConfigurer() .clusterName(cluster) .hosts(cassandraHosts) .port(cassandraPort) .keyspaceName(cassandraKeyspaceName) .create(); SpaceSynchronizationEndpoint syncEndpoint = new CassandraSpaceSynchronizationEndpointConfigurer() .hectorClient(hectorClient) .create(); IJSpace mirror = new UrlSpaceConfigurer("/./mirror-service") .schema("mirror") .spaceSynchronizationEndpoint(syncEndpoint) .addProperty("space-config.mirror-service.cluster.name", "space") .addProperty("space-config.mirror-service.cluster.partitions", String.valueOf(numOfPartitiones)) .addProperty("space-config.mirror-service.cluster.backups-per-partition", String.valueOf(numOfBackups)) .create(); For more details about different configurations see Space Persistency. CassandraSpaceSynchronizationEndpoint Properties
Property Value SerializerBy default when serializing object/document properties to column values, the following serialization logic is applied: For fixed properties:
For dynamic properties:
It is possible to override this default behavior by providing a custom implementation of PropertyValueSerializer . ByteBuffer toByteBuffer(Object value); Object fromByteBuffer(ByteBuffer byteBuffer); The behavior of overriding the serialization logic is different for fixed properties and dynamic properties:
Flattened Properties FilterIntroductionWhen a type is introduced to the Cassandra Space Synchronzation Endpoint, the type's fixed properties will be introspected and the final result will be a mapping from this type's nested properties to column family columns. // implementation omitted for brevity @SpaceClass public class Person { @SpaceId public Long getId() ... public String getName() ... public Address getAddress() ... ... } public class Address { public String getStreetName() ... public Long getStreetNumber() ... } By default, the fixed properties will be mapped to the Person column family in Cassandra like this:
Notice how the address property was flattened and its properties are flattened as columns. Now suppose that a Person is written to the space as a SpaceDocument which also includes these dynamic properties:
By default, dynamic properties are not flattened and are written as is to Cassandra. Moreover, their static type is not updated in the Column Family metadata and they are serialized using a custom serializer. (see Property Value Serializer). This is how they will be written to Cassandra:
CustomizationIt is possible to override the above behavior by providing a FlattenedPropertiesFilter implementation. The interface is defined by a single method: boolean shouldFlatten(PropertyContext propertyContext);
The return value indicates whether the current introspected property should be serialized as is or should its nested properties be introspected as well. the PropertyContext contains the following details about the current introspected property: String getPath(); String getName(); Class<?> getType(); boolean isDynamic(); int getCurrentNestingLevel(); Column Family Name ConverterDue to implementation details of Cassandra regarding Column Families there are certain limitations when converting a type name (e.g: com.example.data.Person) to a column family name. Among these limitations is a 48 characters max length limitation and invalid characters in the name (such as '.'). String toColumnFamilyName(String typeName); The default implementation is: DefaultColumnFamilyNameConverter . Considerations
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |