Package org.jboss.remoting3.util
Class InvocationTracker
- java.lang.Object
-
- org.jboss.remoting3.util.InvocationTracker
-
public final class InvocationTracker extends Object
An invocation tracker.- Author:
- David M. Lloyd
-
-
Constructor Summary
Constructors Constructor Description InvocationTracker(Channel channel)
Construct a new instance, using the maximum number of messages from the channel.InvocationTracker(Channel channel, int maxMessages)
Construct a new instance.InvocationTracker(Channel channel, int maxMessages, IntUnaryOperator intMasker)
Construct a new instance.InvocationTracker(Channel channel, IntUnaryOperator intMasker)
Construct a new instance, using the maximum number of messages from the channel.InvocationTracker(Channel channel, MessageTracker messageTracker, IntUnaryOperator intMasker)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Invocation>
TaddInvocation(IntFunction<T> producer)
Add an invocation to this tracker.MessageOutputStream
allocateMessage()
Allocate a message, possibly blocking until one is available.MessageOutputStream
allocateMessage(Invocation invocation)
Allocate a message on behalf of an invocation, possibly blocking until a message is available.boolean
containsIndex(int index)
Determine if the tracker contains an entry at the given index.Invocation
putIfAbsent(Invocation invocation)
Put an invocation into the tracker if there is none with the corresponding ID.void
remove(Invocation invocation)
Unconditionally remove an invocation from the map.boolean
signalResponse(int index, int parameter, MessageInputStream responseStream, boolean remove)
Signal the arrival of a response with the given index.
-
-
-
Constructor Detail
-
InvocationTracker
public InvocationTracker(Channel channel, int maxMessages, IntUnaryOperator intMasker)
Construct a new instance.- Parameters:
channel
- the channel that is being trackedmaxMessages
- the maximum number of concurrent messages to allowintMasker
- 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 trackedmessageTracker
- the message tracker to useintMasker
- 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 trackedintMasker
- 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 trackedmaxMessages
- 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 responseparameter
- an integer parameter to pass to the response handler (typically a message ID type)responseStream
- the response streamremove
-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
-
-