Package rx.internal.schedulers
Class EventLoopsScheduler
- java.lang.Object
-
- rx.Scheduler
-
- rx.internal.schedulers.EventLoopsScheduler
-
- All Implemented Interfaces:
SchedulerLifecycle
public final class EventLoopsScheduler extends Scheduler implements SchedulerLifecycle
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
EventLoopsScheduler.EventLoopWorker
(package private) static class
EventLoopsScheduler.FixedSchedulerPool
(package private) static class
EventLoopsScheduler.PoolWorker
-
Nested classes/interfaces inherited from class rx.Scheduler
Scheduler.Worker
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
KEY_MAX_THREADS
Key to setting the maximum number of computation scheduler threads.(package private) static int
MAX_THREADS
The maximum number of computation scheduler threads.(package private) static EventLoopsScheduler.FixedSchedulerPool
NONE
This will indicate no pool is active.(package private) java.util.concurrent.atomic.AtomicReference<EventLoopsScheduler.FixedSchedulerPool>
pool
(package private) static EventLoopsScheduler.PoolWorker
SHUTDOWN_WORKER
(package private) java.util.concurrent.ThreadFactory
threadFactory
-
Constructor Summary
Constructors Constructor Description EventLoopsScheduler(java.util.concurrent.ThreadFactory threadFactory)
Create a scheduler with pool size equal to the available processor count and using least-recent worker selection policy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Scheduler.Worker
createWorker()
Retrieves or creates a newScheduler.Worker
that represents serial execution of actions.Subscription
scheduleDirect(Action0 action)
Schedules the action directly on one of the event loop workers without the additional infrastructure and checking.void
shutdown()
Instructs the Scheduler instance to stop threads and stop accepting tasks on any outstanding Workers.void
start()
Allows the Scheduler instance to start threads and accept tasks on them.
-
-
-
Field Detail
-
KEY_MAX_THREADS
static final java.lang.String KEY_MAX_THREADS
Key to setting the maximum number of computation scheduler threads. Zero or less is interpreted as use available. Capped by available.- See Also:
- Constant Field Values
-
MAX_THREADS
static final int MAX_THREADS
The maximum number of computation scheduler threads.
-
SHUTDOWN_WORKER
static final EventLoopsScheduler.PoolWorker SHUTDOWN_WORKER
-
NONE
static final EventLoopsScheduler.FixedSchedulerPool NONE
This will indicate no pool is active.
-
threadFactory
final java.util.concurrent.ThreadFactory threadFactory
-
pool
final java.util.concurrent.atomic.AtomicReference<EventLoopsScheduler.FixedSchedulerPool> pool
-
-
Constructor Detail
-
EventLoopsScheduler
public EventLoopsScheduler(java.util.concurrent.ThreadFactory threadFactory)
Create a scheduler with pool size equal to the available processor count and using least-recent worker selection policy.- Parameters:
threadFactory
- the factory to use with the executors
-
-
Method Detail
-
createWorker
public Scheduler.Worker createWorker()
Description copied from class:Scheduler
Retrieves or creates a newScheduler.Worker
that represents serial execution of actions.When work is completed it should be unsubscribed using
Subscription.unsubscribe()
.Work on a
Scheduler.Worker
is guaranteed to be sequential.- Specified by:
createWorker
in classScheduler
- Returns:
- a Worker representing a serial queue of actions to be executed
-
start
public void start()
Description copied from interface:SchedulerLifecycle
Allows the Scheduler instance to start threads and accept tasks on them.Implementations should make sure the call is idempotent and threadsafe.
- Specified by:
start
in interfaceSchedulerLifecycle
-
shutdown
public void shutdown()
Description copied from interface:SchedulerLifecycle
Instructs the Scheduler instance to stop threads and stop accepting tasks on any outstanding Workers.Implementations should make sure the call is idempotent and threadsafe.
- Specified by:
shutdown
in interfaceSchedulerLifecycle
-
scheduleDirect
public Subscription scheduleDirect(Action0 action)
Schedules the action directly on one of the event loop workers without the additional infrastructure and checking.- Parameters:
action
- the action to schedule- Returns:
- the subscription
-
-