Class NonSerializedMemoryBlock<K extends java.io.Serializable>

  • Type Parameters:
    K - the key type of its partitions.
    All Implemented Interfaces:
    Block<K>

    @NotThreadSafe
    public final class NonSerializedMemoryBlock<K extends java.io.Serializable>
    extends java.lang.Object
    implements Block<K>
    This class represents a block which is stored in local memory and not serialized. Concurrent read is supported, but concurrent write is not supported.
    • Constructor Detail

      • NonSerializedMemoryBlock

        public NonSerializedMemoryBlock​(java.lang.String blockId,
                                        Serializer serializer,
                                        MemoryPoolAssigner memoryPoolAssigner)
        Constructor.
        Parameters:
        blockId - the ID of this block.
        serializer - the Serializer.
        memoryPoolAssigner - the MemoryPoolAssigner for memory allocation.
    • Method Detail

      • write

        public void write​(K key,
                          java.lang.Object element)
                   throws BlockWriteException
        Writes an element to non-committed block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.
        Specified by:
        write in interface Block<K extends java.io.Serializable>
        Parameters:
        key - the key.
        element - the element to write.
        Throws:
        BlockWriteException - for any error occurred while trying to write a block.
      • writeSerializedPartitions

        public void writeSerializedPartitions​(java.lang.Iterable<SerializedPartition<K>> partitions)
                                       throws BlockWriteException
        Stores SerializedPartitions to this block. Because all data in this block is stored in a non-serialized form, the data in these partitions have to be deserialized. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.
        Specified by:
        writeSerializedPartitions in interface Block<K extends java.io.Serializable>
        Parameters:
        partitions - the SerializedPartitions to store.
        Throws:
        BlockWriteException - for any error occurred while trying to write a block.
      • commit

        public java.util.Optional<java.util.Map<K,​java.lang.Long>> commit()
        Commits this block to prevent further write.
        Specified by:
        commit in interface Block<K extends java.io.Serializable>
        Returns:
        empty optional because the data is not serialized.
      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface Block<K extends java.io.Serializable>
        Returns:
        the ID of this block.
      • isCommitted

        public boolean isCommitted()
        Specified by:
        isCommitted in interface Block<K extends java.io.Serializable>
        Returns:
        whether this block is committed or not.