Class SerializedCompositeKeyBuilder<K>

  • Type Parameters:
    K - type of the key.

    @NotThreadSafe
    @Internal
    public final class SerializedCompositeKeyBuilder<K>
    extends Object
    Responsible for serialization of currentKey, currentGroup and namespace. Will reuse the previous serialized currentKeyed if possible.
    • Constructor Detail

      • SerializedCompositeKeyBuilder

        public SerializedCompositeKeyBuilder​(@Nonnull
                                             TypeSerializer<K> keySerializer,
                                             @Nonnegative
                                             int keyGroupPrefixBytes,
                                             @Nonnegative
                                             int initialSize)
    • Method Detail

      • setKeyAndKeyGroup

        public void setKeyAndKeyGroup​(@Nonnull
                                      K key,
                                      @Nonnegative
                                      int keyGroupId)
        Sets the key and key-group as prefix. This will serialize them into the buffer and the will be used to create composite keys with provided namespaces.
        Parameters:
        key - the key.
        keyGroupId - the key-group id for the key.
      • setNamespace

        public <N> void setNamespace​(@Nonnull
                                     N namespace,
                                     @Nonnull
                                     TypeSerializer<N> namespaceSerializer)
      • buildCompositeKeyNamespace

        @Nonnull
        public <N> byte[] buildCompositeKeyNamespace​(@Nonnull
                                                     N namespace,
                                                     @Nonnull
                                                     TypeSerializer<N> namespaceSerializer)
        Returns a serialized composite key, from the key and key-group provided in a previous call to setKeyAndKeyGroup(Object, int) and the given namespace.
        Type Parameters:
        N - the type of the namespace.
        Parameters:
        namespace - the namespace to concatenate for the serialized composite key bytes.
        namespaceSerializer - the serializer to obtain the serialized form of the namespace.
        Returns:
        the bytes for the serialized composite key of key-group, key, namespace.
      • buildCompositeKeyNamesSpaceUserKey

        @Nonnull
        public <N,​UK> byte[] buildCompositeKeyNamesSpaceUserKey​(@Nonnull
                                                                      N namespace,
                                                                      @Nonnull
                                                                      TypeSerializer<N> namespaceSerializer,
                                                                      @Nonnull
                                                                      UK userKey,
                                                                      @Nonnull
                                                                      TypeSerializer<UK> userKeySerializer)
                                                               throws IOException
        Returns a serialized composite key, from the key and key-group provided in a previous call to setKeyAndKeyGroup(Object, int) and the given namespace, followed by the given user-key.
        Type Parameters:
        N - the type of the namespace.
        UK - the type of the user-key.
        Parameters:
        namespace - the namespace to concatenate for the serialized composite key bytes.
        namespaceSerializer - the serializer to obtain the serialized form of the namespace.
        userKey - the user-key to concatenate for the serialized composite key, after the namespace.
        userKeySerializer - the serializer to obtain the serialized form of the user-key.
        Returns:
        the bytes for the serialized composite key of key-group, key, namespace.
        Throws:
        IOException
      • buildCompositeKeyUserKey

        @Nonnull
        public <UK> byte[] buildCompositeKeyUserKey​(@Nonnull
                                                    UK userKey,
                                                    @Nonnull
                                                    TypeSerializer<UK> userKeySerializer)
                                             throws IOException
        Returns a serialized composite key, from the key and key-group provided in a previous call to setKeyAndKeyGroup(Object, int) and the namespace provided in setNamespace(Object, TypeSerializer), followed by the given user-key.
        Type Parameters:
        UK - the type of the user-key.
        Parameters:
        userKey - the user-key to concatenate for the serialized composite key, after the namespace.
        userKeySerializer - the serializer to obtain the serialized form of the user-key.
        Returns:
        the bytes for the serialized composite key of key-group, key, namespace.
        Throws:
        IOException
      • build

        @Nonnull
        public byte[] build()
                     throws IOException
        Returns a serialized composite key, from whatever was set so far.
        Throws:
        IOException