Class CacheEntryCodec

java.lang.Object
se.liu.ida.hefquin.federation.access.impl.cache.CacheEntryCodec

public final class CacheEntryCodec extends Object
Codec for serializing and deserializing PersistentCacheEntry instances.

This class defines the binary format used to persist cache entries independently of the underlying storage technology. Implementations for ChronicleMap, MapDB, or other storage backends can reuse this codec to ensure a consistent on-disk representation.

Each serialized entry consists of the entry creation timestamp followed by a serialized form of the cached DataRetrievalResponse, prefixed with a type discriminator that identifies the concrete response type.

Serialization is performed into a temporary in-memory buffer before any bytes are written to the provided output. This ensures that partially serialized entries are never committed if serialization fails.

  • Method Details

    • write

      public static void write(DataOutput out, PersistentCacheEntry entry) throws IOException
      Serializes the given cache entry to the provided output.

      Serialization is first performed into a temporary buffer and only written to out after successful completion. This prevents partially serialized entries from being persisted if an error occurs during serialization.

      This method blocks until the DataRetrievalResponse contained in the cache entry becomes available.

       [creationTime: long]
       [type: int]
      
       SOLUTION_MAPPING_RESPONSE:
         [numMappings: int]
         repeat numMappings:
           [bindingSize: int]
           repeat bindingSize:
             [varName: UTF-8]
             [node: UTF-8]
      
       TPF_RESPONSE:
         [numMatchingTriples: int]
         repeat numMatchingTriples:
           [subject: UTF-8]
           [predicate: UTF-8]
           [object: UTF-8]
         [numMetadataTriples: int]
         repeat numMetadataTriples:
           [subject: UTF-8]
           [predicate: UTF-8]
           [object: UTF-8]
         [nextPageURL: UTF-8 or null]
      
       CARDINALITY_RESPONSE:
         [cardinality: int]
       
      Parameters:
      out - destination to which the serialized representation is written
      entry - cache entry to serialize
      Throws:
      IOException - if writing to the output fails
      IllegalStateException - if the response type is unsupported or the contained future cannot be resolved
    • read

      public static PersistentCacheEntry read(DataInput in) throws IOException
      Deserializes a cache entry from the provided input.

      The input must contain data encoded according to the binary format defined by write(DataOutput, PersistentCacheEntry).

      The deserialized response is wrapped in a completed CompletableFuture preserving the original creation timestamp.

      Parameters:
      in - source containing a serialized cache entry
      Returns:
      reconstructed cache entry
      Throws:
      IOException - if the serialized representation cannot be read
      IllegalStateException - if an unsupported response type identifier is encountered
    • serializeNode

      protected static String serializeNode(org.apache.jena.graph.Node node)
      Serializes a Jena Node into its N-Triples string representation.
      Parameters:
      node - the node to serialize
    • deserializeNode

      protected static org.apache.jena.graph.Node deserializeNode(String s)
      Parses a Jena Node from its N-Triples string representation.
      Parameters:
      s - the serialized node