Class InvocationTracker

    • Constructor Detail

      • InvocationTracker

        public InvocationTracker​(Channel channel,
                                 int maxMessages,
                                 IntUnaryOperator intMasker)
        Construct a new instance.
        Parameters:
        channel - the channel that is being tracked
        maxMessages - the maximum number of concurrent messages to allow
        intMasker - the function to apply to ID numbers to limit them to a specific range
      • InvocationTracker

        public InvocationTracker​(Channel channel,
                                 MessageTracker messageTracker,
                                 IntUnaryOperator intMasker)
        Construct a new instance.
        Parameters:
        channel - the channel that is being tracked
        messageTracker - the message tracker to use
        intMasker - the function to apply to ID numbers to limit them to a specific range
      • InvocationTracker

        public InvocationTracker​(Channel channel,
                                 IntUnaryOperator intMasker)
        Construct a new instance, using the maximum number of messages from the channel.
        Parameters:
        channel - the channel that is being tracked
        intMasker - the function to apply to ID numbers to limit them to a specific range
      • InvocationTracker

        public InvocationTracker​(Channel channel,
                                 int maxMessages)
        Construct a new instance.
        Parameters:
        channel - the channel that is being tracked
        maxMessages - the maximum number of concurrent messages to allow
      • InvocationTracker

        public InvocationTracker​(Channel channel)
        Construct a new instance, using the maximum number of messages from the channel.
        Parameters:
        channel - the channel that is being tracked
    • Method Detail

      • addInvocation

        public <T extends Invocation> T addInvocation​(IntFunction<T> producer)
        Add an invocation to this tracker.
        Type Parameters:
        T - the invocation type
        Parameters:
        producer - the invocation producer, which may be called more than once
        Returns:
        the produced invocation
      • containsIndex

        public boolean containsIndex​(int index)
        Determine if the tracker contains an entry at the given index.
        Parameters:
        index - the index
        Returns:
        true if the tracker contains the entry, false otherwise
      • putIfAbsent

        public Invocation putIfAbsent​(Invocation invocation)
        Put an invocation into the tracker if there is none with the corresponding ID.
        Parameters:
        invocation - the invocation
        Returns:
        the existing invocation, or null if the put was successful
      • signalResponse

        public boolean signalResponse​(int index,
                                      int parameter,
                                      MessageInputStream responseStream,
                                      boolean remove)
        Signal the arrival of a response with the given index.
        Parameters:
        index - the index of the response
        parameter - an integer parameter to pass to the response handler (typically a message ID type)
        responseStream - the response stream
        remove - true to release the index for subsequent invocations, false otherwise
        Returns:
        true if the index was valid, false otherwise
      • remove

        public void remove​(Invocation invocation)
        Unconditionally remove an invocation from the map. This should only be done if the outbound request definitely failed to be written.
        Parameters:
        invocation - the invocation
      • allocateMessage

        public MessageOutputStream allocateMessage()
                                            throws IOException
        Allocate a message, possibly blocking until one is available.
        Returns:
        the allocated message
        Throws:
        IOException - if an error occurs
      • allocateMessage

        public MessageOutputStream allocateMessage​(Invocation invocation)
                                            throws IOException
        Allocate a message on behalf of an invocation, possibly blocking until a message is available. The invocation will automatically be removed if writing the message fails or is cancelled.
        Parameters:
        invocation - the invocation of the message
        Returns:
        the allocated message
        Throws:
        IOException - if an error occurs