Skip to main content

General Container

General container allows to get and modify the key-value pairs on the rostore service instance in a general manner. In this way the caller can provide the serializer and deserializer classes that will allow transform the InputStreams received over the network to the java classes. The general container may also be used for direct streaming of the data, which is especially interesting for longer values. If the data is suppose to be mapped to the java classes, than the mapped container should rather be used.

The general container offers the universal access to the rostore service, but as it is not aware of the value type, the serializer/deserializer should all the time be provided on every read/write operation.

Create a Container​

To create a new container one can use the following command:


final GeneralContainer<String> container = roStoreClient.getGeneralContainer("my-container");
final ContainerMeta containerMeta = new ContainerMeta();
containerMeta.setShardNumber(5);
container.create(containerMeta);

The last operation will create a new container on the rostore service. If the container already exists the operation will fail with an exception.

Create a new key​

To create a new key one should create a value's input stream and then pass it to the post function:

  VersionObject<String,String> inputVO = VersionedObject.createUnversionedEternal("my-key", "my-value")
VersionedObject<String,String> outputVO = container.post(inputVO, (s) -> new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)));

The latest operation would sent the key-value to rostore service.

Read a Key​

To read the key from the general container the following command can be executed:

  VersionedObject<String,String> vo = container.get("my-key", (inputStream) -> new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining("\n")));