This site hosts historical documentation. Visit www.terracotta.org for recent product information.
The following examples are provided in the code-samples/
directory in the kit.
The BSON - C# example consists of three files:
CacheSerializer<string, Recipe2>
interface. It is responsible for serializing and deserializing keys and values, moving between the Recipe2 domain object and the Thrift types Value and StoredValue. Serialization and deserialization of the Recipe2 objects is handled through the Json.net automatic BSON serializer.To run the BSON - C# example:
Create a new Visual Studio project and add the three .CS recipe files.
Add the following libraries in the References section of your project:
Start the server as described on the Get Started page, and then run the console application (Recipe2ConsoleApp.cs).
The Protocol Buffer - C# example consists of the following files:
The example is a recipe package that includes ingredients, measurements, and instructions.
package RecipeProject;
message RecipeStructure {
required string name = 1;
required string description = 2;
required int32 preparation_time = 3;
required Method method = 6;
required Ingredients ingredients = 5;
optional int32 baking_time = 4;
optional ServingInstructions instructions = 7;
}
message Ingredients {
repeated Ingredient ingredient = 1;
}
message Ingredient {
required float quantity = 1;
required Measurement measurement = 2;
required IngredientDescription ingredient = 3;
}
message Measurement {
required string measurement_type = 1;
}
message IngredientDescription {
required string ingredient = 1;
optional Ingredient alternative_ingredient = 2;
}
message Method {
repeated MethodItem items = 1;
}
message MethodItem {
required int32 step_number = 1;
required string instruction = 2;
}
message ServingInstructions {
required int32 servings = 1;
required Measurement serving_measurement = 2;
optional Method method = 3;
}
To run the Protocol Buffer - C# example:
Create a new Visual Studio project and add the three .CS recipe files.
Add the following libraries in the References section of your project:
Start the server as described on the Get Started page, and then run the console application (SimpleRecipeConsoleApp.cs).
Note: If you have already installed the BigMemory Client and Cross-Language Connector, you can run this example by adding the external protobuf dependancy. The maven link is
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
This dependancy will need to be in both BigMemory .Net Client and CL Connector classpaths. For the CL Connector, the component that needs to be set is EhcacheThriftConfiguration.Builder().cacheSerializerFactory(RecipeSerializerFactory.class)
so that the RecipeSerializerFactory, RecipeSerializer, and Recipe classes will be in the CL Connector's classpath. For the BigMemory .Net Client, the component that will be run is SimpleRecipeConsoleApp, which requires the SimpleRecipeConsoleApp, RecipeSerializer, and Recipe classes to be on the classpath along with the BigMemory .Net Client dependancies.