Class SharedBufferAccessor<V>

  • All Implemented Interfaces:
    AutoCloseable

    public class SharedBufferAccessor<V>
    extends Object
    implements AutoCloseable
    Accessor to SharedBuffer that allows operations on the underlying structures in batches. Operations are persisted only after closing the Accessor.
    • Method Detail

      • advanceTime

        public void advanceTime​(long timestamp)
                         throws Exception
        Notifies shared buffer that there will be no events with timestamp <&eq; the given value. It allows to clear internal counters for number of events seen so far per timestamp.
        Parameters:
        timestamp - watermark, no earlier events will arrive
        Throws:
        Exception - Thrown if the system cannot access the state.
      • registerEvent

        public EventId registerEvent​(V value,
                                     long timestamp)
                              throws Exception
        Adds another unique event to the shared buffer and assigns a unique id for it. It automatically creates a lock on this event, so it won't be removed during processing of that event. Therefore the lock should be removed after processing all ComputationStates

        NOTE:Should be called only once for each unique event!

        Parameters:
        value - event to be registered
        Returns:
        unique id of that event that should be used when putting entries to the buffer.
        Throws:
        Exception - Thrown if the system cannot access the state.
      • put

        public NodeId put​(String stateName,
                          EventId eventId,
                          @Nullable
                          NodeId previousNodeId,
                          DeweyNumber version)
        Stores given value (value + timestamp) under the given state. It assigns a preceding element relation to the previous entry.
        Parameters:
        stateName - name of the state that the event should be assigned to
        eventId - unique id of event assigned by this SharedBuffer
        previousNodeId - id of previous entry (might be null if start of new run)
        version - Version of the previous relation
        Returns:
        assigned id of this element
      • extractPatterns

        public List<Map<String,​List<EventId>>> extractPatterns​(NodeId nodeId,
                                                                     DeweyNumber version)
        Returns all elements from the previous relation starting at the given entry.
        Parameters:
        nodeId - id of the starting entry
        version - Version of the previous relation which shall be extracted
        Returns:
        Collection of previous relations starting with the given value
      • materializeMatch

        public Map<String,​List<V>> materializeMatch​(Map<String,​List<EventId>> match)
        Extracts the real event from the sharedBuffer with pre-extracted eventId.
        Parameters:
        match - the matched event's eventId.
        Returns:
        the event associated with the eventId.
      • lockNode

        public void lockNode​(NodeId node,
                             DeweyNumber version)
        Increases the reference counter for the given entry so that it is not accidentally removed.
        Parameters:
        node - id of the entry
        version - dewey number of the (potential) edge that locks the given node
      • releaseNode

        public void releaseNode​(NodeId node,
                                DeweyNumber version)
                         throws Exception
        Decreases the reference counter for the given entry so that it can be removed once the reference counter reaches 0.
        Parameters:
        node - id of the entry
        version - dewey number of the (potential) edge that locked the given node
        Throws:
        Exception - Thrown if the system cannot access the state.
      • releaseEvent

        public void releaseEvent​(EventId eventId)
                          throws Exception
        Decreases the reference counter for the given event so that it can be removed once the reference counter reaches 0.
        Parameters:
        eventId - id of the event
        Throws:
        Exception - Thrown if the system cannot access the state.
      • close

        public void close()
                   throws Exception
        Persists the entry in the cache to the underlay state.
        Specified by:
        close in interface AutoCloseable
        Throws:
        Exception - Thrown if the system cannot access the state.