public class FirstInFirstOutReleaseRunner extends ReleaseRunner
ReleaseRunner
that uses a pool of FIFO scheduled
realtime threads to run handlers. This reduces the amount of threads
required for handling events compared with bounding a thread to each
handler. It also supports handlers that suspend themselves, e.g., by
calling the Object.wait()
method. The size of the pool of threads
is based on the number of handlers, the number of priorities in use, and
the number of cpus available. For systems with many
AsyncBaseEventHandler
instances, there can be significantly fewer
threads to run releases of those handlers in the system.ReleaseRunner.Proxy
Constructor and Description |
---|
FirstInFirstOutReleaseRunner(ConfigurationParameters config)
Same as
FirstInFirstOutReleaseRunner(ConfigurationParameters, RealtimeThreadGroup, IntBinaryOperator)
with arguments {(config, null, null)}. |
FirstInFirstOutReleaseRunner(ConfigurationParameters config,
RealtimeThreadGroup group,
java.util.function.IntBinaryOperator sizer)
Create a release runner which maintains a pool of threads to run releases
of
AsyncBaseEventHandler instances. |
Modifier and Type | Method and Description |
---|---|
protected void |
attach(ReleaseRunner.Proxy handler)
Attach a handler from this runner, so it will be released.
|
protected void |
detach(ReleaseRunner.Proxy handler)
Detach a handler from this runner, so it will no longer be released.
|
ConfigurationParameters |
getConfigurationParameters()
Get the
ConfigurationParameters object used for all threads
provided by this release runner. |
protected RealtimeThreadGroup |
getRealtimeThreadGroup()
Determine the
RealtimeThreadGroup instance used. |
protected void |
release(ReleaseRunner.Proxy handler)
Finds a thread and has it call the
Runnable.run()
method. |
public FirstInFirstOutReleaseRunner(ConfigurationParameters config, RealtimeThreadGroup group, java.util.function.IntBinaryOperator sizer)
AsyncBaseEventHandler
instances. The threads in the pool all
run in a given RealtimeThreadGroup
instance. The thread pool size
is determined by the binary function sizer
. When sizer
is null
, a reasonable default is provided.config
- the ConfigurationParameters object to use for all handler
run from this pool, which means for each thread in the pool.group
- for the pool threads.sizer
- A binary function from the number of handlers and the
number of priorities of those handles to the
number of threads in the pool. It may use global
information, such as the number of available CPUs. It may
also ignore its arguments.public FirstInFirstOutReleaseRunner(ConfigurationParameters config)
FirstInFirstOutReleaseRunner(ConfigurationParameters, RealtimeThreadGroup, IntBinaryOperator)
with arguments {(config, null, null)}.protected RealtimeThreadGroup getRealtimeThreadGroup()
ReleaseRunner
RealtimeThreadGroup
instance used.getRealtimeThreadGroup
in class ReleaseRunner
RealtimeThreadGroup
instance used by all threads
used for running releases.public ConfigurationParameters getConfigurationParameters()
ReleaseRunner
ConfigurationParameters
object used for all threads
provided by this release runner.getConfigurationParameters
in class ReleaseRunner
protected void release(ReleaseRunner.Proxy handler)
ReleaseRunner
Runnable.run()
method. Care should be exercised when implementing this method, since
it adds to both the latency and jitter of releasing events. The caller
must guarantee that releases of any given handler are always executed in
order.
This method should only be called from the infrastructure.
release
in class ReleaseRunner
handler
- The handler to be released.protected void attach(ReleaseRunner.Proxy handler) throws StaticIllegalStateException
attach
in class ReleaseRunner
handler
- to be removed.StaticIllegalArgumentException
- When handler
is nullStaticIllegalStateException
- when handler
is
already attached.protected void detach(ReleaseRunner.Proxy handler) throws StaticIllegalStateException
detach
in class ReleaseRunner
handler
- to be detached.StaticIllegalArgumentException
- When handler
is nullStaticIllegalStateException
- when handler
is not attached.